diff --git a/package.json b/package.json index d7ae086b..2127aa24 100644 --- a/package.json +++ b/package.json @@ -8,6 +8,7 @@ "dev": "vite", "build": "tsc && vite build", "test:desktop-reopen": "node --experimental-strip-types --test tests/desktopReopen.test.ts", + "test:browser-runtime": "node --experimental-strip-types --test tests/browserRuntime.test.ts", "test:close-preference": "node --experimental-strip-types --test tests/codexClosePreference.test.ts", "test:reset-credits": "node --experimental-strip-types --test tests/resetCredits.test.ts", "test:updater": "node --experimental-strip-types --test tests/updateInstallation.test.ts tests/updaterToolchain.test.ts", diff --git a/src/App.tsx b/src/App.tsx index 6b11a1e2..9e836c6c 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -1,5 +1,4 @@ import { useState, useEffect, useCallback, useMemo, useRef } from "react"; -import { getCurrentWindow } from "@tauri-apps/api/window"; import { useAccounts } from "./hooks/useAccounts"; import { useDesktopReopen } from "./hooks/useDesktopReopen"; import { useCodexClosePreference } from "./hooks/useCodexClosePreference"; @@ -42,6 +41,7 @@ import { type AutoWarmupWindow, type AutoWarmupWindowKind, } from "./lib/autoWarmupPolicy"; +import { getTauriWindow } from "./lib/tauriWindow"; import "./App.css"; const AUTO_WARMUP_CHECK_INTERVAL_MS = 30 * 1000; @@ -65,7 +65,6 @@ type AutoWarmupLedger = Record< lastAutoWindowKind?: AutoWarmupWindowKind; } >; -const appWindow = getCurrentWindow(); const isMacOs = typeof navigator !== "undefined" && /(Mac|iPhone|iPod|iPad)/i.test(navigator.userAgent); @@ -388,14 +387,14 @@ function App() { const handleTitlebarDrag = useCallback( (event: React.MouseEvent) => { if (!isTauriRuntime() || event.button !== 0) return; - void appWindow.startDragging(); + void getTauriWindow()?.startDragging(); }, [] ); const handleTitlebarDoubleClick = useCallback(() => { if (!isTauriRuntime()) return; - void appWindow.toggleMaximize(); + void getTauriWindow()?.toggleMaximize(); }, []); const toggleMask = (accountId: string) => { @@ -522,6 +521,9 @@ function App() { useEffect(() => { if (!isTauriRuntime() || isMacOs) return; + const appWindow = getTauriWindow(); + if (!appWindow) return; + let unlisten: (() => void) | undefined; const syncMaximizedState = async () => { @@ -1354,11 +1356,11 @@ function App() { onDoubleClick={handleTitlebarDoubleClick} className={`h-full flex-1 select-none cursor-default ${isMacOs ? "ml-18 mr-2" : "mr-3"}`} /> - {!isMacOs && ( + {isTauriRuntime() && !isMacOs && (