@@ -127,19 +127,19 @@ def setup_ui(self):
127127 switch_box = Gtk .Box (orientation = Gtk .Orientation .HORIZONTAL , spacing = 12 )
128128 switch_box .set_margin_top (12 )
129129
130- self .dont_show_switch = Gtk .Switch ()
131- self .dont_show_switch .set_active (False )
132- self .dont_show_switch .set_valign (Gtk .Align .CENTER )
130+ self .show_switch = Gtk .Switch ()
131+ self .show_switch .set_active (False )
132+ self .show_switch .set_valign (Gtk .Align .CENTER )
133133
134134 switch_label = Gtk .Label (label = _ ("Show dialog on startup" ))
135135 switch_label .set_xalign (0 )
136136 switch_label .set_hexpand (True )
137137
138138 switch_box .append (switch_label )
139- switch_box .append (self .dont_show_switch )
139+ switch_box .append (self .show_switch )
140140
141141 # Set initial state based on saved preference
142- self .dont_show_switch .set_active (not self .get_show_preference ())
142+ self .show_switch .set_active (self .get_show_preference ())
143143
144144 content_box .append (switch_box )
145145
@@ -163,8 +163,8 @@ def setup_ui(self):
163163
164164 def on_close (self , button ):
165165 """Handle close button click"""
166- # Save or remove preference based on switch state
167- self .save_preference (dont_show = self .dont_show_switch .get_active ())
166+ # Save preference based on switch state
167+ self .save_preference (show = self .show_switch .get_active ())
168168
169169 # Close the dialog
170170 self .destroy ()
@@ -179,50 +179,29 @@ def get_show_preference(self):
179179 try :
180180 with open (self .config_file , "r" ) as f :
181181 preferences = json .load (f )
182- # Return True if we should show the dialog (inverted from saved setting)
182+ # Return whether we should show the dialog (direct from saved setting)
183183 return preferences .get ("show_welcome" , True )
184184 except Exception :
185185 # If there's an error reading the file, default to showing the dialog
186186 return True
187187
188- def save_preference (self , dont_show = False ):
188+ def save_preference (self , show = True ):
189189 """
190190 Save the preference for showing the welcome dialog
191191
192192 Parameters:
193- dont_show (bool): If True, don't show the dialog; if False, show it
193+ show (bool): If True, show the dialog; if False, don't show it
194194 """
195195 # Make sure the directory exists
196196 os .makedirs (os .path .dirname (self .config_file ), exist_ok = True )
197197
198- if dont_show :
199- # Save preference to not show the dialog
200- preferences = {"show_welcome" : False }
201- try :
202- with open (self .config_file , "w" ) as f :
203- json .dump (preferences , f )
204- except Exception as e :
205- print (f"Error saving welcome dialog preference: { e } " )
206- else :
207- # Ensure the dialog will be shown next time by removing the file
208- # or updating the preference
209- if os .path .exists (self .config_file ):
210- try :
211- # Option 1: Update the file to show dialog
212- with open (self .config_file , "r+" ) as f :
213- try :
214- preferences = json .load (f )
215- preferences ["show_welcome" ] = False
216- f .seek (0 )
217- f .truncate ()
218- json .dump (preferences , f )
219- except json .JSONDecodeError :
220- # If file is corrupted, recreate it
221- f .seek (0 )
222- f .truncate ()
223- json .dump ({"show_welcome" : False }, f )
224- except Exception as e :
225- print (f"Error updating welcome dialog preference: { e } " )
198+ # Save preference directly
199+ preferences = {"show_welcome" : show }
200+ try :
201+ with open (self .config_file , "w" ) as f :
202+ json .dump (preferences , f )
203+ except Exception as e :
204+ print (f"Error saving welcome dialog preference: { e } " )
226205
227206 @staticmethod
228207 def should_show_welcome ():
0 commit comments