A:增加“开机自启动”

This commit is contained in:
jimmy committed 2025-08-13 23:42:23 +08:00
1 parent 6b3d369b89
commit 04cc443464
2 files changed
+27

No files matched your search

@@ -331,6 +331,10 @@
Margin="0,8,0,0" Margin="0,8,0,0"
Checked="ShowDetailedInfoCheckBox_Changed" Checked="ShowDetailedInfoCheckBox_Changed"
Unchecked="ShowDetailedInfoCheckBox_Changed" FontSize="13" /> Unchecked="ShowDetailedInfoCheckBox_Changed" FontSize="13" />
<CheckBox x:Name="AutoStartCheckBox" Content="开机自启动" IsChecked="False"
Margin="0,8,0,0"
Checked="AutoStartCheckBox_Changed"
Unchecked="AutoStartCheckBox_Changed" FontSize="13" />
<Button Content="重置窗口位置" Click="ResetWindowPosition_Click" Margin="0,16,0,0" <Button Content="重置窗口位置" Click="ResetWindowPosition_Click" Margin="0,16,0,0"
Style="{StaticResource SecondaryButtonStyle}" HorizontalAlignment="Left" /> Style="{StaticResource SecondaryButtonStyle}" HorizontalAlignment="Left" />
@@ -8,6 +8,7 @@ using Common.Logger;
using Data.Models; using Data.Models;
using Data; using Data;
using System.Linq; using System.Linq;
using Shell.Utils;
namespace Shell.Views; namespace Shell.Views;
@@ -155,6 +156,15 @@ public partial class SettingsWindow : Window
ClickThroughCheckBox.IsChecked = _settings.IsClickThrough; ClickThroughCheckBox.IsChecked = _settings.IsClickThrough;
SnapToScreenCheckBox.IsChecked = _settings.SnapToScreen; SnapToScreenCheckBox.IsChecked = _settings.SnapToScreen;
ShowDetailedInfoCheckBox.IsChecked = _settings.ShowDetailedInfo; ShowDetailedInfoCheckBox.IsChecked = _settings.ShowDetailedInfo;
// 检查实际的Windows启动状态并同步到UI和设置
var actualStartupState = WindowsStartupHelper.IsStartupEnabled();
if (actualStartupState != _settings.AutoStart)
{
Log.Info($"Windows启动状态({actualStartupState})与数据库设置({_settings.AutoStart})不一致,以Windows实际状态为准");
_settings.AutoStart = actualStartupState;
}
AutoStartCheckBox.IsChecked = _settings.AutoStart;
UpdateColorButtons(); UpdateColorButtons();
} }
@@ -342,6 +352,11 @@ public partial class SettingsWindow : Window
// 详细信息设置变化,不需要预览更新 // 详细信息设置变化,不需要预览更新
} }
private void AutoStartCheckBox_Changed(object sender, RoutedEventArgs e)
{
// 开机自启动设置变化,不需要预览更新
}
private void UpdatePreview() private void UpdatePreview()
{ {
if (PreviewBorder == null || PreviewPanel == null) return; if (PreviewBorder == null || PreviewPanel == null) return;
@@ -468,6 +483,14 @@ public partial class SettingsWindow : Window
_settings.IsClickThrough = ClickThroughCheckBox.IsChecked == true; _settings.IsClickThrough = ClickThroughCheckBox.IsChecked == true;
_settings.SnapToScreen = SnapToScreenCheckBox.IsChecked == true; _settings.SnapToScreen = SnapToScreenCheckBox.IsChecked == true;
_settings.ShowDetailedInfo = ShowDetailedInfoCheckBox.IsChecked == true; _settings.ShowDetailedInfo = ShowDetailedInfoCheckBox.IsChecked == true;
// 应用开机自启动设置
_settings.AutoStart = AutoStartCheckBox.IsChecked == true;
var startupResult = WindowsStartupHelper.SetStartup(_settings.AutoStart);
if (!startupResult)
{
Log.Warning("设置开机自启动失败,但设置已保存到数据库");
}
// 设置更新时间 // 设置更新时间
_settings.UpdateTime = DateTimeOffset.Now.ToUnixTimeSeconds(); _settings.UpdateTime = DateTimeOffset.Now.ToUnixTimeSeconds();