99 useMemo ,
1010} from "react" ;
1111import clsx from "clsx" ;
12- import { useMount } from "ahooks" ;
12+ import { useMount , useMutationObserver } from "ahooks" ;
1313
1414import Search from "@/components/Search/Search" ;
1515import InputBox from "@/components/Search/InputBox" ;
@@ -28,10 +28,12 @@ import { useConnectStore } from "@/stores/connectStore";
2828import { useAppearanceStore } from "@/stores/appearanceStore" ;
2929import type { StartPage } from "@/types/chat" ;
3030import {
31+ canNavigateBack ,
3132 hasUploadingAttachment ,
3233 visibleFilterBar ,
3334 visibleSearchBar ,
3435} from "@/utils" ;
36+ import { useTauriFocus } from "@/hooks/useTauriFocus" ;
3537
3638interface SearchChatProps {
3739 isTauri ?: boolean ;
@@ -82,6 +84,7 @@ function SearchChat({
8284 ) ;
8385
8486 const [ state , dispatch ] = useReducer ( appReducer , customInitialState ) ;
87+
8588 const {
8689 isChatMode,
8790 input,
@@ -91,6 +94,52 @@ function SearchChat({
9194 isMCPActive,
9295 isTyping,
9396 } = state ;
97+
98+ const inputRef = useRef < string > ( ) ;
99+ const isChatModeRef = useRef ( false ) ;
100+
101+ const setWindowSize = useCallback ( ( ) => {
102+ const width = 680 ;
103+ let height = 590 ;
104+
105+ const updateAppDialog = document . querySelector ( "#update-app-dialog" ) ;
106+
107+ if ( ! updateAppDialog && ! canNavigateBack ( ) && ! inputRef . current ) {
108+ const { windowMode } = useAppearanceStore . getState ( ) ;
109+
110+ if ( windowMode === "compact" ) {
111+ const searchBar = document . querySelector ( "#search-bar" ) ;
112+ const filterBar = document . querySelector ( "#filter-bar" ) ;
113+
114+ if ( searchBar && filterBar ) {
115+ height = searchBar . clientHeight + filterBar . clientHeight + 16 ;
116+ } else {
117+ height = 82 ;
118+ }
119+
120+ height = Math . min ( height , 88 ) ;
121+ }
122+ }
123+
124+ platformAdapter . setWindowSize ( width , height ) ;
125+ } , [ ] ) ;
126+
127+ useMutationObserver ( setWindowSize , document . body , {
128+ subtree : true ,
129+ childList : true ,
130+ } ) ;
131+
132+ useEffect ( ( ) => {
133+ inputRef . current = input ;
134+ isChatModeRef . current = isChatMode ;
135+
136+ setWindowSize ( ) ;
137+ } , [ input , isChatMode ] ) ;
138+
139+ useTauriFocus ( {
140+ onFocus : setWindowSize ,
141+ } ) ;
142+
94143 useEffect ( ( ) => {
95144 dispatch ( {
96145 type : "SET_SEARCH_ACTIVE" ,
@@ -114,11 +163,6 @@ function SearchChat({
114163 const setTheme = useThemeStore ( ( state ) => state . setTheme ) ;
115164 const setIsDark = useThemeStore ( ( state ) => state . setIsDark ) ;
116165
117- const isChatModeRef = useRef ( false ) ;
118- useEffect ( ( ) => {
119- isChatModeRef . current = isChatMode ;
120- } , [ isChatMode ] ) ;
121-
122166 useMount ( async ( ) => {
123167 const isWin10 = await platformAdapter . isWindows10 ( ) ;
124168
0 commit comments