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
@@ -537,6 +537,7 @@ export interface SettingsPayload {
|
||||
openInAppId?: string;
|
||||
gitProviderId?: string;
|
||||
gitModelId?: string;
|
||||
pwaAppName?: string;
|
||||
|
||||
[key: string]: unknown;
|
||||
}
|
||||
|
||||
@@ -110,6 +110,7 @@ export type DesktopSettings = {
|
||||
zenModel?: string;
|
||||
gitProviderId?: string;
|
||||
gitModelId?: string;
|
||||
pwaAppName?: string;
|
||||
toolCallExpansion?: 'collapsed' | 'activity' | 'detailed';
|
||||
userMessageRenderingMode?: 'markdown' | 'plain';
|
||||
stickyUserHeader?: boolean;
|
||||
|
||||
@@ -74,6 +74,14 @@ const persistToLocalStorage = (settings: DesktopSettings) => {
|
||||
if (typeof settings.openInAppId === 'string' && settings.openInAppId.length > 0) {
|
||||
localStorage.setItem('openInAppId', settings.openInAppId);
|
||||
}
|
||||
if (typeof settings.pwaAppName === 'string') {
|
||||
const normalized = settings.pwaAppName.trim().replace(/\s+/g, ' ').slice(0, 64);
|
||||
if (normalized.length > 0) {
|
||||
localStorage.setItem('openchamber.pwaName', normalized);
|
||||
} else {
|
||||
localStorage.removeItem('openchamber.pwaName');
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
type PersistApi = {
|
||||
@@ -784,6 +792,10 @@ const sanitizeWebSettings = (payload: unknown): DesktopSettings | null => {
|
||||
if (typeof candidate.openInAppId === 'string' && candidate.openInAppId.length > 0) {
|
||||
result.openInAppId = candidate.openInAppId;
|
||||
}
|
||||
if (typeof candidate.pwaAppName === 'string') {
|
||||
const normalized = candidate.pwaAppName.trim().replace(/\s+/g, ' ').slice(0, 64);
|
||||
result.pwaAppName = normalized.length > 0 ? normalized : '';
|
||||
}
|
||||
|
||||
if (typeof candidate.messageLimit === 'number' && Number.isFinite(candidate.messageLimit)) {
|
||||
result.messageLimit = candidate.messageLimit;
|
||||
|
||||
@@ -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';
|
||||
};
|
||||
@@ -143,7 +143,7 @@ export const SETTINGS_PAGE_METADATA: readonly SettingsPageMeta[] = [
|
||||
title: 'Appearance',
|
||||
group: 'appearance',
|
||||
kind: 'single',
|
||||
keywords: ['theme', 'font', 'spacing', 'padding', 'corner radius', 'radius', 'input bar', 'terminal'],
|
||||
keywords: ['theme', 'font', 'spacing', 'padding', 'corner radius', 'radius', 'input bar', 'terminal', 'pwa', 'install name', 'app shortcuts'],
|
||||
},
|
||||
{
|
||||
slug: 'chat',
|
||||
|
||||
Reference in New Issue
Block a user