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 });