From a2d1993bee239ea8fb6164942fab80e4dde66855 Mon Sep 17 00:00:00 2001 From: tianma-if Date: Mon, 21 Sep 2026 20:16:30 +0800 Subject: [PATCH] fix(android): open GitHub update links Fixes #423 --- .../src/lib/mobile-update-destination.test.ts | 36 ++++++++++++------- .../src/lib/mobile-update-destination.ts | 6 ++-- apps/mobile/src/lib/mobile-update.tsx | 2 +- 3 files changed, 28 insertions(+), 16 deletions(-) diff --git a/apps/mobile/src/lib/mobile-update-destination.test.ts b/apps/mobile/src/lib/mobile-update-destination.test.ts index 2a2e229f..2e1fdd94 100644 --- a/apps/mobile/src/lib/mobile-update-destination.test.ts +++ b/apps/mobile/src/lib/mobile-update-destination.test.ts @@ -14,13 +14,15 @@ test("opens the app listing directly in Google Play without invoking a generic U const openedUrls: string[] = []; const result = await openMobileInstallUpdateSource(googlePlay, { + linking: { + openURL: async (url) => { + openedUrls.push(url); + }, + }, openGooglePlayDetails: (applicationId) => { openedApplicationIds.push(applicationId); return "opened"; }, - openUrl: async (url) => { - openedUrls.push(url); - }, }); expect(openedApplicationIds).toEqual(["org.edgeever.mobile"]); @@ -32,10 +34,12 @@ test("reports that Google Play is not installed without opening a browser automa const openedUrls: string[] = []; const result = await openMobileInstallUpdateSource(googlePlay, { - openGooglePlayDetails: () => "not-installed", - openUrl: async (url) => { - openedUrls.push(url); + linking: { + openURL: async (url) => { + openedUrls.push(url); + }, }, + openGooglePlayDetails: () => "not-installed", }); expect(result).toEqual({ @@ -47,8 +51,8 @@ test("reports that Google Play is not installed without opening a browser automa test("preserves the disabled Google Play reason", async () => { const result = await openMobileInstallUpdateSource(googlePlay, { + linking: { openURL: async () => undefined }, openGooglePlayDetails: () => "disabled", - openUrl: async () => undefined, }); expect(result).toEqual({ @@ -62,12 +66,14 @@ test("reports Google Play as unavailable when the native launch fails unexpected const openedUrls: string[] = []; const result = await openMobileInstallUpdateSource(googlePlay, { + linking: { + openURL: async (url) => { + openedUrls.push(url); + }, + }, openGooglePlayDetails: () => { throw new Error("native module unavailable"); }, - openUrl: async (url) => { - openedUrls.push(url); - }, }); expect(result).toEqual({ @@ -80,14 +86,18 @@ test("reports Google Play as unavailable when the native launch fails unexpected test("opens GitHub through the regular URL handler", async () => { const openedUrls: string[] = []; + const linking = { + async openURL(url: string) { + expect(this).toBe(linking); + openedUrls.push(url); + }, + }; const result = await openMobileInstallUpdateSource(github, { + linking, openGooglePlayDetails: () => { throw new Error("Google Play should not be called"); }, - openUrl: async (url) => { - openedUrls.push(url); - }, }); expect(openedUrls).toEqual([github.url]); diff --git a/apps/mobile/src/lib/mobile-update-destination.ts b/apps/mobile/src/lib/mobile-update-destination.ts index 80261e01..baa130ab 100644 --- a/apps/mobile/src/lib/mobile-update-destination.ts +++ b/apps/mobile/src/lib/mobile-update-destination.ts @@ -2,8 +2,10 @@ import type { MobileInstallUpdateSource } from "./mobile-release"; import type { GooglePlayOpenResult } from "../../modules/edgeever-app-store"; type MobileUpdateDestinationDependencies = { + linking: { + openURL: (url: string) => Promise; + }; openGooglePlayDetails: (applicationId: string) => GooglePlayOpenResult | Promise; - openUrl: (url: string) => Promise; }; type GooglePlayOpenFailure = Exclude; @@ -47,6 +49,6 @@ export const openMobileInstallUpdateSource = async ( }; } - await dependencies.openUrl(source.url); + await dependencies.linking.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 d1e5711d..9e9d239c 100644 --- a/apps/mobile/src/lib/mobile-update.tsx +++ b/apps/mobile/src/lib/mobile-update.tsx @@ -59,8 +59,8 @@ export const MobileUpdateProvider = ({ children }: { children: ReactNode }) => { const openManualUpdateSource = useCallback((source: MobileInstallUpdateSource) => { void openMobileInstallUpdateSource(source, { + linking: Linking, openGooglePlayDetails, - openUrl: Linking.openURL, }).then((result) => { if (result.status !== "google-play-unavailable") { return;