mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-21 11:36:05 +00:00
feat(native): a capability handshake between the app binary and the server's UI
The UI ships with the server and the binary through the stores, so the two drift. TrekShell.getCapabilities now reports the binary's shell API, version and native features by name (iOS and Android), and the UI turns each native feature on only where the binary has it; a binary from before the handshake counts as shell API 1 with none. The other way round, the server names the oldest binary its UI works with (minNativeShellApi), and an app below it is asked to update with a link to its store.
This commit is contained in:
@@ -3,6 +3,7 @@ import { Keyboard } from '@capacitor/keyboard';
|
||||
import { SplashScreen } from '@capacitor/splash-screen';
|
||||
import { StatusBar, Style } from '@capacitor/status-bar';
|
||||
import { isEffectivelyOffline } from '../sync/networkMode';
|
||||
import { checkAppUpdate } from './capabilities';
|
||||
import { keepOfflineShellFresh } from './offlineShell';
|
||||
import { isNativeApp, isNativeIos } from './platform';
|
||||
import { reportNativeFailure } from './reportFailure';
|
||||
@@ -20,6 +21,9 @@ export function startNativeApp(): void {
|
||||
|
||||
followThemeInStatusBar();
|
||||
|
||||
// What this binary can do, and whether this server's UI needs a newer one.
|
||||
void checkAppUpdate(fetchServerFeatures);
|
||||
|
||||
// Android's back gesture: through the app's own history first, and only
|
||||
// then out of the app, the way a browser tab would behave.
|
||||
void App.addListener('backButton', ({ canGoBack }) => {
|
||||
@@ -58,3 +62,10 @@ function followThemeInStatusBar(): void {
|
||||
apply();
|
||||
new MutationObserver(apply).observe(root, { attributes: true, attributeFilter: ['class'] });
|
||||
}
|
||||
|
||||
/** The server's feature flags, bounded so a slow server cannot hold anything up. */
|
||||
async function fetchServerFeatures(): Promise<{ minNativeShellApi?: unknown }> {
|
||||
const res = await fetch('/api/health/features', { credentials: 'same-origin', signal: AbortSignal.timeout(8000) });
|
||||
if (!res.ok) return {};
|
||||
return (await res.json()) as { minNativeShellApi?: unknown };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user