Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Flow.Launcher.Core/ExternalPlugins/CommunityPluginSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -70,7 +70,7 @@ public async Task<List<UserPlugin>> FetchAsync(CancellationToken token)
else
{
API.LogWarn(ClassName, $"Failed to load resource {ManifestFileUrl} with response {response.StatusCode}");
return plugins;
return null;
}
}
catch (Exception e)
Expand All @@ -83,7 +83,7 @@ public async Task<List<UserPlugin>> FetchAsync(CancellationToken token)
{
API.LogException(ClassName, "Error Occurred", e);
}
return plugins;
return null;
}
}
}
Expand Down
12 changes: 8 additions & 4 deletions Flow.Launcher.Core/ExternalPlugins/CommunityPluginStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,14 @@ public async Task<List<UserPlugin>> 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);
}
Expand Down
11 changes: 2 additions & 9 deletions Flow.Launcher/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
63 changes: 38 additions & 25 deletions Flow.Launcher/Helper/AutoStartup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
}
}

Expand Down Expand Up @@ -70,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()
Expand Down
1 change: 0 additions & 1 deletion Flow.Launcher/Helper/HotKeyMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ public bool StartFlowLauncherOnSystemStartup
{
if (UseLogonTaskForStartup)
{
AutoStartup.EnableViaLogonTask();
AutoStartup.ChangeToViaLogonTask();
}
else
{
AutoStartup.EnableViaRegistry();
AutoStartup.ChangeToViaRegistry();
}
}
else
Expand Down
Loading