Treat the mobile web surface as a constrained runtime so sync loads smaller message pages, keeps fewer warm session caches, and evicts heavy inactive sessions instead of retaining them across switches. Limit mobile message-record and turn-model caches to reduce memory pressure on phones while preserving bounded initial page expansion for large final turns. Split the mobile session status bar so the collapsed state avoids subscribing to the full session/status list; the expensive grouping work now only mounts for the expanded list. Verified with bun run type-check and bun run lint.
45 lines
1.4 KiB
TypeScript
45 lines
1.4 KiB
TypeScript
import { isDesktopShell } from '@/lib/desktop';
|
|
|
|
export type HostedSurface = 'desktop' | 'mobile';
|
|
|
|
declare global {
|
|
interface Window {
|
|
__OPENCHAMBER_SURFACE__?: HostedSurface;
|
|
}
|
|
}
|
|
|
|
const MOBILE_SURFACE_MAX_WIDTH = 768;
|
|
|
|
const isTouchOrCoarsePointer = (): boolean => {
|
|
if (typeof window === 'undefined') return false;
|
|
|
|
const coarsePointer = typeof window.matchMedia === 'function'
|
|
? window.matchMedia('(pointer: coarse)').matches || window.matchMedia('(hover: none)').matches
|
|
: false;
|
|
const touchPoints = typeof navigator !== 'undefined' ? navigator.maxTouchPoints ?? 0 : 0;
|
|
return coarsePointer || touchPoints > 0;
|
|
};
|
|
|
|
export const detectHostedSurface = (): HostedSurface => {
|
|
if (typeof window === 'undefined') return 'desktop';
|
|
|
|
const explicitSurface = window.__OPENCHAMBER_SURFACE__;
|
|
if (explicitSurface === 'mobile' || explicitSurface === 'desktop') {
|
|
return explicitSurface;
|
|
}
|
|
|
|
const override = new URLSearchParams(window.location.search).get('surface');
|
|
if (override === 'mobile' || override === 'desktop') {
|
|
return override;
|
|
}
|
|
|
|
if (isDesktopShell()) return 'desktop';
|
|
|
|
const width = window.innerWidth || window.screen?.width || 0;
|
|
return width > 0 && width <= MOBILE_SURFACE_MAX_WIDTH && isTouchOrCoarsePointer()
|
|
? 'mobile'
|
|
: 'desktop';
|
|
};
|
|
|
|
export const isMobileSurfaceRuntime = (): boolean => detectHostedSurface() === 'mobile';
|