AI-native knowledge base & Evernote/Obsidian alternative with instant sync & native MCP. Free on Cloudflare or self-hosted via Docker.
HTML ai-agentcloudflarecloudflare-d1cloudflare-r2cloudflare-workersdockerelectronevernoteevernote-alternativeknowledge-basemcpnote-takingobsidian-alternativeoffline-firstpersonal-knowledge-basepwaself-hostedsqlitetiptapweb-clipper
fix(mobile): detect installable app updates
tianma-if2b334f5c6190
diff --git a/apps/mobile/package.json b/apps/mobile/package.jsonindex 7e4f574f..32e5bfd5 100644--- a/apps/mobile/package.json+++ b/apps/mobile/package.json@@ -46,10 +46,12 @@"react-native-safe-area-context": "~5.7.0","react-native-screens": "4.25.2","react-native-svg": "15.15.4",- "react-native-web": "~0.21.0"+ "react-native-web": "~0.21.0",+ "semver": "^7.8.5"},"devDependencies": {"@types/react": "latest",+ "@types/semver": "^7.7.1","babel-preset-expo": "latest","gluestack-ui": "latest","typescript": "6.0.3"diff --git a/apps/mobile/src/components/MobileUpdateCard.tsx b/apps/mobile/src/components/MobileUpdateCard.tsxindex cca30e81..554203b5 100644--- a/apps/mobile/src/components/MobileUpdateCard.tsx+++ b/apps/mobile/src/components/MobileUpdateCard.tsx@@ -1,4 +1,5 @@import Constants from "expo-constants";+import * as Updates from "expo-updates";import { ActivityIndicator, StyleSheet, View } from "react-native";import { RefreshCw } from "./icons";import { Pressable, Text } from "./LocalizedText";@@ -27,11 +28,11 @@ export const MobileUpdateCard = () => {<Text style={styles.title}>{english ? "App updates" : "应用更新"}</Text><Text style={styles.description}>{english- ? "EdgeEver checks for compatible updates when it starts and returns to the foreground."- : "EdgeEver 会在启动和回到前台时自动检查兼容更新。"}+ ? "EdgeEver automatically checks for compatible in-app updates. Manual checks also look for newer installable versions."+ : "EdgeEver 会自动检查兼容的应用内热更新;手动检查还会查找更新的安装包版本。"}</Text><Text style={styles.version}>- {english ? "Current version" : "当前版本"}: v{Constants.expoConfig?.version ?? "unknown"}+ {english ? "Current version" : "当前版本"}: v{Updates.runtimeVersion ?? Constants.expoConfig?.version ?? "unknown"}</Text></View><Pressablediff --git a/apps/mobile/src/lib/mobile-release.test.ts b/apps/mobile/src/lib/mobile-release.test.tsnew file mode 100644index 00000000..43e018a2--- /dev/null+++ b/apps/mobile/src/lib/mobile-release.test.ts@@ -0,0 +1,27 @@+import { expect, test } from "bun:test";+import { findNewerMobileRelease } from "./mobile-release";++const responseWithTag = (tagName: string) => new Response(JSON.stringify({ tag_name: tagName }), {+ headers: { "Content-Type": "application/json" },+ status: 200,+});++test("finds a newer formal GitHub release", async () => {+ const release = await findNewerMobileRelease("0.4.14", async () => responseWithTag("v0.4.15"));++ expect(release).toEqual({ version: "0.4.15" });+});++test("does not treat the current or an older release as an update", async () => {+ expect(await findNewerMobileRelease("0.4.15", async () => responseWithTag("v0.4.15"))).toBeNull();+ expect(await findNewerMobileRelease("0.4.15", async () => responseWithTag("v0.4.14"))).toBeNull();+});++test("rejects invalid release responses instead of claiming the app is current", async () => {+ await expect(findNewerMobileRelease("0.4.14", async () => responseWithTag("latest"))).rejects.toThrow(+ "Invalid GitHub release version"+ );+ await expect(findNewerMobileRelease("0.4.14", async () => new Response(null, { status: 403 }))).rejects.toThrow(+ "status 403"+ );+});diff --git a/apps/mobile/src/lib/mobile-release.ts b/apps/mobile/src/lib/mobile-release.tsnew file mode 100644index 00000000..47210ce9--- /dev/null+++ b/apps/mobile/src/lib/mobile-release.ts@@ -0,0 +1,50 @@+import { clean, gt, valid } from "semver";++const LATEST_RELEASE_API_URL = "https://api.github.com/repos/tianma-if/edgeever/releases/latest";++export const GITHUB_LATEST_RELEASE_URL = "https://github.com/tianma-if/edgeever/releases/latest";+export const GOOGLE_PLAY_URL = "https://play.google.com/store/apps/details?id=org.edgeever.mobile";++type LatestReleaseResponse = {+ tag_name?: unknown;+};++export type MobileRelease = {+ version: string;+};++const normalizeVersion = (value: string) => {+ const normalized = clean(value);+ return normalized && valid(normalized) ? normalized : null;+};++export const findNewerMobileRelease = async (+ currentVersion: string,+ fetchRelease: typeof fetch = fetch+): Promise<MobileRelease | null> => {+ const normalizedCurrentVersion = normalizeVersion(currentVersion);+ if (!normalizedCurrentVersion) {+ throw new Error(`Invalid installed app version: ${currentVersion}`);+ }++ const response = await fetchRelease(LATEST_RELEASE_API_URL, {+ headers: {+ Accept: "application/vnd.github+json",+ "X-GitHub-Api-Version": "2022-11-28",+ },+ });+ if (!response.ok) {+ throw new Error(`GitHub release check failed with status ${response.status}`);+ }++ const release = await response.json() as LatestReleaseResponse;+ if (typeof release.tag_name !== "string") {+ throw new Error("GitHub release response does not contain a version tag");+ }+ const latestVersion = normalizeVersion(release.tag_name);+ if (!latestVersion) {+ throw new Error(`Invalid GitHub release version: ${release.tag_name}`);+ }++ return gt(latestVersion, normalizedCurrentVersion) ? { version: latestVersion } : null;+};diff --git a/apps/mobile/src/lib/mobile-update.tsx b/apps/mobile/src/lib/mobile-update.tsxindex 2ac8b4a3..8ed494aa 100644--- a/apps/mobile/src/lib/mobile-update.tsx+++ b/apps/mobile/src/lib/mobile-update.tsx@@ -1,8 +1,10 @@import { createContext, useCallback, useContext, useEffect, useMemo, useRef, useState, type ReactNode } from "react";-import { AppState, type AppStateStatus } from "react-native";+import Constants from "expo-constants";+import { AppState, Linking, Platform, type AppStateStatus } from "react-native";import * as Updates from "expo-updates";import { Alert } from "../components/LocalizedText";import { useMobileLocale } from "./mobile-locale";+import { findNewerMobileRelease, GITHUB_LATEST_RELEASE_URL, GOOGLE_PLAY_URL, type MobileRelease } from "./mobile-release";const FOREGROUND_CHECK_INTERVAL_MS = 6 * 60 * 60 * 1000;@@ -27,6 +29,30 @@ export const MobileUpdateProvider = ({ children }: { children: ReactNode }) => {const lastAutomaticCheckRef = useRef(0);const isSupported = !__DEV__ && Updates.isEnabled;const english = resolvedLocale === "en-US";+ const installedVersion = Updates.runtimeVersion ?? Constants.expoConfig?.version ?? null;++ const openUpdateUrl = useCallback((url: string) => {+ void Linking.openURL(url).catch(() => {+ Alert.alert(+ english ? "Unable to open update page" : "无法打开更新页面",+ english ? "Open the app store or GitHub Releases and try again." : "请手动打开应用商店或 GitHub Releases 后重试。"+ );+ });+ }, [english]);++ const showInstallableUpdatePrompt = useCallback((release: MobileRelease) => {+ Alert.alert(+ english ? "New app version available" : "发现新版本",+ english+ ? `Version v${release.version} is available. This update includes an installable app package and cannot be applied as an in-app update.`+ : `发现可安装的新版本 v${release.version}。此类更新包含新的应用安装包,无法通过应用内热更新完成。`,+ [+ { text: english ? "Later" : "稍后", style: "cancel" },+ { text: "Google Play", onPress: () => openUpdateUrl(GOOGLE_PLAY_URL) },+ { text: "GitHub", onPress: () => openUpdateUrl(GITHUB_LATEST_RELEASE_URL) },+ ]+ );+ }, [english, openUpdateUrl]);const restart = useCallback(async () => {try {@@ -71,17 +97,44 @@ export const MobileUpdateProvider = ({ children }: { children: ReactNode }) => {}const check = (async () => {+ let installableReleaseCheckFailed = false;try {setStatus("checking");++ if (userInitiated && Platform.OS === "android") {+ try {+ if (!installedVersion) {+ throw new Error("Installed app version is unavailable");+ }+ const release = await findNewerMobileRelease(installedVersion);+ if (release) {+ setStatus("idle");+ showInstallableUpdatePrompt(release);+ return;+ }+ } catch {+ installableReleaseCheckFailed = true;+ }+ }+const result = await Updates.checkForUpdateAsync();if (!result.isAvailable) {setStatus("idle");if (userInitiated) {- Alert.alert(- english ? "You're up to date" : "已是最新版本",- english ? "No new update is available for this version." : "当前版本暂无可用更新。"- );+ if (installableReleaseCheckFailed) {+ Alert.alert(+ english ? "Unable to fully check for updates" : "无法完成更新检查",+ english+ ? "No compatible in-app update was found, but the latest installable app version could not be verified. Check your connection and try again."+ : "未发现兼容的应用内热更新,但无法确认最新安装包版本。请检查网络连接后重试。"+ );+ } else {+ Alert.alert(+ english ? "You're up to date" : "已是最新版本",+ english ? "No newer app package or compatible in-app update is available." : "当前没有更新的安装包或兼容的应用内热更新。"+ );+ }}return;}@@ -107,7 +160,7 @@ export const MobileUpdateProvider = ({ children }: { children: ReactNode }) => {activeCheckRef.current = null;});return check;- }, [english, isSupported, showRestartPrompt]);+ }, [english, installedVersion, isSupported, showInstallableUpdatePrompt, showRestartPrompt]);useEffect(() => {const attemptAutomaticCheck = () => {diff --git a/bun.lock b/bun.lockindex c63693da..68cb01c6 100644--- a/bun.lock+++ b/bun.lock@@ -116,9 +116,11 @@"react-native-screens": "4.25.2","react-native-svg": "15.15.4","react-native-web": "~0.21.0",+ "semver": "^7.8.5",},"devDependencies": {"@types/react": "latest",+ "@types/semver": "^7.7.1","babel-preset-expo": "latest","gluestack-ui": "latest","typescript": "6.0.3",@@ -1159,6 +1161,8 @@"@types/sax": ["@types/[email protected]", "", { "dependencies": { "@types/node": "*" } }, "sha512-rO73L89PJxeYM3s3pPPjiPgVVcymqU490g0YO5n5By0k2Erzj6tay/4lr1CHAAU4JyOWd1rpQ8bCf6cZfHU96A=="],+ "@types/semver": ["@types/[email protected]", "", {}, "sha512-FmgJfu+MOcQ370SD0ev7EI8TlCAfKYU+B4m5T3yXc1CiRN94g/SZPtsCkk506aUDtlMnFZvasDwHHUcZUEaYuA=="],+"@types/trusted-types": ["@types/[email protected]", "", {}, "sha512-ScaPdn1dQczgbl0QFTeTOmVHFULt394XJgOQNoyVhZ6r2vLnMLJfBPd53SB52T/3G36VI1/g2MZaX0cwDuXsfw=="],"@types/turndown": ["@types/[email protected]", "", {}, "sha512-ru00MoyeeouE5BX4gRL+6m/BsDfbRayOskWqUvh7CLGW+UXxHQItqALa38kKnOiZPqJrtzJUgAC2+F0rL1S4Pg=="],