@@ -48,6 +48,9 @@ class CodeContextGenerator:
4848
4949 def __init__ (self , root ):
5050 self .root = root
51+
52+ # 先隐藏窗口,避免在配置过程中显示
53+ self .root .withdraw ()
5154
5255 self .languages = LANGUAGES
5356 # 初始化设置管理器
@@ -65,15 +68,11 @@ def __init__(self, root):
6568 self .version = __version__
6669
6770 self .root .title (f"{ self .texts ['app_title' ]} v{ self .version } " )
71+
72+ # 设置窗口大小但不设置位置
6873 self .root .geometry ("800x600" )
6974 self .root .minsize (600 , 400 )
7075
71- try :
72- icon_path = Path (__file__ ).parent / RESOURCES_DIR / ICON_FILENAME
73- self .root .iconbitmap (str (icon_path ))
74- except Exception as e :
75- print (f"无法加载图标: { str (e )} " )
76-
7776 # 根据初始设置立即应用窗口置顶状态
7877 if self .is_topmost .get ():
7978 self .root .wm_attributes ("-topmost" , 1 )
@@ -100,6 +99,7 @@ def __init__(self, root):
10099 font = (UI_FONT_FAMILY , UI_HEADING_FONT_SIZE , UI_HEADING_FONT_STYLE ),
101100 )
102101
102+ # 重新设置窗口大小(如果DEFAULT_WINDOW_SIZE不同的话)
103103 self .root .geometry (DEFAULT_WINDOW_SIZE )
104104 self .root .minsize (* DEFAULT_WINDOW_MIN_SIZE )
105105
@@ -128,15 +128,25 @@ def __init__(self, root):
128128 )
129129
130130 self .root .protocol ("WM_DELETE_WINDOW" , self .on_close )
131+
132+ # 先居中窗口,然后显示 - 修改这里
131133 self .gui .center_window (self .root )
134+ self .root .deiconify () # 显示窗口
132135
133- self ._initial_loading = True # 添加一个标志表示正在初始化
134- self ._current_loaded_directory = None # 添加这一行来跟踪当前加载的目录
136+ self ._initial_loading = True
137+ self ._current_loaded_directory = None
135138
136139 self ._setup_initial_directory ()
137140 self .root .after (100 , self ._setup_tree_bindings )
138141
139142 self .root .after (100 , self ._setup_tree_bindings )
143+
144+ try :
145+ icon_path = Path (__file__ ).parent / RESOURCES_DIR / ICON_FILENAME
146+ self .root .iconbitmap (str (icon_path ))
147+ except Exception as e :
148+ print (f"无法加载图标: { str (e )} " )
149+
140150 # 初始化系统托盘图标
141151 self ._create_system_tray ()
142152
@@ -166,7 +176,6 @@ def _auto_save_task(self):
166176 finally :
167177 self ._schedule_auto_save ()
168178
169-
170179 def _setup_initial_directory (self ):
171180 """设置初始目录并安排加载"""
172181 if self .dir_history and len (self .dir_history ) > 0 :
@@ -422,6 +431,7 @@ def update_tree(self):
422431 if directory and Path (directory ).is_dir ():
423432 # 更新目录树时强制刷新 .gitignore 缓存
424433 from ai_code_context_helper .file_utils import clear_gitignore_cache
434+
425435 clear_gitignore_cache ()
426436 # 先保存当前的滚动位置
427437 try :
@@ -555,13 +565,13 @@ def collect_expanded_items(parent=""):
555565 pass
556566
557567 collect_expanded_items ()
558-
568+
559569 if "." not in expanded_items :
560570 expanded_items .append ("." )
561571
562572 self .settings .expanded_states [current_dir ] = expanded_items
563573 self .settings .settings_changed = True
564-
574+
565575 # 立即保存关键状态
566576 self .settings .save_settings ()
567577
@@ -598,8 +608,9 @@ def on_setting_option_changed(self, *args):
598608 # 如果是gitignore相关设置变更,强制刷新缓存
599609 if args and self .settings .settings_changed :
600610 from ai_code_context_helper .file_utils import clear_gitignore_cache
611+
601612 clear_gitignore_cache ()
602-
613+
603614 self .tree_ops .generate_tree (preserve_state = True )
604615
605616 def on_dir_changed (self , * args ):
0 commit comments