diff --git a/Ink Canvas/Windows/SettingsViews2/Pages/NewSettingStartup.xaml b/Ink Canvas/Windows/SettingsViews2/Pages/NewSettingStartup.xaml index 8c34eec5..62805dec 100644 --- a/Ink Canvas/Windows/SettingsViews2/Pages/NewSettingStartup.xaml +++ b/Ink Canvas/Windows/SettingsViews2/Pages/NewSettingStartup.xaml @@ -4,14 +4,42 @@ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:local="clr-namespace:Ink_Canvas.Windows.SettingsViews2.Pages" + xmlns:ui="http://schemas.inkore.net/lib/ui/wpf/modern" + xmlns:ikw="http://schemas.inkore.net/lib/ui/wpf" + xmlns:i18n="clr-namespace:Ink_Canvas.MarkupExtensions" + xmlns:sys="clr-namespace:System;assembly=mscorlib" mc:Ignorable="d" d:DesignHeight="450" d:DesignWidth="800" Title="启动"> - - - - - - + + + + + 4 + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Ink Canvas/Windows/SettingsViews2/Pages/NewSettingStartup.xaml.cs b/Ink Canvas/Windows/SettingsViews2/Pages/NewSettingStartup.xaml.cs index cf0bc76b..8c553661 100644 --- a/Ink Canvas/Windows/SettingsViews2/Pages/NewSettingStartup.xaml.cs +++ b/Ink Canvas/Windows/SettingsViews2/Pages/NewSettingStartup.xaml.cs @@ -23,6 +23,73 @@ namespace Ink_Canvas.Windows.SettingsViews2.Pages public NewSettingStartup() { InitializeComponent(); + // 初始化开关状态 + InitializeSwitchState(); + } + + /// + /// 初始化开关状态 + /// + private void InitializeSwitchState() + { + try + { + // 通过检查启动文件夹中是否存在快捷方式来判断开机自启动状态 + if (System.IO.File.Exists(System.Environment.GetFolderPath(System.Environment.SpecialFolder.Startup) + "\\Ink Canvas Annotation.lnk")) + { + ToggleSwitchRunAtStartup.IsOn = true; + } + else + { + ToggleSwitchRunAtStartup.IsOn = false; + } + + // 同步主窗口的开关状态 + var mainWindow = Application.Current.MainWindow as MainWindow; + if (mainWindow != null && mainWindow.ToggleSwitchRunAtStartup != null) + { + mainWindow.ToggleSwitchRunAtStartup.IsOn = ToggleSwitchRunAtStartup.IsOn; + } + } + catch (Exception) + { + // 如果发生异常,默认设置为关闭 + ToggleSwitchRunAtStartup.IsOn = false; + } + } + + /// + /// 处理开机自启动开关状态更改事件 + /// + /// 事件发送者 + /// 路由事件参数 + private void ToggleSwitchRunAtStartup_Toggled(object sender, RoutedEventArgs e) + { + try + { + // 直接实现开机自启动逻辑 + if (ToggleSwitchRunAtStartup.IsOn) + { + MainWindow.StartAutomaticallyDel("InkCanvas"); + MainWindow.StartAutomaticallyCreate("Ink Canvas Annotation"); + } + else + { + MainWindow.StartAutomaticallyDel("InkCanvas"); + MainWindow.StartAutomaticallyDel("Ink Canvas Annotation"); + } + + // 同步到主窗口的设置 + var mainWindow = Application.Current.MainWindow as MainWindow; + if (mainWindow != null && mainWindow.ToggleSwitchRunAtStartup != null) + { + mainWindow.ToggleSwitchRunAtStartup.IsOn = ToggleSwitchRunAtStartup.IsOn; + } + } + catch (Exception) + { + // 忽略异常 + } } } } \ No newline at end of file