From da3a4b6ae3da1be4f6249a00069f57af145a4326 Mon Sep 17 00:00:00 2001 From: uye <99072975+ABA2396@users.noreply.github.com> Date: Sat, 27 Jun 2026 17:37:28 +0800 Subject: [PATCH 1/2] =?UTF-8?q?fix:=20=E7=A7=BB=E9=99=A4=E9=87=8D=E5=A4=8D?= =?UTF-8?q?=E7=9A=84=E6=B3=A8=E5=86=8C=E8=A1=A8=E8=87=AA=E5=90=AF=E9=80=BB?= =?UTF-8?q?=E8=BE=91=EF=BC=8C=E7=BB=9F=E4=B8=80=E7=94=B1=20AutoStartManage?= =?UTF-8?q?r=20=E7=AE=A1=E7=90=86=E5=BC=80=E6=9C=BA=E5=90=AF=E5=8A=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/App.xaml.cs | 20 -------------------- src/ControlPanelWindow.xaml.cs | 21 +++++++++------------ 2 files changed, 9 insertions(+), 32 deletions(-) diff --git a/src/App.xaml.cs b/src/App.xaml.cs index ec6c813..1a76ba7 100644 --- a/src/App.xaml.cs +++ b/src/App.xaml.cs @@ -282,25 +282,5 @@ private void ExitApplication() System.Windows.Application.Current.Shutdown(); } - public static void SetAutoStart(bool enable) - { - try - { - string path = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Run"; - using RegistryKey key = Registry.CurrentUser.OpenSubKey(path, true)!; - string exePath = System.Environment.ProcessPath ?? System.Diagnostics.Process.GetCurrentProcess().MainModule!.FileName; - - if (enable) - key.SetValue("BASpark", $"\"{exePath}\" --autostart"); - else - key.DeleteValue("BASpark", false); - - ConfigManager.Save("AutoStart", enable); - } - catch (Exception ex) - { - System.Windows.MessageBox.Show("自启设置失败: " + ex.Message); - } - } } } diff --git a/src/ControlPanelWindow.xaml.cs b/src/ControlPanelWindow.xaml.cs index dbbaafc..6541225 100644 --- a/src/ControlPanelWindow.xaml.cs +++ b/src/ControlPanelWindow.xaml.cs @@ -1474,7 +1474,6 @@ private void SaveSettings_Click(object sender, RoutedEventArgs e) IsEnabled = item.IsEnabled })); - App.SetAutoStart(ConfigManager.AutoStart); ApplyAutoStartSettings(); App.Overlay?.UpdateColor(ConfigManager.ParticleColor); @@ -1596,19 +1595,17 @@ private void ApplyAutoStartSettings() try { - using (RegistryKey? key = Registry.CurrentUser.CreateSubKey(regKeyPath, true)) + using RegistryKey? key = Registry.CurrentUser.CreateSubKey(regKeyPath, true); + if (plan.RegistryRunEnabled) { - if (plan.RegistryRunEnabled) - { - key?.SetValue(AutoStartManager.RunValueName, AutoStartManager.BuildRunCommand(exePath)); - } - else - { - key?.DeleteValue(AutoStartManager.RunValueName, false); - } - - ManageTaskScheduler(AutoStartManager.TaskName, exePath, plan.ScheduledTaskEnabled); + key?.SetValue(AutoStartManager.RunValueName, AutoStartManager.BuildRunCommand(exePath)); } + else + { + key?.DeleteValue(AutoStartManager.RunValueName, false); + } + + ManageTaskScheduler(AutoStartManager.TaskName, exePath, plan.ScheduledTaskEnabled); } catch (Exception ex) { From d515eef726069e3314df7ed2fffae74edef00a27 Mon Sep 17 00:00:00 2001 From: uye <99072975+ABA2396@users.noreply.github.com> Date: Sat, 27 Jun 2026 18:00:45 +0800 Subject: [PATCH 2/2] =?UTF-8?q?chore:=20=E6=89=93=E5=BC=80=E5=BC=80?= =?UTF-8?q?=E6=9C=BA=E8=87=AA=E5=90=AF=E6=B3=A8=E5=86=8C=E8=A1=A8=E5=A4=B1?= =?UTF-8?q?=E8=B4=A5=E6=97=B6=E8=AE=B0=E5=BD=95=E9=94=99=E8=AF=AF=E5=B9=B6?= =?UTF-8?q?=E5=BF=AB=E9=80=9F=E5=A4=B1=E8=B4=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/ControlPanelWindow.xaml.cs | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/src/ControlPanelWindow.xaml.cs b/src/ControlPanelWindow.xaml.cs index 6541225..ddeb52e 100644 --- a/src/ControlPanelWindow.xaml.cs +++ b/src/ControlPanelWindow.xaml.cs @@ -1595,21 +1595,29 @@ private void ApplyAutoStartSettings() try { - using RegistryKey? key = Registry.CurrentUser.CreateSubKey(regKeyPath, true); - if (plan.RegistryRunEnabled) + // 注册表 Run 条目(普通自启)与计划任务(管理员自启)是两条独立路径, + // 注册表打开失败不应阻止计划任务的创建/清理 + using (RegistryKey? key = Registry.CurrentUser.CreateSubKey(regKeyPath, true)) { - key?.SetValue(AutoStartManager.RunValueName, AutoStartManager.BuildRunCommand(exePath)); - } - else - { - key?.DeleteValue(AutoStartManager.RunValueName, false); + if (key == null) + { + AppLogger.Warn($"Failed to open registry key for auto-start: {regKeyPath}"); + } + else if (plan.RegistryRunEnabled) + { + key.SetValue(AutoStartManager.RunValueName, AutoStartManager.BuildRunCommand(exePath)); + } + else + { + key.DeleteValue(AutoStartManager.RunValueName, false); + } } ManageTaskScheduler(AutoStartManager.TaskName, exePath, plan.ScheduledTaskEnabled); } catch (Exception ex) { - Debug.WriteLine("应用高权限自启失败: " + ex.Message); + AppLogger.Warn($"Failed to apply auto-start settings: {ex.Message}"); } }