From 3eb9493bdd23c6a3bf686d097c19a8ff481e93ab Mon Sep 17 00:00:00 2001 From: Jack251970 <1160210343@qq.com> Date: Thu, 17 Apr 2025 23:01:45 +0800 Subject: [PATCH 1/3] Remove unused usings --- Flow.Launcher/Helper/AutoStartup.cs | 1 - Flow.Launcher/Helper/HotKeyMapper.cs | 1 - 2 files changed, 2 deletions(-) diff --git a/Flow.Launcher/Helper/AutoStartup.cs b/Flow.Launcher/Helper/AutoStartup.cs index 568ea794446..81568875e85 100644 --- a/Flow.Launcher/Helper/AutoStartup.cs +++ b/Flow.Launcher/Helper/AutoStartup.cs @@ -3,7 +3,6 @@ using System.Linq; using System.Security.Principal; using Flow.Launcher.Infrastructure; -using Flow.Launcher.Infrastructure.Logger; using Microsoft.Win32; using Microsoft.Win32.TaskScheduler; diff --git a/Flow.Launcher/Helper/HotKeyMapper.cs b/Flow.Launcher/Helper/HotKeyMapper.cs index 1e83415cc46..e5fabb3a89f 100644 --- a/Flow.Launcher/Helper/HotKeyMapper.cs +++ b/Flow.Launcher/Helper/HotKeyMapper.cs @@ -5,7 +5,6 @@ using NHotkey.Wpf; using Flow.Launcher.ViewModel; using ChefKeys; -using Flow.Launcher.Infrastructure.Logger; using CommunityToolkit.Mvvm.DependencyInjection; namespace Flow.Launcher.Helper; From 1b0c11425504bc024919af2f9b9132e8076c4e10 Mon Sep 17 00:00:00 2001 From: Jack251970 <1160210343@qq.com> Date: Thu, 17 Apr 2025 23:14:41 +0800 Subject: [PATCH 2/3] Fix possible window show issue during startup --- Flow.Launcher/App.xaml.cs | 11 +--- Flow.Launcher/Helper/AutoStartup.cs | 62 ++++++++++++------- .../SettingsPaneGeneralViewModel.cs | 4 +- 3 files changed, 42 insertions(+), 35 deletions(-) diff --git a/Flow.Launcher/App.xaml.cs b/Flow.Launcher/App.xaml.cs index 87677f58a67..87698a54571 100644 --- a/Flow.Launcher/App.xaml.cs +++ b/Flow.Launcher/App.xaml.cs @@ -202,18 +202,11 @@ private void AutoStartup() { // we try to enable auto-startup on first launch, or reenable if it was removed // but the user still has the setting set - if (_settings.StartFlowLauncherOnSystemStartup && !Helper.AutoStartup.IsEnabled) + if (_settings.StartFlowLauncherOnSystemStartup) { try { - if (_settings.UseLogonTaskForStartup) - { - Helper.AutoStartup.EnableViaLogonTask(); - } - else - { - Helper.AutoStartup.EnableViaRegistry(); - } + Helper.AutoStartup.CheckIsEnabled(_settings.UseLogonTaskForStartup); } catch (Exception e) { diff --git a/Flow.Launcher/Helper/AutoStartup.cs b/Flow.Launcher/Helper/AutoStartup.cs index 81568875e85..b83bb594894 100644 --- a/Flow.Launcher/Helper/AutoStartup.cs +++ b/Flow.Launcher/Helper/AutoStartup.cs @@ -16,29 +16,37 @@ public class AutoStartup private const string LogonTaskName = $"{Constant.FlowLauncher} Startup"; private const string LogonTaskDesc = $"{Constant.FlowLauncher} Auto Startup"; - public static bool IsEnabled + public static void CheckIsEnabled(bool useLogonTaskForStartup) { - get + // We need to check both because if both of them are enabled, + // Hide Flow Launcher on startup will not work since the later one will trigger main window show event + var logonTaskEnabled = CheckLogonTask(); + var registryEnabled = CheckRegistry(); + if (useLogonTaskForStartup) { - // Check if logon task is enabled - if (CheckLogonTask()) + // Enable logon task + if (!logonTaskEnabled) { - return true; + Enable(true); } - - // Check if registry is enabled - try + // Disable registry + if (registryEnabled) { - using var key = Registry.CurrentUser.OpenSubKey(StartupPath, true); - var path = key?.GetValue(Constant.FlowLauncher) as string; - return path == Constant.ExecutablePath; + Disable(false); } - catch (Exception e) + } + else + { + // Enable registry + if (!registryEnabled) { - App.API.LogError(ClassName, $"Ignoring non-critical registry error (querying if enabled): {e}"); + Enable(false); + } + // Disable logon task + if (logonTaskEnabled) + { + Disable(true); } - - return false; } } @@ -69,20 +77,26 @@ private static bool CheckLogonTask() return false; } - public static void DisableViaLogonTaskAndRegistry() + private static bool CheckRegistry() { - Disable(true); - Disable(false); - } + try + { + using var key = Registry.CurrentUser.OpenSubKey(StartupPath, true); + var path = key?.GetValue(Constant.FlowLauncher) as string; + return path == Constant.ExecutablePath; + } + catch (Exception e) + { + App.API.LogError(ClassName, $"Ignoring non-critical registry error (querying if enabled): {e}"); + } - public static void EnableViaLogonTask() - { - Enable(true); + return false; } - public static void EnableViaRegistry() + public static void DisableViaLogonTaskAndRegistry() { - Enable(false); + Disable(true); + Disable(false); } public static void ChangeToViaLogonTask() diff --git a/Flow.Launcher/SettingPages/ViewModels/SettingsPaneGeneralViewModel.cs b/Flow.Launcher/SettingPages/ViewModels/SettingsPaneGeneralViewModel.cs index 021c9d7fe61..6b56caf5e74 100644 --- a/Flow.Launcher/SettingPages/ViewModels/SettingsPaneGeneralViewModel.cs +++ b/Flow.Launcher/SettingPages/ViewModels/SettingsPaneGeneralViewModel.cs @@ -48,11 +48,11 @@ public bool StartFlowLauncherOnSystemStartup { if (UseLogonTaskForStartup) { - AutoStartup.EnableViaLogonTask(); + AutoStartup.ChangeToViaLogonTask(); } else { - AutoStartup.EnableViaRegistry(); + AutoStartup.ChangeToViaRegistry(); } } else From dd61ab43cb5cc47d54edf21df77452d76b1ad1c3 Mon Sep 17 00:00:00 2001 From: Jack251970 <1160210343@qq.com> Date: Fri, 18 Apr 2025 07:17:33 +0800 Subject: [PATCH 3/3] Use null as flag to report community source error --- .../ExternalPlugins/CommunityPluginSource.cs | 8 ++++---- .../ExternalPlugins/CommunityPluginStore.cs | 12 ++++++++---- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/Flow.Launcher.Core/ExternalPlugins/CommunityPluginSource.cs b/Flow.Launcher.Core/ExternalPlugins/CommunityPluginSource.cs index ac27c523c7e..6f3b23e1120 100644 --- a/Flow.Launcher.Core/ExternalPlugins/CommunityPluginSource.cs +++ b/Flow.Launcher.Core/ExternalPlugins/CommunityPluginSource.cs @@ -16,12 +16,12 @@ namespace Flow.Launcher.Core.ExternalPlugins { public record CommunityPluginSource(string ManifestFileUrl) { + private static readonly string ClassName = nameof(CommunityPluginSource); + // We should not initialize API in static constructor because it will create another API instance private static IPublicAPI api = null; private static IPublicAPI API => api ??= Ioc.Default.GetRequiredService(); - private static readonly string ClassName = nameof(CommunityPluginSource); - private string latestEtag = ""; private List plugins = new(); @@ -70,7 +70,7 @@ public async Task> FetchAsync(CancellationToken token) else { API.LogWarn(ClassName, $"Failed to load resource {ManifestFileUrl} with response {response.StatusCode}"); - return plugins; + return null; } } catch (Exception e) @@ -83,7 +83,7 @@ public async Task> FetchAsync(CancellationToken token) { API.LogException(ClassName, "Error Occurred", e); } - return plugins; + return null; } } } diff --git a/Flow.Launcher.Core/ExternalPlugins/CommunityPluginStore.cs b/Flow.Launcher.Core/ExternalPlugins/CommunityPluginStore.cs index 1f23c2f6619..bdc1ad3dd8f 100644 --- a/Flow.Launcher.Core/ExternalPlugins/CommunityPluginStore.cs +++ b/Flow.Launcher.Core/ExternalPlugins/CommunityPluginStore.cs @@ -40,10 +40,14 @@ public async Task> FetchAsync(CancellationToken token, bool onl var completedTask = await Task.WhenAny(tasks); if (completedTask.IsCompletedSuccessfully) { - // one of the requests completed successfully; keep its results - // and cancel the remaining http requests. - pluginResults = await completedTask; - cts.Cancel(); + var result = await completedTask; + if (result != null) + { + // one of the requests completed successfully; keep its results + // and cancel the remaining http requests. + pluginResults = result; + cts.Cancel(); + } } tasks.Remove(completedTask); }