replace onCloseRequested with beforeunload to fix window close
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
import { useState, useEffect, useCallback } from "react";
|
||||
import { getCurrentWindow } from "@tauri-apps/api/window";
|
||||
import { AnimatePresence, motion } from "framer-motion";
|
||||
import { springs, fadeSlideLeft, fadeSlideRight } from "@/lib/motion";
|
||||
import { useAppStore } from "@/stores/app-store";
|
||||
@@ -27,11 +26,12 @@ export default function App() {
|
||||
|
||||
// Flush pending board saves before the app window closes
|
||||
useEffect(() => {
|
||||
const unlisten = getCurrentWindow().onCloseRequested(async () => {
|
||||
function handleBeforeUnload() {
|
||||
useBoardStore.getState().closeBoard();
|
||||
});
|
||||
}
|
||||
window.addEventListener("beforeunload", handleBeforeUnload);
|
||||
return () => {
|
||||
unlisten.then((fn) => fn());
|
||||
window.removeEventListener("beforeunload", handleBeforeUnload);
|
||||
};
|
||||
}, []);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user