import { Platform } from "react-native"; import { getElectronHost } from "@/desktop/electron/host"; export type DesktopNotificationPermission = "granted" | "denied" | "default"; export interface DesktopDialogAskOptions { title?: string; okLabel?: string; cancelLabel?: string; kind?: "info" | "warning" | "error"; } export interface DesktopDialogOpenOptions { title?: string; defaultPath?: string; directory?: boolean; multiple?: boolean; filters?: Array<{ name: string; extensions: string[]; }>; } export interface DesktopDialogBridge { ask?: (message: string, options?: DesktopDialogAskOptions) => Promise; open?: (options?: DesktopDialogOpenOptions) => Promise; } export interface DesktopNotificationBridge { isSupported?: () => Promise; sendNotification?: ( payload: string | { title: string; body?: string; data?: Record }, ) => Promise; } export interface DesktopOpenerBridge { openUrl?: (url: string) => Promise; } export interface DesktopWindowBridge { label?: string; startMove?: (screenX: number, screenY: number) => void; moving?: (screenX: number, screenY: number) => void; endMove?: () => void; toggleMaximize?: () => Promise; isFullscreen?: () => Promise; onResized?: ( handler: (event: TEvent) => void, ) => Promise<() => void> | (() => void); setBadgeCount?: (count?: number) => Promise; onDragDropEvent?: ( handler: (event: TEvent) => void, ) => Promise<() => void> | (() => void); } export interface DesktopWindowModuleBridge { getCurrentWindow?: () => DesktopWindowBridge; } export interface DesktopEventsBridge { on?: (event: string, handler: (payload: unknown) => void) => Promise<() => void> | (() => void); } export interface DesktopInvokeBridge { invoke?: (command: string, args?: Record) => Promise; } export interface DesktopHostBridge { platform?: string; invoke?: DesktopInvokeBridge["invoke"]; events?: DesktopEventsBridge; window?: DesktopWindowModuleBridge; dialog?: DesktopDialogBridge; notification?: DesktopNotificationBridge; opener?: DesktopOpenerBridge; } declare global { interface Window { paseoDesktop?: DesktopHostBridge; } } export function getDesktopHost(): DesktopHostBridge | null { if (Platform.OS !== "web") { return null; } return getElectronHost(); } export function isDesktop(): boolean { return getDesktopHost() !== null; } export function isDesktopMac(): boolean { if (!isDesktop()) { return false; } if (typeof navigator === "undefined") { return false; } const hostPlatform = getDesktopHost()?.platform?.toLowerCase(); if (hostPlatform === "darwin" || hostPlatform === "mac" || hostPlatform === "macos") { return true; } const ua = navigator.userAgent; return ua.includes("Mac OS") || ua.includes("Macintosh"); }