fix tauri module resolution in browser builds - dynamic imports for window controls

This commit is contained in:
2026-04-03 06:10:07 +03:00
parent a8349c3f18
commit a77b2d491c
2 changed files with 41 additions and 29 deletions
+21 -16
View File
@@ -1,6 +1,6 @@
import { useEffect, useState } from 'react'
import { NavLink, useLocation, useNavigate } from 'react-router-dom'
import { getCurrentWindow } from '@tauri-apps/api/window'
import { motion, AnimatePresence } from 'framer-motion'
import {
Search,
@@ -110,17 +110,20 @@ export default function AppHeader({ pinned, onTogglePin }: Props) {
if (!isTauri) return
let cancelled = false
let unlisten: (() => void) | undefined
const win = getCurrentWindow()
win.isMaximized().then(v => {
if (!cancelled) setMaximized(v)
}).catch(() => {})
win.onResized(async () => {
const v = await win.isMaximized()
if (!cancelled) setMaximized(v)
}).then(u => {
if (cancelled) u()
else unlisten = u
}).catch(() => {})
import('@tauri-apps/api/window').then(({ getCurrentWindow }) => {
if (cancelled) return
const win = getCurrentWindow()
win.isMaximized().then(v => {
if (!cancelled) setMaximized(v)
}).catch(() => {})
win.onResized(async () => {
const v = await win.isMaximized()
if (!cancelled) setMaximized(v)
}).then(u => {
if (cancelled) u()
else unlisten = u
}).catch(() => {})
})
return () => {
cancelled = true
unlisten?.()
@@ -129,10 +132,12 @@ export default function AppHeader({ pinned, onTogglePin }: Props) {
function callWin(action: 'minimize' | 'toggleMaximize' | 'close') {
if (!isTauri) return
const win = getCurrentWindow()
if (action === 'minimize') win.minimize()
else if (action === 'toggleMaximize') win.toggleMaximize()
else win.close()
import('@tauri-apps/api/window').then(({ getCurrentWindow }) => {
const win = getCurrentWindow()
if (action === 'minimize') win.minimize()
else if (action === 'toggleMaximize') win.toggleMaximize()
else win.close()
})
}
const showBack = !TOP_LEVEL_PATHS.has(location.pathname)