Phase 5: 系统托盘与开机自启
- 系统托盘: NotifyIcon 常驻, 程序化生成 32x32 图标, 左键切换显示/隐藏, 右键菜单(显示主界面/设置/彻底退出) - 窗口关闭拦截: OnClosing 取消关闭改为 Hide(), 退出菜单执行真实 Shutdown() - 开机自启: AutoStartHelper 写入/删除 HKCU\...\Run 注册表项, UI 开关按钮显示 ✔/⊗ 状态 - 静默启动: -autostart 参数下 mainWindow.Hide() 直接最小化到托盘 - 类型冲突解决: ImplicitUsings=disable + GlobalUsings.cs 统一全局 using, 消除 WPF/WinForms 共享类型冲突 - 测试: 75 tests total (含 AutoStartHelper 2 tests)
This commit is contained in:
@@ -63,6 +63,9 @@ public partial class MainViewModel : ObservableObject
|
||||
[ObservableProperty]
|
||||
private string _currentTheme = "Dark";
|
||||
|
||||
[ObservableProperty]
|
||||
private bool _isAutoStart;
|
||||
|
||||
// ───────────────────────────── 命令 ─────────────────────────────
|
||||
|
||||
[RelayCommand]
|
||||
@@ -78,6 +81,27 @@ public partial class MainViewModel : ObservableObject
|
||||
_logService.Info($"已切换到{(CurrentTheme == "Dark" ? "暗黑" : "明亮")}主题");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 切换开机自启动
|
||||
/// </summary>
|
||||
[RelayCommand]
|
||||
private void ToggleAutoStart()
|
||||
{
|
||||
IsAutoStart = !IsAutoStart;
|
||||
AutoStartHelper.SetAutoStart(IsAutoStart);
|
||||
_dataService.Config.AutoStart = IsAutoStart;
|
||||
_dataService.Save();
|
||||
_logService.Info(IsAutoStart ? "已启用开机自启动" : "已关闭开机自启动");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 供 MainWindow 外部调用,用于输出提示信息
|
||||
/// </summary>
|
||||
public void LogServiceMessage(string message)
|
||||
{
|
||||
_logService.Info(message);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 打开添加工具弹窗
|
||||
/// </summary>
|
||||
@@ -225,6 +249,7 @@ public partial class MainViewModel : ObservableObject
|
||||
|
||||
SelectedCategory = AllCategory;
|
||||
CurrentTheme = _dataService.Config.Theme;
|
||||
IsAutoStart = _dataService.Config.AutoStart;
|
||||
ThemeHelper.ApplyTheme(CurrentTheme);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user