Close window when document is closed with 'open with Readest'

This commit is contained in:
chrox
2024-12-04 18:58:05 +01:00
parent 999e4828db
commit 32ffaa0e05
3 changed files with 25 additions and 17 deletions
@@ -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();
}
}
};
@@ -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<HTMLDivElement>;
@@ -73,21 +75,6 @@ const WindowButtons: React.FC<WindowButtonsProps> = ({
// 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();
+14
View File
@@ -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();
};