From e1b85d8f95f1148627ae5e371b1d35712aaa46cb Mon Sep 17 00:00:00 2001 From: Mohamed Boudra Date: Wed, 21 Jan 2026 11:16:32 +0700 Subject: [PATCH] fix(app): guard Tauri window import for Metro --- packages/app/src/utils/tauri-window.ts | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/packages/app/src/utils/tauri-window.ts b/packages/app/src/utils/tauri-window.ts index 118bf1a99..b8cd5084d 100644 --- a/packages/app/src/utils/tauri-window.ts +++ b/packages/app/src/utils/tauri-window.ts @@ -4,12 +4,24 @@ import { getIsTauriMac, TAURI_TRAFFIC_LIGHT_WIDTH, TAURI_TRAFFIC_LIGHT_HEIGHT } let tauriWindow: any = null; +// Runtime check for Tauri environment +function isTauriEnvironment(): boolean { + return typeof window !== "undefined" && + (window as any).__TAURI__ !== undefined; +} + async function getTauriWindow() { if (tauriWindow) return tauriWindow; - if (!getIsTauriMac()) return null; + + // Double-check: both environment check AND platform check + if (!isTauriEnvironment() || !getIsTauriMac()) { + return null; + } try { - const { getCurrentWindow } = await import("@tauri-apps/api/window"); + // @metro-ignore tells Metro to skip bundling this import + // It will be resolved at runtime in Tauri's WebView + const { getCurrentWindow } = await import(/* @metro-ignore */ "@tauri-apps/api/window"); tauriWindow = getCurrentWindow(); return tauriWindow; } catch {