From 96305166e834864f7884e897c38c5fc1bec4e87f Mon Sep 17 00:00:00 2001 From: Jack251970 <1160210343@qq.com> Date: Mon, 24 Feb 2025 19:55:48 +0800 Subject: [PATCH] Improve function names for code quality --- Flow.Launcher/App.xaml.cs | 9 +++++- Flow.Launcher/Helper/AutoStartup.cs | 32 +++++++++++++++++-- .../SettingsPaneGeneralViewModel.cs | 25 ++++++++++----- 3 files changed, 55 insertions(+), 11 deletions(-) diff --git a/Flow.Launcher/App.xaml.cs b/Flow.Launcher/App.xaml.cs index 38f846d92..f74e9a388 100644 --- a/Flow.Launcher/App.xaml.cs +++ b/Flow.Launcher/App.xaml.cs @@ -119,7 +119,14 @@ namespace Flow.Launcher { try { - Helper.AutoStartup.Enable(_settings.UseLogonTaskForStartup); + if (_settings.UseLogonTaskForStartup) + { + Helper.AutoStartup.EnableViaLogonTask(); + } + else + { + Helper.AutoStartup.EnableViaRegistry(); + } } catch (Exception e) { diff --git a/Flow.Launcher/Helper/AutoStartup.cs b/Flow.Launcher/Helper/AutoStartup.cs index 79466f1fb..936951ee9 100644 --- a/Flow.Launcher/Helper/AutoStartup.cs +++ b/Flow.Launcher/Helper/AutoStartup.cs @@ -68,7 +68,35 @@ public class AutoStartup return false; } - public static void Disable(bool logonTask) + public static void DisableViaLogonTaskAndRegistry() + { + Disable(true); + Disable(false); + } + + public static void EnableViaLogonTask() + { + Enable(true); + } + + public static void EnableViaRegistry() + { + Enable(false); + } + + public static void ChangeToViaLogonTask() + { + Disable(false); + Enable(true); + } + + public static void ChangeToViaRegistry() + { + Disable(true); + Enable(false); + } + + private static void Disable(bool logonTask) { try { @@ -89,7 +117,7 @@ public class AutoStartup } } - internal static void Enable(bool logonTask) + private static void Enable(bool logonTask) { try { diff --git a/Flow.Launcher/SettingPages/ViewModels/SettingsPaneGeneralViewModel.cs b/Flow.Launcher/SettingPages/ViewModels/SettingsPaneGeneralViewModel.cs index 0aca761a0..ab38cd514 100644 --- a/Flow.Launcher/SettingPages/ViewModels/SettingsPaneGeneralViewModel.cs +++ b/Flow.Launcher/SettingPages/ViewModels/SettingsPaneGeneralViewModel.cs @@ -43,14 +43,18 @@ public partial class SettingsPaneGeneralViewModel : BaseModel { if (value) { - // Enable either registry or task scheduler - AutoStartup.Enable(UseLogonTaskForStartup); + if (UseLogonTaskForStartup) + { + AutoStartup.EnableViaLogonTask(); + } + else + { + AutoStartup.EnableViaRegistry(); + } } else { - // Disable both registry and task scheduler - AutoStartup.Disable(true); - AutoStartup.Disable(false); + AutoStartup.DisableViaLogonTaskAndRegistry(); } } catch (Exception e) @@ -72,9 +76,14 @@ public partial class SettingsPaneGeneralViewModel : BaseModel { try { - // Disable and enable to update the startup method - AutoStartup.Disable(!UseLogonTaskForStartup); - AutoStartup.Enable(UseLogonTaskForStartup); + if (UseLogonTaskForStartup) + { + AutoStartup.ChangeToViaLogonTask(); + } + else + { + AutoStartup.ChangeToViaRegistry(); + } } catch (Exception e) {