From a6544eafc064f348259907398b40a7a8eb122149 Mon Sep 17 00:00:00 2001 From: lashman Date: Mon, 16 Nov 2026 19:46:03 +0200 Subject: [PATCH] wait for the pending save before the window closes the flush was fired and forgotten, so an edit made in the last half second died with the window --- src/App.tsx | 5 +++-- src/stores/board-store.ts | 10 ++++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/App.tsx b/src/App.tsx index afc395f..20aeb12 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -50,8 +50,9 @@ export default function App() { // The title bar close button skips beforeunload on some platforms const appWindow = getCurrentWindow(); - const unlistenClose = appWindow.onCloseRequested(() => { - useBoardStore.getState().closeBoard(); + const unlistenClose = appWindow.onCloseRequested(async () => { + // tauri destroys the window only once this handler settles + await useBoardStore.getState().flushBoard(); }); return () => { diff --git a/src/stores/board-store.ts b/src/stores/board-store.ts index d6cc45b..5f582f8 100644 --- a/src/stores/board-store.ts +++ b/src/stores/board-store.ts @@ -21,6 +21,7 @@ interface BoardState { interface BoardActions { openBoard: (boardId: string) => Promise; closeBoard: () => void; + flushBoard: () => Promise; addColumn: (title: string) => void; updateColumnTitle: (columnId: string, title: string) => void; @@ -128,6 +129,15 @@ export const useBoardStore = create()( set({ board: null, saving: false, lastSaved: null }); }, + flushBoard: async () => { + if (saveTimeout) { + clearTimeout(saveTimeout); + saveTimeout = null; + } + const { board } = get(); + if (board) await saveBoard(board); + }, + // -- Column actions -- addColumn: (title: string) => {