From 53e7f2526c8a03c89e5808e74b9239a61609a2cd Mon Sep 17 00:00:00 2001 From: Huang Xin Date: Sat, 12 Apr 2025 19:42:36 +0800 Subject: [PATCH] fix: window maximized and fullscreen now don't conflict with each other (#872) --- .../src-tauri/capabilities/default.json | 1 + apps/readest-app/src/utils/window.ts | 17 ++++++++++++++--- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/apps/readest-app/src-tauri/capabilities/default.json b/apps/readest-app/src-tauri/capabilities/default.json index f372850d..0bc7d2f7 100644 --- a/apps/readest-app/src-tauri/capabilities/default.json +++ b/apps/readest-app/src-tauri/capabilities/default.json @@ -57,6 +57,7 @@ "core:window:allow-center", "core:window:allow-minimize", "core:window:allow-maximize", + "core:window:allow-unmaximize", "core:window:allow-set-size", "core:window:allow-set-focus", "core:window:allow-is-maximized", diff --git a/apps/readest-app/src/utils/window.ts b/apps/readest-app/src/utils/window.ts index ee187087..d747d079 100644 --- a/apps/readest-app/src/utils/window.ts +++ b/apps/readest-app/src/utils/window.ts @@ -15,7 +15,14 @@ export const tauriHandleMinimize = async () => { }; export const tauriHandleToggleMaximize = async () => { - getCurrentWindow().toggleMaximize(); + const currentWindow = getCurrentWindow(); + const isFullscreen = await currentWindow.isFullscreen(); + if (isFullscreen) { + await currentWindow.setFullscreen(false); + await currentWindow.unmaximize(); + } else { + getCurrentWindow().toggleMaximize(); + } }; export const tauriHandleClose = async () => { @@ -34,8 +41,12 @@ export const tauriHandleOnCloseWindow = async (callback: () => void) => { export const tauriHandleToggleFullScreen = async () => { const currentWindow = getCurrentWindow(); const isFullscreen = await currentWindow.isFullscreen(); - const newIsFullscreen = !isFullscreen; - await currentWindow.setFullscreen(newIsFullscreen); + const isMaximized = await currentWindow.isMaximized(); + if (isMaximized) { + await currentWindow.unmaximize(); + } else { + await currentWindow.setFullscreen(!isFullscreen); + } }; export const tauriHandleSetAlwaysOnTop = async (isAlwaysOnTop: boolean) => {