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) => {