Skip to content

AI-native knowledge base & Evernote/Obsidian alternative with instant sync & native MCP. Free on Cloudflare or self-hosted via Docker.

fix(mobile): improve Android update destinations

tianma-if59fe7c7cf9d2
diff --git a/apps/mobile/.gitignore b/apps/mobile/.gitignore
index 1bdf3c9d..917e04bb 100644
--- a/apps/mobile/.gitignore
+++ b/apps/mobile/.gitignore
@@ -14,3 +14,5 @@ ios/
modules/edgeever-keyboard/android/build/
!modules/edgeever-app-installer/android/
modules/edgeever-app-installer/android/build/
+!modules/edgeever-app-store/android/
+modules/edgeever-app-store/android/build/
diff --git a/apps/mobile/modules/edgeever-app-store/android/build.gradle b/apps/mobile/modules/edgeever-app-store/android/build.gradle
new file mode 100644
index 00000000..82032d61
--- /dev/null
+++ b/apps/mobile/modules/edgeever-app-store/android/build.gradle
@@ -0,0 +1,15 @@
+plugins {
+ id 'com.android.library'
+ id 'expo-module-gradle-plugin'
+}
+
+group = 'org.edgeever.appstore'
+version = '1.0.0'
+
+android {
+ namespace "org.edgeever.appstore"
+ defaultConfig {
+ versionCode 1
+ versionName '1.0.0'
+ }
+}
diff --git a/apps/mobile/modules/edgeever-app-store/android/src/main/AndroidManifest.xml b/apps/mobile/modules/edgeever-app-store/android/src/main/AndroidManifest.xml
new file mode 100644
index 00000000..020a24bd
--- /dev/null
+++ b/apps/mobile/modules/edgeever-app-store/android/src/main/AndroidManifest.xml
@@ -0,0 +1,5 @@
+<manifest xmlns:android="http://schemas.android.com/apk/res/android">
+ <queries>
+ <package android:name="com.android.vending" />
+ </queries>
+</manifest>
diff --git a/apps/mobile/modules/edgeever-app-store/android/src/main/java/org/edgeever/appstore/EdgeEverAppStoreModule.kt b/apps/mobile/modules/edgeever-app-store/android/src/main/java/org/edgeever/appstore/EdgeEverAppStoreModule.kt
new file mode 100644
index 00000000..45562d0c
--- /dev/null
+++ b/apps/mobile/modules/edgeever-app-store/android/src/main/java/org/edgeever/appstore/EdgeEverAppStoreModule.kt
@@ -0,0 +1,58 @@
+package org.edgeever.appstore
+
+import android.content.ActivityNotFoundException
+import android.content.Intent
+import android.content.pm.PackageManager
+import android.net.Uri
+import expo.modules.kotlin.modules.Module
+import expo.modules.kotlin.modules.ModuleDefinition
+
+private const val GOOGLE_PLAY_PACKAGE = "com.android.vending"
+private const val RESULT_DISABLED = "disabled"
+private const val RESULT_NOT_INSTALLED = "not-installed"
+private const val RESULT_OPENED = "opened"
+private const val RESULT_UNAVAILABLE = "unavailable"
+
+class EdgeEverAppStoreModule : Module() {
+ override fun definition() = ModuleDefinition {
+ Name("EdgeEverAppStore")
+
+ AsyncFunction("openGooglePlayDetails") { applicationId: String ->
+ val activity = appContext.currentActivity ?: return@AsyncFunction RESULT_UNAVAILABLE
+ val detailsUri = Uri.Builder()
+ .scheme("market")
+ .authority("details")
+ .appendQueryParameter("id", applicationId)
+ .build()
+ val intent = Intent(Intent.ACTION_VIEW, detailsUri).apply {
+ setPackage(GOOGLE_PLAY_PACKAGE)
+ }
+
+ try {
+ activity.startActivity(intent)
+ RESULT_OPENED
+ } catch (_: ActivityNotFoundException) {
+ getGooglePlayFailureReason(activity.packageManager)
+ } catch (_: SecurityException) {
+ getGooglePlayFailureReason(activity.packageManager)
+ }
+ }
+ }
+
+ @Suppress("DEPRECATION")
+ private fun getGooglePlayFailureReason(packageManager: PackageManager): String {
+ return try {
+ val applicationInfo = packageManager.getApplicationInfo(
+ GOOGLE_PLAY_PACKAGE,
+ PackageManager.MATCH_DISABLED_COMPONENTS
+ )
+ val enabledSetting = packageManager.getApplicationEnabledSetting(GOOGLE_PLAY_PACKAGE)
+ val disabled = !applicationInfo.enabled || enabledSetting == PackageManager.COMPONENT_ENABLED_STATE_DISABLED ||
+ enabledSetting == PackageManager.COMPONENT_ENABLED_STATE_DISABLED_USER ||
+ enabledSetting == PackageManager.COMPONENT_ENABLED_STATE_DISABLED_UNTIL_USED
+ if (disabled) RESULT_DISABLED else RESULT_UNAVAILABLE
+ } catch (_: PackageManager.NameNotFoundException) {
+ RESULT_NOT_INSTALLED
+ }
+ }
+}
diff --git a/apps/mobile/modules/edgeever-app-store/expo-module.config.json b/apps/mobile/modules/edgeever-app-store/expo-module.config.json
new file mode 100644
index 00000000..2db887d0
--- /dev/null
+++ b/apps/mobile/modules/edgeever-app-store/expo-module.config.json
@@ -0,0 +1,6 @@
+{
+ "platforms": ["android"],
+ "android": {
+ "modules": ["org.edgeever.appstore.EdgeEverAppStoreModule"]
+ }
+}
diff --git a/apps/mobile/modules/edgeever-app-store/index.ts b/apps/mobile/modules/edgeever-app-store/index.ts
new file mode 100644
index 00000000..c7588503
--- /dev/null
+++ b/apps/mobile/modules/edgeever-app-store/index.ts
@@ -0,0 +1,19 @@
+import { requireNativeModule } from "expo";
+
+export type GooglePlayOpenResult = "disabled" | "not-installed" | "opened" | "unavailable";
+
+type EdgeEverAppStoreNativeModule = {
+ openGooglePlayDetails: (applicationId: string) => Promise<GooglePlayOpenResult | boolean>;
+};
+
+export const openGooglePlayDetails = async (applicationId: string): Promise<GooglePlayOpenResult> => {
+ const result = await requireNativeModule<EdgeEverAppStoreNativeModule>("EdgeEverAppStore")
+ .openGooglePlayDetails(applicationId);
+ if (result === true) {
+ return "opened";
+ }
+ if (result === false) {
+ return "unavailable";
+ }
+ return result;
+};
diff --git a/apps/mobile/modules/edgeever-app-store/package.json b/apps/mobile/modules/edgeever-app-store/package.json
new file mode 100644
index 00000000..7623ce00
--- /dev/null
+++ b/apps/mobile/modules/edgeever-app-store/package.json
@@ -0,0 +1,6 @@
+{
+ "name": "edgeever-app-store",
+ "version": "1.0.0",
+ "main": "index.ts",
+ "private": true
+}
diff --git a/apps/mobile/src/components/AppDialogProvider.tsx b/apps/mobile/src/components/AppDialogProvider.tsx
index f8201fe9..64c5fde6 100644
--- a/apps/mobile/src/components/AppDialogProvider.tsx
+++ b/apps/mobile/src/components/AppDialogProvider.tsx
@@ -1,9 +1,9 @@
import { useCallback, useEffect, useMemo, useState, type ReactNode } from "react";
-import { Modal, StyleSheet, View, type AlertButton } from "react-native";
+import { Modal, StyleSheet, View } from "react-native";
import { useSafeAreaInsets } from "react-native-safe-area-context";
-import { AlertTriangle, ShieldCheck, X } from "./icons";
+import { AlertTriangle, GitHub, GooglePlay, ShieldCheck, X } from "./icons";
import { Pressable, Text } from "./LocalizedText";
-import { registerAppDialogPresenter, type AppDialogRequest } from "./app-dialog-controller";
+import { registerAppDialogPresenter, type AppDialogButton, type AppDialogRequest } from "./app-dialog-controller";
import { translateCurrentMobileText } from "../lib/mobile-locale";
import { resolveMobileThemeStyles, useMobileTheme } from "../lib/mobile-theme";
@@ -21,7 +21,7 @@ export const AppDialogProvider = ({ children }: { children: ReactNode }) => {
}
return request.buttons?.length
? request.buttons
- : [{ text: translateCurrentMobileText("确定") } satisfies AlertButton];
+ : [{ text: translateCurrentMobileText("确定") } satisfies AppDialogButton];
}, [request]);
const cancelButton = buttons.find((button) => button.style === "cancel");
const destructive = buttons.some((button) => button.style === "destructive");
@@ -36,7 +36,7 @@ export const AppDialogProvider = ({ children }: { children: ReactNode }) => {
activeRequest?.options?.onDismiss?.();
}, [cancelButton, request]);
- const selectButton = (button: AlertButton) => {
+ const selectButton = (button: AppDialogButton) => {
setRequest(null);
button.onPress?.();
};
@@ -88,6 +88,7 @@ export const AppDialogProvider = ({ children }: { children: ReactNode }) => {
{[...buttons].reverse().map((button, index) => {
const isDestructive = button.style === "destructive";
const isCancel = button.style === "cancel";
+ const iconColor = isCancel ? "#0f172a" : "#ffffff";
return (
<Pressable
accessibilityRole="button"
@@ -98,6 +99,11 @@ export const AppDialogProvider = ({ children }: { children: ReactNode }) => {
isDestructive ? styles.buttonDanger : isCancel ? styles.buttonOutline : styles.buttonPrimary,
]}
>
+ {button.icon === "google-play"
+ ? <GooglePlay accessibilityElementsHidden color={iconColor} size={19} />
+ : button.icon === "github"
+ ? <GitHub accessibilityElementsHidden color={iconColor} size={18} />
+ : null}
<Text style={[
styles.buttonText,
isDestructive ? styles.buttonTextDanger : isCancel ? styles.buttonTextOutline : styles.buttonTextPrimary,
@@ -203,6 +209,8 @@ const baseStyles = StyleSheet.create({
alignItems: "center",
borderRadius: 7,
borderWidth: 1,
+ flexDirection: "row",
+ gap: 9,
justifyContent: "center",
minHeight: 42,
paddingHorizontal: 16,
diff --git a/apps/mobile/src/components/LocalizedText.tsx b/apps/mobile/src/components/LocalizedText.tsx
index 99a836ae..841bcde8 100644
--- a/apps/mobile/src/components/LocalizedText.tsx
+++ b/apps/mobile/src/components/LocalizedText.tsx
@@ -4,12 +4,13 @@ import {
Pressable as NativePressable,
Text as NativeText,
TextInput as NativeTextInput,
+ type AlertOptions,
type PressableProps,
type TextInputProps,
type TextProps,
} from "react-native";
import { translateCurrentMobileText, useMobileLocale } from "../lib/mobile-locale";
-import { presentAppDialog } from "./app-dialog-controller";
+import { presentAppDialog, type AppDialogButton } from "./app-dialog-controller";
const translateChildren = (children: ReactNode, translate: (value: string) => string): ReactNode =>
Children.map(children, (child) => {
@@ -66,8 +67,15 @@ export const Pressable = forwardRef<ComponentRef<typeof NativePressable>, Pressa
Pressable.displayName = "LocalizedPressable";
+type AppAlertParameters = [
+ title: string,
+ message?: string,
+ buttons?: AppDialogButton[],
+ options?: AlertOptions,
+];
+
export const Alert = {
- alert: (...[title, message, buttons, options]: Parameters<typeof NativeAlert.alert>) => {
+ alert: (...[title, message, buttons, options]: AppAlertParameters) => {
const translatedTitle = translateCurrentMobileText(title);
const translatedMessage = message ? translateCurrentMobileText(message) : message;
const translatedButtons = buttons?.map((button) => ({
diff --git a/apps/mobile/src/components/app-dialog-controller.test.ts b/apps/mobile/src/components/app-dialog-controller.test.ts
index 4f51f1c9..aebdeaf8 100644
--- a/apps/mobile/src/components/app-dialog-controller.test.ts
+++ b/apps/mobile/src/components/app-dialog-controller.test.ts
@@ -17,6 +17,23 @@ describe("app dialog controller", () => {
expect(requests).toEqual([{ title: "Delete?", message: "Cannot be undone." }]);
});
+ it("preserves optional brand icons on dialog actions", () => {
+ const requests: AppDialogRequest[] = [];
+ unregister = registerAppDialogPresenter((request) => requests.push(request));
+
+ expect(presentAppDialog({
+ title: "Update available",
+ buttons: [
+ { icon: "google-play", text: "Update on Google Play" },
+ { icon: "github", text: "Download from GitHub" },
+ ],
+ })).toBe(true);
+ expect(requests[0]?.buttons).toEqual([
+ { icon: "google-play", text: "Update on Google Play" },
+ { icon: "github", text: "Download from GitHub" },
+ ]);
+ });
+
it("falls back when the provider is not mounted", () => {
unregister = registerAppDialogPresenter(() => undefined);
unregister();
diff --git a/apps/mobile/src/components/app-dialog-controller.ts b/apps/mobile/src/components/app-dialog-controller.ts
index 7a9b6c7b..5fdc8c5f 100644
--- a/apps/mobile/src/components/app-dialog-controller.ts
+++ b/apps/mobile/src/components/app-dialog-controller.ts
@@ -1,7 +1,13 @@
import type { AlertButton, AlertOptions } from "react-native";
+export type AppDialogButtonIcon = "github" | "google-play";
+
+export type AppDialogButton = AlertButton & {
+ icon?: AppDialogButtonIcon;
+};
+
export type AppDialogRequest = {
- buttons?: AlertButton[];
+ buttons?: AppDialogButton[];
message?: string;
options?: AlertOptions;
title: string;
diff --git a/apps/mobile/src/components/icons.tsx b/apps/mobile/src/components/icons.tsx
index ca9bf5c4..25eb11fa 100644
--- a/apps/mobile/src/components/icons.tsx
+++ b/apps/mobile/src/components/icons.tsx
@@ -46,6 +46,10 @@ export const FileText = createIcon("file-text");
export const Folder = createIcon("folder");
export const Grid = createIcon("grid");
export const GitHub = createIcon("github");
+export const GooglePlay = ({ color, ...props }: MaterialCommunityIconProps) => {
+ const { resolvedTheme } = useMobileTheme();
+ return <MaterialCommunityIcons name="google-play" {...props} color={resolveMobileThemeColor(color as string | undefined, resolvedTheme)} />;
+};
export const HardDrive = createIcon("hard-drive");
export const Heading2 = createIcon("type");
export const History = createIcon("clock");
diff --git a/apps/mobile/src/lib/mobile-release.test.ts b/apps/mobile/src/lib/mobile-release.test.ts
index 5c0efa26..4795b0b0 100644
--- a/apps/mobile/src/lib/mobile-release.test.ts
+++ b/apps/mobile/src/lib/mobile-release.test.ts
@@ -1,5 +1,6 @@
import { expect, test } from "bun:test";
import {
+ ANDROID_APPLICATION_ID,
ANDROID_INSTALL_UPDATE_SOURCES,
findNewerMobileRelease,
GITHUB_LATEST_RELEASE_URL,
@@ -73,6 +74,7 @@ test("rejects invalid release responses instead of claiming the app is current",
test("offers Google Play and the latest GitHub Release as manual update destinations", () => {
expect(ANDROID_INSTALL_UPDATE_SOURCES).toEqual([
{
+ applicationId: ANDROID_APPLICATION_ID,
fallbackUrl: GOOGLE_PLAY_WEB_URL,
id: "google-play",
labelEn: "Update on Google Play",
diff --git a/apps/mobile/src/lib/mobile-release.ts b/apps/mobile/src/lib/mobile-release.ts
index 06901961..76566e27 100644
--- a/apps/mobile/src/lib/mobile-release.ts
+++ b/apps/mobile/src/lib/mobile-release.ts
@@ -3,20 +3,30 @@ 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 ANDROID_APPLICATION_ID = "org.edgeever.mobile";
export const GOOGLE_PLAY_APP_URL = "market://details?id=org.edgeever.mobile";
export const GOOGLE_PLAY_WEB_URL = "https://play.google.com/store/apps/details?id=org.edgeever.mobile";
-export type MobileInstallUpdateSource = {
- fallbackUrl?: string;
- id: "github" | "google-play";
+type MobileInstallUpdateSourceBase = {
labelEn: string;
labelZh: string;
url: string;
};
+export type MobileInstallUpdateSource =
+ | MobileInstallUpdateSourceBase & {
+ applicationId: string;
+ fallbackUrl: string;
+ id: "google-play";
+ }
+ | MobileInstallUpdateSourceBase & {
+ id: "github";
+ };
+
/** Manual destinations presented when a newer Android binary is available. */
export const ANDROID_INSTALL_UPDATE_SOURCES: readonly MobileInstallUpdateSource[] = [
{
+ applicationId: ANDROID_APPLICATION_ID,
fallbackUrl: GOOGLE_PLAY_WEB_URL,
id: "google-play",
labelEn: "Update on Google Play",
diff --git a/apps/mobile/src/lib/mobile-update-destination.test.ts b/apps/mobile/src/lib/mobile-update-destination.test.ts
new file mode 100644
index 00000000..2a2e229f
--- /dev/null
+++ b/apps/mobile/src/lib/mobile-update-destination.test.ts
@@ -0,0 +1,95 @@
+import { expect, test } from "bun:test";
+import { ANDROID_INSTALL_UPDATE_SOURCES, GOOGLE_PLAY_WEB_URL } from "./mobile-release";
+import { openMobileInstallUpdateSource } from "./mobile-update-destination";
+
+const googlePlay = ANDROID_INSTALL_UPDATE_SOURCES.find((source) => source.id === "google-play");
+const github = ANDROID_INSTALL_UPDATE_SOURCES.find((source) => source.id === "github");
+
+if (!googlePlay || !github) {
+ throw new Error("Android update sources are incomplete");
+}
+
+test("opens the app listing directly in Google Play without invoking a generic URL handler", async () => {
+ const openedApplicationIds: string[] = [];
+ const openedUrls: string[] = [];
+
+ const result = await openMobileInstallUpdateSource(googlePlay, {
+ openGooglePlayDetails: (applicationId) => {
+ openedApplicationIds.push(applicationId);
+ return "opened";
+ },
+ openUrl: async (url) => {
+ openedUrls.push(url);
+ },
+ });
+
+ expect(openedApplicationIds).toEqual(["org.edgeever.mobile"]);
+ expect(openedUrls).toEqual([]);
+ expect(result).toEqual({ status: "opened" });
+});
+
+test("reports that Google Play is not installed without opening a browser automatically", async () => {
+ const openedUrls: string[] = [];
+
+ const result = await openMobileInstallUpdateSource(googlePlay, {
+ openGooglePlayDetails: () => "not-installed",
+ openUrl: async (url) => {
+ openedUrls.push(url);
+ },
+ });
+
+ expect(result).toEqual({
+ reason: "not-installed",
+ status: "google-play-unavailable",
+ });
+ expect(openedUrls).toEqual([]);
+});
+
+test("preserves the disabled Google Play reason", async () => {
+ const result = await openMobileInstallUpdateSource(googlePlay, {
+ openGooglePlayDetails: () => "disabled",
+ openUrl: async () => undefined,
+ });
+
+ expect(result).toEqual({
+ fallbackUrl: GOOGLE_PLAY_WEB_URL,
+ reason: "disabled",
+ status: "google-play-unavailable",
+ });
+});
+
+test("reports Google Play as unavailable when the native launch fails unexpectedly", async () => {
+ const openedUrls: string[] = [];
+
+ const result = await openMobileInstallUpdateSource(googlePlay, {
+ openGooglePlayDetails: () => {
+ throw new Error("native module unavailable");
+ },
+ openUrl: async (url) => {
+ openedUrls.push(url);
+ },
+ });
+
+ expect(result).toEqual({
+ fallbackUrl: GOOGLE_PLAY_WEB_URL,
+ reason: "unavailable",
+ status: "google-play-unavailable",
+ });
+ expect(openedUrls).toEqual([]);
+});
+
+test("opens GitHub through the regular URL handler", async () => {
+ const openedUrls: string[] = [];
+
+ const result = await openMobileInstallUpdateSource(github, {
+ openGooglePlayDetails: () => {
+ throw new Error("Google Play should not be called");
+ },
+ openUrl: async (url) => {
+ openedUrls.push(url);
+ },
+ });
+
+ expect(openedUrls).toEqual([github.url]);
+ expect(result).toEqual({ status: "opened" });
+});
diff --git a/apps/mobile/src/lib/mobile-update-destination.ts b/apps/mobile/src/lib/mobile-update-destination.ts
new file mode 100644
index 00000000..80261e01
--- /dev/null
+++ b/apps/mobile/src/lib/mobile-update-destination.ts
@@ -0,0 +1,52 @@
+import type { MobileInstallUpdateSource } from "./mobile-release";
+import type { GooglePlayOpenResult } from "../../modules/edgeever-app-store";
+
+type MobileUpdateDestinationDependencies = {
+ openGooglePlayDetails: (applicationId: string) => GooglePlayOpenResult | Promise<GooglePlayOpenResult>;
+ openUrl: (url: string) => Promise<unknown>;
+};
+
+type GooglePlayOpenFailure = Exclude<GooglePlayOpenResult, "opened">;
+
+export type MobileUpdateDestinationResult =
+ | { status: "opened" }
+ | {
+ reason: "not-installed";
+ status: "google-play-unavailable";
+ }
+ | {
+ fallbackUrl: string;
+ reason: Exclude<GooglePlayOpenFailure, "not-installed">;
+ status: "google-play-unavailable";
+ };
+
+export const openMobileInstallUpdateSource = async (
+ source: MobileInstallUpdateSource,
+ dependencies: MobileUpdateDestinationDependencies
+): Promise<MobileUpdateDestinationResult> => {
+ if (source.id === "google-play") {
+ let result: GooglePlayOpenResult;
+ try {
+ result = await dependencies.openGooglePlayDetails(source.applicationId);
+ } catch {
+ result = "unavailable";
+ }
+ if (result === "opened") {
+ return { status: "opened" };
+ }
+ if (result === "not-installed") {
+ return {
+ reason: result,
+ status: "google-play-unavailable",
+ };
+ }
+ return {
+ fallbackUrl: source.fallbackUrl,
+ reason: result,
+ status: "google-play-unavailable",
+ };
+ }
+
+ await dependencies.openUrl(source.url);
+ return { status: "opened" };
+};
diff --git a/apps/mobile/src/lib/mobile-update.tsx b/apps/mobile/src/lib/mobile-update.tsx
index 80dc1920..378cc68a 100644
--- a/apps/mobile/src/lib/mobile-update.tsx
+++ b/apps/mobile/src/lib/mobile-update.tsx
@@ -3,6 +3,7 @@ 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 { openGooglePlayDetails } from "../../modules/edgeever-app-store";
import { useMobileLocale } from "./mobile-locale";
import {
ANDROID_INSTALL_UPDATE_SOURCES,
@@ -10,6 +11,7 @@ import {
type MobileInstallUpdateSource,
type MobileRelease,
} from "./mobile-release";
+import { openMobileInstallUpdateSource } from "./mobile-update-destination";
const FOREGROUND_CHECK_INTERVAL_MS = 6 * 60 * 60 * 1000;
@@ -48,23 +50,60 @@ export const MobileUpdateProvider = ({ children }: { children: ReactNode }) => {
const english = resolvedLocale === "en-US";
const installedVersion = Updates.runtimeVersion ?? Constants.expoConfig?.version ?? null;
+ const showLinkError = useCallback(() => {
+ Alert.alert(
+ english ? "Could not open link" : "无法打开链接",
+ english ? "Check your browser settings and try again." : "请检查浏览器设置后重试。"
+ );
+ }, [english]);
+
const openManualUpdateSource = useCallback((source: MobileInstallUpdateSource) => {
- void Linking.openURL(source.url).catch(() => {
- if (source.fallbackUrl) {
- void Linking.openURL(source.fallbackUrl).catch(() => {
- Alert.alert(
- english ? "Could not open link" : "无法打开链接",
- english ? "Check your browser settings and try again." : "请检查浏览器设置后重试。"
- );
- });
+ void openMobileInstallUpdateSource(source, {
+ openGooglePlayDetails,
+ openUrl: Linking.openURL,
+ }).then((result) => {
+ if (result.status !== "google-play-unavailable") {
return;
}
- Alert.alert(
- english ? "Could not open link" : "无法打开链接",
- english ? "Check your browser settings and try again." : "请检查浏览器设置后重试。"
- );
+ if (result.reason === "not-installed") {
+ Alert.alert(
+ english ? "Google Play is not installed" : "未安装 Google Play",
+ english
+ ? "Google Play Store is not installed on this device, so this update channel is unavailable."
+ : "这台设备未安装 Google Play 商店,无法通过该渠道更新。"
+ );
+ return;
+ }
+ const { fallbackUrl, reason } = result;
+ const copy = reason === "disabled"
+ ? {
+ message: english
+ ? "Google Play Store is disabled. Enable it in system settings, or open the web listing instead."
+ : "Google Play 商店已被停用,请先在系统设置中启用,或改用网页版。",
+ title: english ? "Google Play is disabled" : "Google Play 已停用",
+ }
+ : {
+ message: english
+ ? "Google Play Store could not handle this update link. Try again later, or open the web listing instead."
+ : "Google Play 商店无法处理这个更新链接,请稍后重试,或改用网页版。",
+ title: english ? "Could not open Google Play" : "无法打开 Google Play",
+ };
+ Alert.alert(copy.title, copy.message, [
+ {
+ text: english ? "Cancel" : "取消",
+ style: "cancel",
+ },
+ {
+ text: english ? "Open web listing" : "打开网页版",
+ onPress: () => {
+ void Linking.openURL(fallbackUrl).catch(showLinkError);
+ },
+ },
+ ]);
+ }).catch(() => {
+ showLinkError();
});
- }, [english]);
+ }, [english, showLinkError]);
const openInstallUpdateOptions = useCallback((release: MobileRelease) => {
const googlePlay = ANDROID_INSTALL_UPDATE_SOURCES.find((source) => source.id === "google-play");
@@ -83,10 +122,12 @@ export const MobileUpdateProvider = ({ children }: { children: ReactNode }) => {
style: "cancel",
},
{
+ icon: "github",
text: english ? github.labelEn : github.labelZh,
onPress: () => openManualUpdateSource(github),
},
{
+ icon: "google-play",
text: english ? googlePlay.labelEn : googlePlay.labelZh,
onPress: () => openManualUpdateSource(googlePlay),
},