Merge pull request #3472 from Flow-Launcher/startup_window_popup

Fix Possible Window Popup During Startup & Fix Store Plugin List Refresh Issue
This commit is contained in:
DB P 2025-04-18 16:14:52 +09:00 committed by GitHub
commit d30fdbb527
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 55 additions and 46 deletions

View file

@ -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<IPublicAPI>();
private static readonly string ClassName = nameof(CommunityPluginSource);
private string latestEtag = "";
private List<UserPlugin> plugins = new();
@ -70,7 +70,7 @@ namespace Flow.Launcher.Core.ExternalPlugins
else
{
API.LogWarn(ClassName, $"Failed to load resource {ManifestFileUrl} with response {response.StatusCode}");
return plugins;
return null;
}
}
catch (Exception e)
@ -83,7 +83,7 @@ namespace Flow.Launcher.Core.ExternalPlugins
{
API.LogException(ClassName, "Error Occurred", e);
}
return plugins;
return null;
}
}
}

View file

@ -40,10 +40,14 @@ namespace Flow.Launcher.Core.ExternalPlugins
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);
}

View file

@ -202,18 +202,11 @@ namespace Flow.Launcher
{
// 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)
{

View file

@ -3,7 +3,6 @@ using System.IO;
using System.Linq;
using System.Security.Principal;
using Flow.Launcher.Infrastructure;
using Flow.Launcher.Infrastructure.Logger;
using Microsoft.Win32;
using Microsoft.Win32.TaskScheduler;
@ -17,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;
}
}
@ -70,22 +77,28 @@ public class AutoStartup
return false;
}
private static bool CheckRegistry()
{
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}");
}
return false;
}
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);

View file

@ -5,7 +5,6 @@ using NHotkey;
using NHotkey.Wpf;
using Flow.Launcher.ViewModel;
using ChefKeys;
using Flow.Launcher.Infrastructure.Logger;
using CommunityToolkit.Mvvm.DependencyInjection;
namespace Flow.Launcher.Helper;

View file

@ -48,11 +48,11 @@ public partial class SettingsPaneGeneralViewModel : BaseModel
{
if (UseLogonTaskForStartup)
{
AutoStartup.EnableViaLogonTask();
AutoStartup.ChangeToViaLogonTask();
}
else
{
AutoStartup.EnableViaRegistry();
AutoStartup.ChangeToViaRegistry();
}
}
else