Skip to content

Commit dfe7c8b

Browse files
committed
Persist auto-refresh, fix settings clobber on init, verify cross-platform save
1 parent 259f201 commit dfe7c8b

4 files changed

Lines changed: 20 additions & 4 deletions

File tree

MainWindow.axaml.cs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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)

README.en.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ Pushing a `v*` tag builds single-file binaries for
4545
`win-x64`, `linux-x64`, `osx-x64`, `osx-arm64` via GitHub Actions and attaches them to the release.
4646

4747
```bash
48-
git tag v0.1.1 && git push origin v0.1.1
48+
git tag v0.1.2 && git push origin v0.1.2
4949
```
5050

5151
## License

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ dotnet publish -c Release -r win-x64 --self-contained \
4545
`win-x64`, `linux-x64`, `osx-x64`, `osx-arm64` и прикладывает их к релизу.
4646

4747
```bash
48-
git tag v0.1.1 && git push origin v0.1.1
48+
git tag v0.1.2 && git push origin v0.1.2
4949
```
5050

5151
## Лицензия

Services/Settings.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ public sealed class Settings
1111
public bool Compact { get; set; }
1212
public bool Topmost { get; set; }
1313
public bool ShowFlag { get; set; } = true;
14+
public bool AutoRefresh { get; set; }
1415
public int? X { get; set; }
1516
public int? Y { get; set; }
1617

0 commit comments

Comments
 (0)