@@ -27,6 +27,7 @@ public partial class MainWindow : Window
2727 private CancellationTokenSource ? _inflight ;
2828 private DispatcherTimer ? _autoTimer ;
2929 private bool _busy ;
30+ private bool _applying ;
3031 private string ? _lastCountryCode ;
3132
3233 /// <summary>Set by App; performs a real application shutdown (window lives in tray).</summary>
@@ -55,6 +56,7 @@ public partial class MainWindow : Window
5556 // settings controls
5657 private RadioButton _closeTrayRadio = null ! , _closeQuitRadio = null ! ;
5758 private CheckBox _topmostChk = null ! , _flagChk = null ! , _compactChk = null ! ;
59+ private ToggleButton _autoBtn = null ! ;
5860
5961 private static readonly IBrush Muted = new SolidColorBrush ( Color . Parse ( "#B9C7EC" ) ) ;
6062 private static readonly IBrush Accent = new SolidColorBrush ( Color . Parse ( "#4FD1FF" ) ) ;
@@ -101,7 +103,8 @@ public MainWindow()
101103 this . FindControl < Button > ( "CloseBtn" ) ! . Click += ( _ , _ ) => OnCloseRequested ( ) ;
102104 _checkBtn . Click += async ( _ , _ ) => await CheckAsync ( ) ;
103105 this . FindControl < Button > ( "CopyBtn" ) ! . Click += OnCopy ;
104- this . FindControl < ToggleButton > ( "AutoBtn" ) ! . IsCheckedChanged += OnAutoToggled ;
106+ _autoBtn = this . FindControl < ToggleButton > ( "AutoBtn" ) ! ;
107+ _autoBtn . IsCheckedChanged += OnAutoToggled ;
105108
106109 // ---- hud view wiring ----
107110 _hudView . PointerPressed += OnDrag ;
@@ -135,6 +138,7 @@ private async void OnOpened(object? sender, EventArgs e)
135138 Topmost = _settings . Topmost ;
136139 _pinIcon . Foreground = Topmost ? Accent : Muted ;
137140 SetCompact ( _settings . Compact , save : false ) ;
141+ _autoBtn . IsChecked = _settings . AutoRefresh ; // restores timer via OnAutoToggled
138142
139143 await CheckAsync ( ) ;
140144 }
@@ -187,15 +191,18 @@ private void ShowSettings(bool show)
187191
188192 private void ApplySettingsToUi ( )
189193 {
194+ _applying = true ;
190195 _closeTrayRadio . IsChecked = _settings . CloseToTray ;
191196 _closeQuitRadio . IsChecked = ! _settings . CloseToTray ;
192197 _topmostChk . IsChecked = _settings . Topmost ;
193198 _flagChk . IsChecked = _settings . ShowFlag ;
194199 _compactChk . IsChecked = _settings . Compact ;
200+ _applying = false ;
195201 }
196202
197203 private void OnSettingChanged ( object ? sender , RoutedEventArgs e )
198204 {
205+ if ( _applying ) return ;
199206 _settings . CloseToTray = _closeTrayRadio . IsChecked == true ;
200207 _settings . Topmost = _topmostChk . IsChecked == true ;
201208 _settings . ShowFlag = _flagChk . IsChecked == true ;
@@ -218,6 +225,7 @@ private void OnSettingChanged(object? sender, RoutedEventArgs e)
218225
219226 private void OnCompactCheckChanged ( object ? sender , RoutedEventArgs e )
220227 {
228+ if ( _applying ) return ;
221229 if ( _compactChk . IsChecked is { } want && want != _settings . Compact )
222230 SetCompact ( want ) ;
223231 }
@@ -384,7 +392,8 @@ private async void OnCopy(object? sender, RoutedEventArgs e)
384392
385393 private void OnAutoToggled ( object ? sender , RoutedEventArgs e )
386394 {
387- if ( sender is ToggleButton { IsChecked : true } )
395+ var on = _autoBtn . IsChecked == true ;
396+ if ( on )
388397 {
389398 _autoTimer = new DispatcherTimer { Interval = TimeSpan . FromSeconds ( 30 ) } ;
390399 _autoTimer . Tick += async ( _ , _ ) => await CheckAsync ( ) ;
@@ -395,6 +404,12 @@ private void OnAutoToggled(object? sender, RoutedEventArgs e)
395404 _autoTimer ? . Stop ( ) ;
396405 _autoTimer = null ;
397406 }
407+
408+ if ( ! _applying && _settings . AutoRefresh != on )
409+ {
410+ _settings . AutoRefresh = on ;
411+ Save ( ) ;
412+ }
398413 }
399414
400415 protected override void OnClosed ( EventArgs e )
0 commit comments