fix(native): a widget tap that starts the app opens what it points at

A tap on a widget or a Live Activity hands the app
com.liketrek.trek://navigate/<path>. A running app gets it as appUrlOpen;
an app started by the tap gets it as its launch URL, which nothing read, so
the path was lost and the app opened its start page (the packing widget
landed on the trip's plan instead of its lists). The launch link is now
followed once per launch.
This commit is contained in:
Maurice
2026-11-12 16:53:04 +01:00
parent 4983b3407c
commit 56b9bac031
2 changed files with 51 additions and 1 deletions
+26 -1
View File
@@ -11,9 +11,12 @@ import { prepareKeyboardFields } from './keyboardFields';
import { scrollToTop, startNativeApp } from './nativeApp';
import { keepOfflineShellFresh } from './offlineShell';
import { isNativeApp, isNativeIos } from './platform';
import { openPushTarget } from './push';
import { trackTouchInput } from './touchInput';
vi.mock('@capacitor/app', () => ({ App: { addListener: vi.fn(), minimizeApp: vi.fn() } }));
vi.mock('@capacitor/app', () => ({
App: { addListener: vi.fn(), minimizeApp: vi.fn(), getLaunchUrl: vi.fn(async () => undefined) },
}));
vi.mock('@capacitor/keyboard', () => ({
Keyboard: { setAccessoryBarVisible: vi.fn(), addListener: vi.fn(async () => ({ remove: vi.fn() })) },
}));
@@ -193,4 +196,26 @@ describe('startNativeApp', () => {
expect(report).not.toHaveBeenCalled();
vi.unstubAllGlobals();
});
it('follows the link a widget tap launched the app with, once per launch', async () => {
sessionStorage.clear();
vi.mocked(App.getLaunchUrl).mockResolvedValue({ url: 'com.liketrek.trek://navigate/trips/5?tab=listen' });
startNativeApp();
await vi.waitFor(() => expect(openPushTarget).toHaveBeenCalledWith('/trips/5?tab=listen'));
// A reload of the page in the same launch does not follow it again.
vi.mocked(openPushTarget).mockClear();
startNativeApp();
await Promise.resolve();
await Promise.resolve();
expect(openPushTarget).not.toHaveBeenCalled();
});
it('leaves the start page alone for a launch without a TREK link', async () => {
sessionStorage.clear();
vi.mocked(App.getLaunchUrl).mockResolvedValue({ url: 'https://example.com/elsewhere' });
startNativeApp();
await Promise.resolve();
await Promise.resolve();
expect(openPushTarget).not.toHaveBeenCalled();
});
});