mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-21 19:40:34 +00:00
fix(native): a widget tap opens its page every time, also after iOS ended the page
A widget or Live Activity tap reached the UI as Capacitor's appUrlOpen, or as the launch URL. When iOS had ended the web view's process in the background, the event went to the old page's listeners and was lost, and the reloaded page found the same link in getLaunchUrl that it had already followed once and skipped it: the second tap on the packing widget opened the start page. The binary now takes com.liketrek.trek://navigate links itself and hands them over like a quick action, held until the UI takes it and kept for a page that is still loading. It reports the feature appLinks, and the UI only follows the link through Capacitor for binaries without it.
This commit is contained in:
@@ -5,7 +5,7 @@ import { StatusBar, Style } from '@capacitor/status-bar';
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
||||
import { closeTopOverlay } from '../mobile/overlayStack';
|
||||
import { isEffectivelyOffline } from '../sync/networkMode';
|
||||
import { checkAppUpdate } from './capabilities';
|
||||
import { checkAppUpdate, hasNativeFeature } from './capabilities';
|
||||
import { installNativeGeolocation } from './geolocation';
|
||||
import { prepareKeyboardFields } from './keyboardFields';
|
||||
import { scrollToTop, startNativeApp } from './nativeApp';
|
||||
@@ -28,6 +28,7 @@ vi.mock('../sync/networkMode', () => ({ isEffectivelyOffline: vi.fn() }));
|
||||
vi.mock('./capabilities', () => ({
|
||||
checkAppUpdate: vi.fn(async () => false),
|
||||
loadNativeCapabilities: vi.fn(async () => ({})),
|
||||
hasNativeFeature: vi.fn(() => false),
|
||||
}));
|
||||
vi.mock('./geolocation', () => ({ installNativeGeolocation: vi.fn() }));
|
||||
vi.mock('./sharedFiles', () => ({ startSharedFiles: vi.fn(async () => {}) }));
|
||||
@@ -51,6 +52,7 @@ beforeEach(() => {
|
||||
vi.mocked(isNativeIos).mockReturnValue(false);
|
||||
vi.mocked(isEffectivelyOffline).mockReturnValue(false);
|
||||
vi.mocked(keepOfflineShellFresh).mockResolvedValue();
|
||||
vi.mocked(hasNativeFeature).mockReturnValue(false);
|
||||
document.documentElement.classList.remove('dark');
|
||||
document.documentElement.removeAttribute('data-native-app');
|
||||
document.documentElement.removeAttribute('data-native-ios');
|
||||
@@ -210,6 +212,18 @@ describe('startNativeApp', () => {
|
||||
expect(openPushTarget).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('leaves widget links to the binary when it hands them over as quick actions', async () => {
|
||||
sessionStorage.clear();
|
||||
vi.mocked(hasNativeFeature).mockImplementation((feature) => feature === 'appLinks');
|
||||
vi.mocked(App.getLaunchUrl).mockResolvedValue({ url: 'com.liketrek.trek://navigate/trips/5?tab=listen' });
|
||||
startNativeApp();
|
||||
await vi.waitFor(() => expect(hasNativeFeature).toHaveBeenCalledWith('appLinks'));
|
||||
await Promise.resolve();
|
||||
expect(App.getLaunchUrl).not.toHaveBeenCalled();
|
||||
expect(vi.mocked(App.addListener).mock.calls.some(([name]) => name === 'appUrlOpen')).toBe(false);
|
||||
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' });
|
||||
|
||||
@@ -5,7 +5,7 @@ import { StatusBar, Style } from '@capacitor/status-bar';
|
||||
import { closeTopOverlay } from '../mobile/overlayStack';
|
||||
import { useSettingsStore } from '../store/settingsStore';
|
||||
import { isEffectivelyOffline } from '../sync/networkMode';
|
||||
import { checkAppUpdate, loadNativeCapabilities } from './capabilities';
|
||||
import { checkAppUpdate, hasNativeFeature, loadNativeCapabilities } from './capabilities';
|
||||
import { installNativeGeolocation } from './geolocation';
|
||||
import { fadeInImages } from './imageFade';
|
||||
import { keepFieldInView } from './keepFieldInView';
|
||||
@@ -54,13 +54,18 @@ export function startNativeApp(): void {
|
||||
// A quick action on the app icon opens its page, also the one the app was launched with.
|
||||
void loadNativeCapabilities().then(() => startQuickActions());
|
||||
|
||||
// A widget or Live Activity tap opens com.liketrek.trek://navigate/<path>.
|
||||
void App.addListener('appUrlOpen', ({ url }) => {
|
||||
const prefix = `${APP_URL_SCHEME}://navigate`;
|
||||
if (url.startsWith(prefix)) openPushTarget(url.slice(prefix.length) || '/');
|
||||
// A widget or Live Activity tap opens com.liketrek.trek://navigate/<path>. A
|
||||
// binary with the feature appLinks hands it over as a quick action instead,
|
||||
// held until taken, so it is only followed here for older binaries.
|
||||
void loadNativeCapabilities().then(() => {
|
||||
if (hasNativeFeature('appLinks')) return;
|
||||
void App.addListener('appUrlOpen', ({ url }) => {
|
||||
const prefix = `${APP_URL_SCHEME}://navigate`;
|
||||
if (url.startsWith(prefix)) openPushTarget(url.slice(prefix.length) || '/');
|
||||
});
|
||||
// A tap that launched the app comes as the launch URL, not as appUrlOpen.
|
||||
void openLaunchLink();
|
||||
});
|
||||
// A tap that launched the app comes as the launch URL, not as appUrlOpen.
|
||||
void openLaunchLink();
|
||||
|
||||
// A tap on the status bar scrolls the list under it back to the top, as in
|
||||
// every iOS app (the status-bar plugin fires statusTap on iOS).
|
||||
|
||||
@@ -211,9 +211,12 @@ export interface TrekShellPlugin {
|
||||
): Promise<{ remove: () => Promise<void> }>;
|
||||
/** Feature quickActions (iOS): the actions a long press on the app icon shows, in the UI's language. */
|
||||
setQuickActions(options: { items: NativeQuickAction[] }): Promise<void>;
|
||||
/** Feature quickActions: the action the app was launched with, before the UI ran. */
|
||||
/**
|
||||
* Feature quickActions: the action the app was launched with, before the UI ran.
|
||||
* With the feature appLinks also a widget or Live Activity tap, as its path.
|
||||
*/
|
||||
takeQuickAction(): Promise<{ path: string | null }>;
|
||||
/** Feature quickActions: an action chosen while the app was running. */
|
||||
/** Feature quickActions: an action chosen (with appLinks: a widget tapped) while the app was running. */
|
||||
addListener(
|
||||
event: 'quickAction',
|
||||
listener: (payload: { path: string }) => void
|
||||
|
||||
Reference in New Issue
Block a user