diff --git a/index.html b/index.html index 4484aaf..1c285cc 100644 --- a/index.html +++ b/index.html @@ -7,7 +7,7 @@ - Qortal Extension + Qortal Go
diff --git a/latest.json b/latest.json new file mode 100644 index 0000000..32d14e4 --- /dev/null +++ b/latest.json @@ -0,0 +1,5 @@ +{ + "version": "0.2.0", + "apkUrl": "https://github.com/Qortal/qortal-mobile/releases/download/v0.2.0/qortal.apk" + } + \ No newline at end of file diff --git a/package.json b/package.json index cf6d2c6..188ad26 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/App.tsx b/src/App.tsx index 79cfe78..efdefc0 100644 --- a/src/App.tsx +++ b/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"); diff --git a/src/ExtStates/NotAuthenticated.tsx b/src/ExtStates/NotAuthenticated.tsx index 5dff727..cbb0310 100644 --- a/src/ExtStates/NotAuthenticated.tsx +++ b/src/ExtStates/NotAuthenticated.tsx @@ -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 = ({