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
This commit is contained in:
+3
-2
@@ -50,8 +50,9 @@ export default function App() {
|
|||||||
|
|
||||||
// The title bar close button skips beforeunload on some platforms
|
// The title bar close button skips beforeunload on some platforms
|
||||||
const appWindow = getCurrentWindow();
|
const appWindow = getCurrentWindow();
|
||||||
const unlistenClose = appWindow.onCloseRequested(() => {
|
const unlistenClose = appWindow.onCloseRequested(async () => {
|
||||||
useBoardStore.getState().closeBoard();
|
// tauri destroys the window only once this handler settles
|
||||||
|
await useBoardStore.getState().flushBoard();
|
||||||
});
|
});
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ interface BoardState {
|
|||||||
interface BoardActions {
|
interface BoardActions {
|
||||||
openBoard: (boardId: string) => Promise<void>;
|
openBoard: (boardId: string) => Promise<void>;
|
||||||
closeBoard: () => void;
|
closeBoard: () => void;
|
||||||
|
flushBoard: () => Promise<void>;
|
||||||
|
|
||||||
addColumn: (title: string) => void;
|
addColumn: (title: string) => void;
|
||||||
updateColumnTitle: (columnId: string, title: string) => void;
|
updateColumnTitle: (columnId: string, title: string) => void;
|
||||||
@@ -128,6 +129,15 @@ export const useBoardStore = create<BoardState & BoardActions>()(
|
|||||||
set({ board: null, saving: false, lastSaved: null });
|
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 --
|
// -- Column actions --
|
||||||
|
|
||||||
addColumn: (title: string) => {
|
addColumn: (title: string) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user