fix: replace onCloseRequested with beforeunload to fix window close

The Tauri onCloseRequested async handler was preventing the window
from actually closing. Using beforeunload for the save flush instead.
This commit is contained in:
Your Name
2026-02-15 21:46:44 +02:00
parent 86b833a11b
commit f5c6e2e2a5

View File

@@ -1,5 +1,4 @@
import { useState, useEffect, useCallback } from "react"; import { useState, useEffect, useCallback } from "react";
import { getCurrentWindow } from "@tauri-apps/api/window";
import { AnimatePresence, motion } from "framer-motion"; import { AnimatePresence, motion } from "framer-motion";
import { springs, fadeSlideLeft, fadeSlideRight } from "@/lib/motion"; import { springs, fadeSlideLeft, fadeSlideRight } from "@/lib/motion";
import { useAppStore } from "@/stores/app-store"; import { useAppStore } from "@/stores/app-store";
@@ -27,11 +26,12 @@ export default function App() {
// Flush pending board saves before the app window closes // Flush pending board saves before the app window closes
useEffect(() => { useEffect(() => {
const unlisten = getCurrentWindow().onCloseRequested(async () => { function handleBeforeUnload() {
useBoardStore.getState().closeBoard(); useBoardStore.getState().closeBoard();
}); }
window.addEventListener("beforeunload", handleBeforeUnload);
return () => { return () => {
unlisten.then((fn) => fn()); window.removeEventListener("beforeunload", handleBeforeUnload);
}; };
}, []); }, []);