mirror of
https://github.com/Qortal/qortal-mobile.git
synced 2025-03-14 11:52:33 +00:00
add new version popup for apks
This commit is contained in:
parent
c7327aa51d
commit
6e25d338f7
@ -7,7 +7,7 @@
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
|
||||
|
||||
|
||||
<title>Qortal Extension</title>
|
||||
<title>Qortal Go</title>
|
||||
</head>
|
||||
<body>
|
||||
<div id="root"></div>
|
||||
|
5
latest.json
Normal file
5
latest.json
Normal file
@ -0,0 +1,5 @@
|
||||
{
|
||||
"version": "0.2.0",
|
||||
"apkUrl": "https://github.com/Qortal/qortal-mobile/releases/download/v0.2.0/qortal.apk"
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "ext-one",
|
||||
"name": "qortal-go",
|
||||
"private": true,
|
||||
"version": "0.0.0",
|
||||
"version": "0.2.0",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
|
71
src/App.tsx
71
src/App.tsx
@ -42,7 +42,6 @@ import Return from "./assets/svgs/Return.svg";
|
||||
import Success from "./assets/svgs/Success.svg";
|
||||
import Info from "./assets/svgs/Info.svg";
|
||||
import CloseIcon from "@mui/icons-material/Close";
|
||||
|
||||
import {
|
||||
createAccount,
|
||||
generateRandomSentence,
|
||||
@ -112,7 +111,7 @@ import {
|
||||
sortablePinnedAppsAtom,
|
||||
} from "./atoms/global";
|
||||
import { useAppFullScreen } from "./useAppFullscreen";
|
||||
import { NotAuthenticated } from "./ExtStates/NotAuthenticated";
|
||||
import { NotAuthenticated, manifestData } from "./ExtStates/NotAuthenticated";
|
||||
import { openIndexedDB, showSaveFilePicker } from "./components/Apps/useQortalMessageListener";
|
||||
import { fileToBase64 } from "./utils/fileReading";
|
||||
import { handleGetFileFromIndexedDB } from "./utils/indexedDB";
|
||||
@ -183,6 +182,70 @@ if (isMobileDevice()) {
|
||||
console.log("Running on a desktop");
|
||||
}
|
||||
|
||||
async function isFromPlayStore() {
|
||||
try {
|
||||
return false;
|
||||
} catch (error) {
|
||||
console.error("Error checking installer:", error);
|
||||
return false; // Assume sideloaded if there's an error
|
||||
}
|
||||
}
|
||||
|
||||
function promptUserToUpdate(apkUrl) {
|
||||
if (confirm('A new version is available on github. Would you like to download it?')) {
|
||||
window.open(apkUrl, '_system'); // Opens the APK download URL in the default browser
|
||||
}
|
||||
}
|
||||
|
||||
function isNewerVersion(current, latest) {
|
||||
const currentParts = current.split('.').map(Number);
|
||||
const latestParts = latest.split('.').map(Number);
|
||||
|
||||
for (let i = 0; i < currentParts.length; i++) {
|
||||
if (latestParts[i] > currentParts[i]) return true;
|
||||
if (latestParts[i] < currentParts[i]) return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
async function checkForUpdateFromGitHub() {
|
||||
try {
|
||||
|
||||
const currentVersion = manifestData.version;
|
||||
// Fetch the latest release information
|
||||
const response = await fetch('https://api.github.com/repos/Qortal/qortal-mobile/releases/latest');
|
||||
const latestRelease = await response.json();
|
||||
|
||||
// Get the version from the release name, assuming it follows the pattern "v0.2.0"
|
||||
const latestVersion = latestRelease.name.replace(/^v/, ''); // Remove the "v" prefix if present
|
||||
|
||||
if (isNewerVersion(currentVersion, latestVersion)) {
|
||||
const apkAsset = latestRelease.assets.find(asset => asset.name.endsWith('.apk'));
|
||||
console.log('apkAsset', apkAsset)
|
||||
if (apkAsset) {
|
||||
// Prompt user to download the APK if a new version is available
|
||||
promptUserToUpdate(apkAsset.browser_download_url);
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error checking for update:', error);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
async function checkForUpdate() {
|
||||
const fromPlayStore = await isFromPlayStore();
|
||||
if (fromPlayStore) {
|
||||
console.log("App is from the Play Store. Handle updates through the Play Store.");
|
||||
// Show instructions for Play Store updates, or redirect the user to the Play Store.
|
||||
} else {
|
||||
console.log("App is sideloaded. Handle APK-based update.");
|
||||
// Implement APK-based update check, as discussed previously.
|
||||
checkForUpdateFromGitHub();
|
||||
}
|
||||
}
|
||||
|
||||
export const allQueues = {
|
||||
requestQueueCommentCount: requestQueueCommentCount,
|
||||
requestQueuePublishedAccouncements: requestQueuePublishedAccouncements,
|
||||
@ -1168,6 +1231,10 @@ function App() {
|
||||
};
|
||||
}, []);
|
||||
|
||||
useEffect(()=> {
|
||||
checkForUpdate()
|
||||
}, [])
|
||||
|
||||
const registerName = async () => {
|
||||
try {
|
||||
if (!userInfo?.address) throw new Error("Your address was not found");
|
||||
|
@ -22,8 +22,8 @@ import { CustomizedSnackbars } from "../components/Snackbar/Snackbar";
|
||||
import { set } from "lodash";
|
||||
import { cleanUrl, isUsingLocal } from "../background";
|
||||
|
||||
const manifestData = {
|
||||
version: '2.2.0'
|
||||
export const manifestData = {
|
||||
version: '0.2.0'
|
||||
}
|
||||
|
||||
export const NotAuthenticated = ({
|
||||
|
Loading…
x
Reference in New Issue
Block a user