diff --git a/App.xaml.cs b/App.xaml.cs index f05e20f..4907409 100644 --- a/App.xaml.cs +++ b/App.xaml.cs @@ -79,10 +79,16 @@ public partial class App : Application _apiService, _appCache); + // 开机启动:config 是 source of truth,启动时双向同步 Run 项 + // (如果用户在 UI 里禁用过,启动时也会确保从 Run 项里删掉) if (config.Startup.Enabled) { Utils.StartupManager.EnableCurrentUserStartup(_logger); } + else + { + Utils.StartupManager.DisableCurrentUserStartup(_logger); + } // 后台异步拉一次应用列表,不阻塞启动 _ = _appCache.RefreshAsync(); diff --git a/MainWindow.xaml b/MainWindow.xaml index 04e779a..381f478 100644 --- a/MainWindow.xaml +++ b/MainWindow.xaml @@ -111,6 +111,7 @@ + @@ -126,6 +127,16 @@ Background="{DynamicResource CardBackground}" Foreground="{DynamicResource PrimaryText}" BorderBrush="{DynamicResource BorderColor}" /> + + + diff --git a/MainWindow.xaml.cs b/MainWindow.xaml.cs index 6eb9ee1..fc62f27 100644 --- a/MainWindow.xaml.cs +++ b/MainWindow.xaml.cs @@ -63,6 +63,7 @@ public partial class MainWindow : Window UrlTextBox.Text = config.Gotify.Url; TokenBox.Password = config.Gotify.ClientToken; + StartupCheckBox.IsChecked = config.Startup.Enabled; UpdateAppCount(); SetStatus("等待连接", StatusKind.Pending); UpdateHistoryCount(); @@ -377,6 +378,35 @@ public partial class MainWindow : Window ThemeToggleButton.Content = ThemeService.Current == ThemeService.Dark ? "☾ 深色" : "☼ 浅色"; } + private async void StartupCheckBox_Click(object sender, RoutedEventArgs e) + { + if (_config is null || _configService is null) return; + + var enabled = StartupCheckBox.IsChecked == true; + _config.Startup.Enabled = enabled; + + try + { + if (enabled) + { + Utils.StartupManager.EnableCurrentUserStartup(_logger!); + SetStatus("已开启开机启动", StatusKind.Connected); + } + else + { + Utils.StartupManager.DisableCurrentUserStartup(_logger!); + SetStatus("已关闭开机启动", StatusKind.Connected); + } + await _configService.SaveAsync(_config); + _logger?.Info($"Startup toggled. enabled={enabled}"); + } + catch (Exception ex) + { + _logger?.Error("Toggle startup failed.", ex); + SetStatus($"切换开机启动失败:{ex.Message}", StatusKind.Error); + } + } + private async void SaveButton_Click(object sender, RoutedEventArgs e) { if (_config is null || _configService is null) return;