feat: 设置区加开机自启动 CheckBox(默认勾选)

StartupManager 早就实现了,但之前:
1. 没 UI 入口 —— 用户得去注册表手动改
2. App.OnStartup 里只 EnableCurrentUserStartup,不 Disable —— 用户禁用了下次启动会被强制写回,改不掉

现在:

MainWindow.xaml 设置区(URL/Token 下方)加 CheckBox,跨两列:
- 标签:"开机自动启动(写入 HKCU\Software\Microsoft\Windows\CurrentVersion\Run,只对当前用户生效)"
- Tooltip 说明
- 初始状态从 config.Startup.Enabled 读

MainWindow.xaml.cs StartupCheckBox_Click:
- 勾选变化 → 改 _config.Startup.Enabled → 调 EnableCurrentUserStartup 或 DisableCurrentUserStartup → 异步 SaveAsync
- 状态条反馈 "已开启/关闭开机启动"
- 异常时状态条变 ErrorDot 红色

App.xaml.cs OnStartup 双向同步:
- config.Startup.Enabled=true → Enable
- config.Startup.Enabled=false → Disable
(之前是单向只 Enable,导致用户在 UI 禁用了重启又被写回)

config 是 source of truth,UI 改了立刻落盘 + 同步注册表,下次启动再 sync 一次保证一致。
This commit is contained in:
2026-09-07 00:50:44 +08:00
parent 17480f683e
commit bd1c68d8e4
3 changed files with 47 additions and 0 deletions
+11
View File
@@ -111,6 +111,7 @@
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<TextBlock Grid.Row="0" Grid.Column="0" Text="Gotify URL" FontSize="11"
Foreground="{DynamicResource SecondaryText}" />
@@ -126,6 +127,16 @@
Background="{DynamicResource CardBackground}"
Foreground="{DynamicResource PrimaryText}"
BorderBrush="{DynamicResource BorderColor}" />
<!-- 开机自启动(跨两列) -->
<CheckBox Grid.Row="2" Grid.Column="0" Grid.ColumnSpan="2"
x:Name="StartupCheckBox"
Content="开机自动启动(写入 HKCU\Software\Microsoft\Windows\CurrentVersion\Run,只对当前用户生效)"
Margin="0,12,0,0"
VerticalContentAlignment="Center"
Click="StartupCheckBox_Click"
Foreground="{DynamicResource PrimaryText}"
ToolTip="勾选后登录 Windows 时自动启动本程序到托盘;取消勾选会从 Run 项里删除" />
</Grid>
</Border>