feat(pwa): pre-install naming, install UX, and manifest shortcuts (#554)
* feat(web-pwa): add dynamic manifest endpoint with blob fallback * feat(ui-pwa): add install prompt and manifest sync hooks * feat(settings): add web-only preinstall app name preference * fix(web-pwa): scope recent shortcuts to active project sessions --------- Co-authored-by: Bohdan Triapitsyn <artmore@protonmail.com>
This commit is contained in:
committed by
GitHub
co-authored by
Bohdan Triapitsyn
parent
575cfa2604
commit
ca18b8be0f
@@ -0,0 +1,41 @@
|
||||
export type PWADisplayMode =
|
||||
| 'browser'
|
||||
| 'standalone'
|
||||
| 'minimal-ui'
|
||||
| 'fullscreen'
|
||||
| 'window-controls-overlay'
|
||||
| 'twa';
|
||||
|
||||
const DISPLAY_MODES: Array<Exclude<PWADisplayMode, 'browser' | 'twa'>> = ['standalone', 'minimal-ui', 'fullscreen', 'window-controls-overlay'];
|
||||
|
||||
export const PWA_INSTALL_NAME_STORAGE_KEY = 'openchamber.pwaName';
|
||||
export const PWA_RECENT_SESSIONS_STORAGE_KEY = 'openchamber.pwaRecentSessions';
|
||||
|
||||
const matchesDisplayMode = (mode: Exclude<PWADisplayMode, 'browser' | 'twa'>): boolean => {
|
||||
if (typeof window === 'undefined' || typeof window.matchMedia !== 'function') {
|
||||
return false;
|
||||
}
|
||||
return window.matchMedia(`(display-mode: ${mode})`).matches;
|
||||
};
|
||||
|
||||
export const getPWADisplayMode = (): PWADisplayMode => {
|
||||
if (typeof window === 'undefined') {
|
||||
return 'browser';
|
||||
}
|
||||
|
||||
if (typeof document !== 'undefined' && document.referrer.startsWith('android-app://')) {
|
||||
return 'twa';
|
||||
}
|
||||
|
||||
const navigatorStandalone = Boolean((window.navigator as Navigator & { standalone?: boolean }).standalone);
|
||||
if (navigatorStandalone) {
|
||||
return 'standalone';
|
||||
}
|
||||
|
||||
const matched = DISPLAY_MODES.find((mode) => matchesDisplayMode(mode));
|
||||
return matched ?? 'browser';
|
||||
};
|
||||
|
||||
export const isInstalledPWARuntime = (): boolean => {
|
||||
return getPWADisplayMode() !== 'browser';
|
||||
};
|
||||
Reference in New Issue
Block a user