mirror of
https://github.com/priyanshujain/margin.git
synced 2026-10-02 19:17:03 +00:00
fix(persist): flush pending save on navigate-away and quit
Edits are saved on an 800ms debounce, so leaving a book within that window lost the latest changes. Flush a dirty book before openBook / closeBook swap state (covers All books, open-another, Cmd+N), and add a window close-request handler that saves before destroying on quit. Claude-Session: https://claude.ai/code/session_01RzTWrLiy4zGuw2hZSQGamk
This commit is contained in:
1 parent
0bc3e36ee6
commit
14eb3c4427
3 files changed
+29
-3
No files matched your search
+17
-1
@@ -1,10 +1,11 @@
|
||||
import { useEffect } from "react";
|
||||
import { listen } from "@tauri-apps/api/event";
|
||||
import { getCurrentWindow } from "@tauri-apps/api/window";
|
||||
import { Library } from "./components/Library";
|
||||
import { EditorView } from "./components/EditorView";
|
||||
import { useBook } from "./store/useBook";
|
||||
import { isDesktop } from "./ipc";
|
||||
import { newBook } from "./library";
|
||||
import { newBook, saveBook } from "./library";
|
||||
import { runExport } from "./export/run";
|
||||
import { checkForUpdates } from "./updater";
|
||||
|
||||
@@ -27,6 +28,21 @@ function App() {
|
||||
};
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
if (!isDesktop) return;
|
||||
const win = getCurrentWindow();
|
||||
const unlisten = win.onCloseRequested(async (event) => {
|
||||
const { book, dirty } = useBook.getState();
|
||||
if (!book || !dirty) return;
|
||||
event.preventDefault();
|
||||
await saveBook(book).catch(() => {});
|
||||
win.destroy();
|
||||
});
|
||||
return () => {
|
||||
unlisten.then((stop) => stop());
|
||||
};
|
||||
}, []);
|
||||
|
||||
return book ? <EditorView /> : <Library onOpen={openBook} />;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user