From b2bc1e62cb7dbf04e558678ead7b3ea3c7e1b9e3 Mon Sep 17 00:00:00 2001 From: Sakamoto Shiina <68018796+ShiinaSakamoto@users.noreply.github.com> Date: Sun, 11 May 2025 15:26:05 +0900 Subject: [PATCH 1/5] [bugfix] Fix window geometry bug that was not save and restore. changes the way how to get appWindow instance from Tauri. --- .../CornerRadiusController.jsx | 11 +++--- .../app/error_boundary/AppErrorBoundary.jsx | 12 +++---- src-ui/app/index.jsx | 4 +++ .../message_input_box/MessageInputBox.jsx | 3 -- .../app/splash_component/SplashComponent.jsx | 9 ++--- .../app/window_title_bar/WindowTitleBar.jsx | 30 +++------------- src-ui/logics/common/useWindow.js | 34 +++++++++++++------ src-ui/logics/configs/hotkeys/useHotkeys.js | 6 ++-- src-ui/logics/main/useMainFunction.js | 8 ++--- src-ui/logics/main/useMessageInputBoxRatio.js | 4 +-- 10 files changed, 53 insertions(+), 68 deletions(-) diff --git a/src-ui/app/_app_controllers/CornerRadiusController.jsx b/src-ui/app/_app_controllers/CornerRadiusController.jsx index 1b84b9ad..b56d20c5 100644 --- a/src-ui/app/_app_controllers/CornerRadiusController.jsx +++ b/src-ui/app/_app_controllers/CornerRadiusController.jsx @@ -1,10 +1,12 @@ import { useState, useEffect } from "react"; -import { getCurrentWindow } from "@tauri-apps/api/window"; +import { store } from "@store"; export const CornerRadiusController = () => { const [is_win11, setIsWin11] = useState(false); const [is_maximized, setIsMaximized] = useState(false); + const appWindow = store.appWindow; + // OS 判定(Win11 なら platformVersion の major ≥13) useEffect(() => { if (navigator.userAgentData?.getHighEntropyValues) { @@ -27,12 +29,11 @@ export const CornerRadiusController = () => { useEffect(() => { let unlisten; const setup = async () => { - const window = await getCurrentWindow(); // 初期状態取得 - setIsMaximized(await window.isMaximized()); + setIsMaximized(await appWindow.isMaximized()); // リサイズ時にも再取得 - const updateMax = () => window.isMaximized().then(setIsMaximized); - unlisten = await window.listen("tauri://resize", updateMax); + const updateMax = () => appWindow.isMaximized().then(setIsMaximized); + unlisten = await appWindow.listen("tauri://resize", updateMax); } setup(); diff --git a/src-ui/app/error_boundary/AppErrorBoundary.jsx b/src-ui/app/error_boundary/AppErrorBoundary.jsx index 0cc5dfb2..4aeb34a2 100644 --- a/src-ui/app/error_boundary/AppErrorBoundary.jsx +++ b/src-ui/app/error_boundary/AppErrorBoundary.jsx @@ -1,5 +1,4 @@ import { useState } from "react"; -import { getCurrentWindow } from "@tauri-apps/api/window"; import { ErrorBoundary } from "react-error-boundary"; import XMarkSvg from "@images/cancel.svg?react"; import CopySvg from "@images/copy.svg?react"; @@ -7,6 +6,8 @@ import CheckMarkSvg from "@images/check_mark.svg?react"; import { ContactsContainer } from "./contacts_container/ContactsContainer"; +import { useWindow } from "@logics_common"; + import styles from "./AppErrorBoundary.module.scss"; export const AppErrorBoundary = ({children}) => { @@ -65,14 +66,9 @@ const ErrorContainer = ({error}) => { }; const CloseButtonContainer = () => { - - const asyncClose = async () => { - const appWindow = await getCurrentWindow(); - appWindow.close(); - }; - + const { asyncCloseApp } = useWindow(); return ( -