diff --git a/apps/readest-app/src/app/reader/components/ReaderContent.tsx b/apps/readest-app/src/app/reader/components/ReaderContent.tsx index 357571c1..cbb1ef19 100644 --- a/apps/readest-app/src/app/reader/components/ReaderContent.tsx +++ b/apps/readest-app/src/app/reader/components/ReaderContent.tsx @@ -10,6 +10,8 @@ import { useBookDataStore } from '@/store/bookDataStore'; import { useReaderStore } from '@/store/readerStore'; import { useSidebarStore } from '@/store/sidebarStore'; import { SystemSettings } from '@/types/settings'; +import { parseOpenWithFiles } from '@/helpers/cli'; +import { tauriHandleClose } from '@/utils/window'; import { uniqueId } from '@/utils/misc'; import useBooksManager from '../hooks/useBooksManager'; @@ -80,14 +82,19 @@ const ReaderContent: React.FC<{ settings: SystemSettings }> = ({ settings }) => saveSettingsAndGoToLibrary(); }; - const handleCloseBook = (bookKey: string) => { + const handleCloseBook = async (bookKey: string) => { saveConfigAndCloseBook(bookKey); if (sideBarBookKey === bookKey) { setSideBarBookKey(getNextBookKey(sideBarBookKey)); } dismissBook(bookKey); if (bookKeys.filter((key) => key !== bookKey).length == 0) { - saveSettingsAndGoToLibrary(); + const openWithFiles = (await parseOpenWithFiles()) || []; + if (openWithFiles.length > 0) { + tauriHandleClose(); + } else { + saveSettingsAndGoToLibrary(); + } } }; diff --git a/apps/readest-app/src/components/WindowButtons.tsx b/apps/readest-app/src/components/WindowButtons.tsx index 73fbe03d..69aca011 100644 --- a/apps/readest-app/src/components/WindowButtons.tsx +++ b/apps/readest-app/src/components/WindowButtons.tsx @@ -1,6 +1,8 @@ import clsx from 'clsx'; import React, { useEffect, useRef } from 'react'; +import { tauriHandleMinimize, tauriHandleToggleMaximize, tauriHandleClose } from '@/utils/window'; + interface WindowButtonsProps { className?: string; headerRef?: React.RefObject; @@ -73,21 +75,6 @@ const WindowButtons: React.FC = ({ // eslint-disable-next-line react-hooks/exhaustive-deps }, []); - const tauriHandleMinimize = async () => { - const { getCurrentWindow } = await import('@tauri-apps/api/window'); - getCurrentWindow().minimize(); - }; - - const tauriHandleToggleMaximize = async () => { - const { getCurrentWindow } = await import('@tauri-apps/api/window'); - getCurrentWindow().toggleMaximize(); - }; - - const tauriHandleClose = async () => { - const { getCurrentWindow } = await import('@tauri-apps/api/window'); - getCurrentWindow().close(); - }; - const handleMinimize = async () => { if (onMinimize) { onMinimize(); diff --git a/apps/readest-app/src/utils/window.ts b/apps/readest-app/src/utils/window.ts new file mode 100644 index 00000000..35f9d0e6 --- /dev/null +++ b/apps/readest-app/src/utils/window.ts @@ -0,0 +1,14 @@ +export const tauriHandleMinimize = async () => { + const { getCurrentWindow } = await import('@tauri-apps/api/window'); + getCurrentWindow().minimize(); +}; + +export const tauriHandleToggleMaximize = async () => { + const { getCurrentWindow } = await import('@tauri-apps/api/window'); + getCurrentWindow().toggleMaximize(); +}; + +export const tauriHandleClose = async () => { + const { getCurrentWindow } = await import('@tauri-apps/api/window'); + getCurrentWindow().close(); +};