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; getChromeState: () => Promise; subscribeChromeState: (callback: (state: DesktopChromeInsets) => void) => () => void; setTheme: (theme: 'light' | 'dark') => Promise; windowMinimize: () => Promise; windowToggleMaximize: () => Promise; windowClose: () => Promise; checkForUpdates: () => Promise; downloadUpdate: () => Promise; installUpdateNow: () => Promise<{ ok: boolean; error?: string }>; getUpdateState: () => Promise; subscribeUpdateState: (callback: (state: DesktopUpdateState) => void) => () => void; exportDesktopLogs: () => Promise; 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; splashContinueToStudio?: () => Promise; splashStartSignIn?: () => Promise>; splashCancelSignIn?: () => Promise>; splashRefreshAccount?: () => Promise>; }; /** * 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, }; }