Files
openmotion/shared/platform-host.ts
open-design-crew[bot] 6d38d942f2 feat(desktop): cloud-first thin shell, local atoms, signed config, and Sentry observability (#1001)
* feat(desktop): cloud-first thin shell, local atoms, signed config, and complete Sentry observability

* feat(desktop): add in-app update banner, release notes preview, and mandatory update gate

* fix(ci): resolve backend typecheck, dock short-host floor, ci-scope, and source privacy scan

* fix(desktop): address all P1 and P2 security/robustness review findings on PR #1001

* fix(local-atoms): accept TOML array-of-tables headers in merged structure check

---------

Co-authored-by: heggria <bshengtao@gmail.com>
2026-11-24 19:13:55 -08:00

208 lines
6.0 KiB
TypeScript

export type DesktopPlatform = 'darwin' | 'win32' | 'linux';
export type DesktopTitleBarStyle = 'hiddenInset' | 'hiddenOverlay' | 'custom' | 'native';
export type DesktopChromeInsets = {
platform: DesktopPlatform;
titleBarStyle: DesktopTitleBarStyle;
insetLeft: number;
insetRight: number;
titleBarHeight: number;
safeTop?: number;
zoomFactor?: number;
customWindowControls: boolean;
fullscreen: boolean;
maximized: boolean;
};
export type DesktopUpdateStatus =
| 'idle'
| 'checking'
| 'available'
| 'downloading'
| 'downloaded'
| 'up-to-date'
| 'unsupported'
| 'error';
export type DesktopUpdateState = {
status: DesktopUpdateStatus;
currentVersion: string;
availableVersion?: string;
progress?: number;
message?: string;
releaseNotes?: string;
releaseNotesUrl?: string;
checkedAt?: string;
mandatory?: boolean;
minRequiredVersion?: string;
mandatoryReason?: string;
downloadUrl?: string;
};
export type DesktopMenuAction =
| 'open-settings'
| 'open-about'
| 'open-help'
| 'check-updates'
| 'export-logs'
| 'report-issue'
| 'join-community-feishu'
| 'join-community-discord'
| 'new-project'
| 'open-mcp-connect'
| 'open-agent-runtimes'
| 'reload-app';
export type DesktopAppInfo = {
isDesktop: true;
platform: DesktopPlatform;
arch: string;
appVersion: string;
electronVersion: string;
chromeVersion: string;
nodeVersion: string;
isPackaged: boolean;
logDir: string;
dataDir: string;
releaseChannel: 'stable' | 'beta' | 'dev';
};
export type DesktopDiagnosticExportResult = {
ok: boolean;
canceled?: boolean;
path?: string;
entryCount?: number;
error?: string;
};
export type DesktopSplashStep = 'engine' | 'agents' | 'account' | 'ready';
export type DesktopSplashAccountView = {
state: string;
name?: string;
email?: string;
plan?: string;
authorizationUrl?: string;
userCode?: string;
browserOpened?: boolean;
syncing?: boolean;
error?: string;
errorCode?: string;
};
export type DesktopSplashProgress = {
step: DesktopSplashStep;
status: string;
detail?: string;
agentsCount?: number;
agentsNames?: string[];
mode?: 'booting' | 'signin' | 'welcome' | 'error';
account?: DesktopSplashAccountView;
errorMessage?: string;
};
export type DesktopBridgeApi = {
getAppInfo: () => Promise<DesktopAppInfo>;
getChromeState: () => Promise<DesktopChromeInsets>;
subscribeChromeState: (callback: (state: DesktopChromeInsets) => void) => () => void;
setTheme: (theme: 'light' | 'dark') => Promise<void>;
windowMinimize: () => Promise<void>;
windowToggleMaximize: () => Promise<void>;
windowClose: () => Promise<void>;
checkForUpdates: () => Promise<DesktopUpdateState>;
downloadUpdate: () => Promise<DesktopUpdateState>;
installUpdateNow: () => Promise<{ ok: boolean; error?: string }>;
getUpdateState: () => Promise<DesktopUpdateState>;
subscribeUpdateState: (callback: (state: DesktopUpdateState) => void) => () => void;
exportDesktopLogs: () => Promise<DesktopDiagnosticExportResult>;
openLogsFolder: () => Promise<{ ok: boolean; path?: string; error?: string }>;
openExternal: (url: string) => Promise<{ ok: boolean; error?: string }>;
subscribeMenuActions: (callback: (action: DesktopMenuAction) => void) => () => void;
notifyRendererReady: () => void;
retryDesktopStartup?: () => Promise<void>;
splashContinueToStudio?: () => Promise<void>;
splashStartSignIn?: () => Promise<Record<string, unknown>>;
splashCancelSignIn?: () => Promise<Record<string, unknown>>;
splashRefreshAccount?: () => Promise<Record<string, unknown>>;
};
/**
* Resolves platform-specific title bar style and safe inset geometry so macOS
* traffic lights, Windows caption overlay, and Linux controls never collide
* with shared Studio navigation chrome.
*
* When `zoomFactor` differs from 1.0, OS-rendered overlay insets (fixed in OS DIPs)
* are compensated into CSS pixels so native window controls never collide with
* Studio chrome when zoomed out or waste header width when zoomed in.
*
* On Linux with `customWindowControls: true`, Studio renders window controls
* in-flow inside `.om-app-header`, so `insetRight` is 0 (preventing double inset)
* while `safeTop` reserves the title bar height for full-viewport overlays.
*/
export function resolveDesktopChrome(input: {
platform: DesktopPlatform;
fullscreen?: boolean;
maximized?: boolean;
linuxCustomTitleBar?: boolean;
zoomFactor?: number;
}): DesktopChromeInsets {
const fullscreen = Boolean(input.fullscreen);
const maximized = Boolean(input.maximized);
const rawZoom = input.zoomFactor;
const zoomFactor =
typeof rawZoom === 'number' && Number.isFinite(rawZoom) && rawZoom > 0
? Math.min(3, Math.max(0.25, rawZoom))
: 1;
const scaleDipToCss = (dip: number): number =>
dip <= 0 ? 0 : Math.ceil(dip / zoomFactor);
const baseTitleBarHeight = 46;
const titleBarHeight = Math.max(baseTitleBarHeight, scaleDipToCss(baseTitleBarHeight));
if (input.platform === 'darwin') {
const safeTop = fullscreen ? 0 : titleBarHeight;
return {
platform: 'darwin',
titleBarStyle: 'hiddenInset',
insetLeft: fullscreen ? 0 : scaleDipToCss(78),
insetRight: 0,
titleBarHeight,
safeTop,
zoomFactor,
customWindowControls: false,
fullscreen,
maximized,
};
}
if (input.platform === 'win32') {
const safeTop = fullscreen ? 0 : titleBarHeight;
return {
platform: 'win32',
titleBarStyle: 'hiddenOverlay',
insetLeft: 0,
insetRight: fullscreen ? 0 : scaleDipToCss(138),
titleBarHeight,
safeTop,
zoomFactor,
customWindowControls: false,
fullscreen,
maximized,
};
}
const useCustom = input.linuxCustomTitleBar !== false;
return {
platform: 'linux',
titleBarStyle: useCustom ? 'custom' : 'native',
insetLeft: 0,
insetRight: 0,
titleBarHeight: useCustom ? titleBarHeight : baseTitleBarHeight,
safeTop: useCustom && !fullscreen ? titleBarHeight : 0,
zoomFactor,
customWindowControls: useCustom,
fullscreen,
maximized,
};
}