import { isDesktop } from './platform'; export type DesktopUpdatePhase = | 'checking' | 'uptodate' | 'available' | 'downloading' | 'installing' | 'relaunching' | 'error'; export interface DesktopUpdateProgress { phase: DesktopUpdatePhase; message: string; currentVersion?: string; newVersion?: string; downloadPercent?: number; downloadedBytes?: number; totalBytes?: number; } export interface DesktopUpdateResult { ok: boolean; phase: DesktopUpdatePhase; message: string; currentVersion?: string; newVersion?: string; } export interface DesktopBridge { openWidgetWindow: (instance: import('../types/floatingWidget').FloatingWidgetInstance) => Promise; closeWidgetWindow: (id: string) => Promise; focusWidgetWindow: (id: string) => Promise; showNativeNotification: (title: string, body: string) => Promise; checkForUpdates: () => Promise<{ available: boolean; version?: string; message?: string }>; runDesktopUpdate: ( onProgress?: (progress: DesktopUpdateProgress) => void, ) => Promise; getAppVersion: () => Promise; syncMainWindowTitle: () => Promise; } declare global { interface Window { __goldenDesktopBridge?: DesktopBridge; } } export function getDesktopBridge(): DesktopBridge | null { if (!isDesktop()) return null; return window.__goldenDesktopBridge ?? null; } export async function showDesktopNativeNotification(title: string, body: string): Promise { const bridge = getDesktopBridge(); if (!bridge) return; try { await bridge.showNativeNotification(title, body); } catch { /* ignore */ } } export async function checkDesktopUpdates(): Promise<{ available: boolean; version?: string; message?: string }> { const bridge = getDesktopBridge(); if (!bridge) return { available: false, message: '데스크톱 앱에서만 사용 가능합니다.' }; return bridge.checkForUpdates(); } export async function runDesktopUpdate( onProgress?: (progress: DesktopUpdateProgress) => void, ): Promise { const bridge = getDesktopBridge(); if (!bridge?.runDesktopUpdate) { return { ok: false, phase: 'error', message: '데스크톱 앱에서만 사용 가능합니다.' }; } return bridge.runDesktopUpdate(onProgress); } export async function getDesktopAppVersion(): Promise { const bridge = getDesktopBridge(); if (!bridge) return null; try { return await bridge.getAppVersion(); } catch { return null; } } export async function syncDesktopMainWindowTitle(): Promise { const bridge = getDesktopBridge(); if (!bridge?.syncMainWindowTitle) return null; try { return await bridge.syncMainWindowTitle(); } catch { return null; } }