From c42fcf9ac49bbb70234504dd2b8eae845a240616 Mon Sep 17 00:00:00 2001 From: Huang Xin Date: Mon, 17 Nov 2025 21:05:56 +0530 Subject: [PATCH] fix: save reading progress when closing app directly in reader page, closes #2346 (#2461) --- apps/readest-app/src/app/reader/components/ReaderContent.tsx | 3 ++- apps/readest-app/src/utils/window.ts | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/apps/readest-app/src/app/reader/components/ReaderContent.tsx b/apps/readest-app/src/app/reader/components/ReaderContent.tsx index 6fbc7a49..ca9c0106 100644 --- a/apps/readest-app/src/app/reader/components/ReaderContent.tsx +++ b/apps/readest-app/src/app/reader/components/ReaderContent.tsx @@ -138,7 +138,7 @@ const ReaderContent: React.FC<{ ids?: string; settings: SystemSettings }> = ({ i const handleCloseBooks = throttle(async () => { const settings = useSettingsStore.getState().settings; - await Promise.all(bookKeys.map((key) => saveConfigAndCloseBook(key))); + await Promise.all(bookKeys.map(async (key) => await saveConfigAndCloseBook(key))); await saveSettings(envConfig, settings); }, 200); @@ -166,6 +166,7 @@ const ReaderContent: React.FC<{ ids?: string; settings: SystemSettings }> = ({ i const openWithFiles = (await parseOpenWithFiles()) || []; if (appService?.hasWindow) { if (openWithFiles.length > 0) { + tauriHandleOnCloseWindow(handleCloseBooks); return await tauriHandleClose(); } const currentWindow = getCurrentWindow(); diff --git a/apps/readest-app/src/utils/window.ts b/apps/readest-app/src/utils/window.ts index 34e2d7f9..3b3ff472 100644 --- a/apps/readest-app/src/utils/window.ts +++ b/apps/readest-app/src/utils/window.ts @@ -49,7 +49,8 @@ export const tauriHandleClose = async () => { export const tauriHandleOnCloseWindow = async (callback: () => void) => { const currentWindow = getCurrentWindow(); - return currentWindow.listen(TauriEvent.WINDOW_CLOSE_REQUESTED, async () => { + return await currentWindow.onCloseRequested(async (event) => { + event.preventDefault(); await callback(); if (currentWindow.label.startsWith('reader')) { await emitTo('main', 'close-reader-window', { label: currentWindow.label });