Skip to content

Commit d30fdbb

Browse files
authored
Merge pull request #3472 from Flow-Launcher/startup_window_popup
Fix Possible Window Popup During Startup & Fix Store Plugin List Refresh Issue
2 parents 0591970 + dd61ab4 commit d30fdbb

File tree

6 files changed

+54
-45
lines changed

6 files changed

+54
-45
lines changed

Flow.Launcher.Core/ExternalPlugins/CommunityPluginSource.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ namespace Flow.Launcher.Core.ExternalPlugins
1616
{
1717
public record CommunityPluginSource(string ManifestFileUrl)
1818
{
19+
private static readonly string ClassName = nameof(CommunityPluginSource);
20+
1921
// We should not initialize API in static constructor because it will create another API instance
2022
private static IPublicAPI api = null;
2123
private static IPublicAPI API => api ??= Ioc.Default.GetRequiredService<IPublicAPI>();
2224

23-
private static readonly string ClassName = nameof(CommunityPluginSource);
24-
2525
private string latestEtag = "";
2626

2727
private List<UserPlugin> plugins = new();
@@ -70,7 +70,7 @@ public async Task<List<UserPlugin>> FetchAsync(CancellationToken token)
7070
else
7171
{
7272
API.LogWarn(ClassName, $"Failed to load resource {ManifestFileUrl} with response {response.StatusCode}");
73-
return plugins;
73+
return null;
7474
}
7575
}
7676
catch (Exception e)
@@ -83,7 +83,7 @@ public async Task<List<UserPlugin>> FetchAsync(CancellationToken token)
8383
{
8484
API.LogException(ClassName, "Error Occurred", e);
8585
}
86-
return plugins;
86+
return null;
8787
}
8888
}
8989
}

Flow.Launcher.Core/ExternalPlugins/CommunityPluginStore.cs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,14 @@ public async Task<List<UserPlugin>> FetchAsync(CancellationToken token, bool onl
4040
var completedTask = await Task.WhenAny(tasks);
4141
if (completedTask.IsCompletedSuccessfully)
4242
{
43-
// one of the requests completed successfully; keep its results
44-
// and cancel the remaining http requests.
45-
pluginResults = await completedTask;
46-
cts.Cancel();
43+
var result = await completedTask;
44+
if (result != null)
45+
{
46+
// one of the requests completed successfully; keep its results
47+
// and cancel the remaining http requests.
48+
pluginResults = result;
49+
cts.Cancel();
50+
}
4751
}
4852
tasks.Remove(completedTask);
4953
}

Flow.Launcher/App.xaml.cs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -202,18 +202,11 @@ private void AutoStartup()
202202
{
203203
// we try to enable auto-startup on first launch, or reenable if it was removed
204204
// but the user still has the setting set
205-
if (_settings.StartFlowLauncherOnSystemStartup && !Helper.AutoStartup.IsEnabled)
205+
if (_settings.StartFlowLauncherOnSystemStartup)
206206
{
207207
try
208208
{
209-
if (_settings.UseLogonTaskForStartup)
210-
{
211-
Helper.AutoStartup.EnableViaLogonTask();
212-
}
213-
else
214-
{
215-
Helper.AutoStartup.EnableViaRegistry();
216-
}
209+
Helper.AutoStartup.CheckIsEnabled(_settings.UseLogonTaskForStartup);
217210
}
218211
catch (Exception e)
219212
{

Flow.Launcher/Helper/AutoStartup.cs

Lines changed: 38 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
using System.Linq;
44
using System.Security.Principal;
55
using Flow.Launcher.Infrastructure;
6-
using Flow.Launcher.Infrastructure.Logger;
76
using Microsoft.Win32;
87
using Microsoft.Win32.TaskScheduler;
98

@@ -17,29 +16,37 @@ public class AutoStartup
1716
private const string LogonTaskName = $"{Constant.FlowLauncher} Startup";
1817
private const string LogonTaskDesc = $"{Constant.FlowLauncher} Auto Startup";
1918

20-
public static bool IsEnabled
19+
public static void CheckIsEnabled(bool useLogonTaskForStartup)
2120
{
22-
get
21+
// We need to check both because if both of them are enabled,
22+
// Hide Flow Launcher on startup will not work since the later one will trigger main window show event
23+
var logonTaskEnabled = CheckLogonTask();
24+
var registryEnabled = CheckRegistry();
25+
if (useLogonTaskForStartup)
2326
{
24-
// Check if logon task is enabled
25-
if (CheckLogonTask())
27+
// Enable logon task
28+
if (!logonTaskEnabled)
2629
{
27-
return true;
30+
Enable(true);
2831
}
29-
30-
// Check if registry is enabled
31-
try
32+
// Disable registry
33+
if (registryEnabled)
3234
{
33-
using var key = Registry.CurrentUser.OpenSubKey(StartupPath, true);
34-
var path = key?.GetValue(Constant.FlowLauncher) as string;
35-
return path == Constant.ExecutablePath;
35+
Disable(false);
3636
}
37-
catch (Exception e)
37+
}
38+
else
39+
{
40+
// Enable registry
41+
if (!registryEnabled)
3842
{
39-
App.API.LogError(ClassName, $"Ignoring non-critical registry error (querying if enabled): {e}");
43+
Enable(false);
44+
}
45+
// Disable logon task
46+
if (logonTaskEnabled)
47+
{
48+
Disable(true);
4049
}
41-
42-
return false;
4350
}
4451
}
4552

@@ -70,20 +77,26 @@ private static bool CheckLogonTask()
7077
return false;
7178
}
7279

73-
public static void DisableViaLogonTaskAndRegistry()
80+
private static bool CheckRegistry()
7481
{
75-
Disable(true);
76-
Disable(false);
77-
}
82+
try
83+
{
84+
using var key = Registry.CurrentUser.OpenSubKey(StartupPath, true);
85+
var path = key?.GetValue(Constant.FlowLauncher) as string;
86+
return path == Constant.ExecutablePath;
87+
}
88+
catch (Exception e)
89+
{
90+
App.API.LogError(ClassName, $"Ignoring non-critical registry error (querying if enabled): {e}");
91+
}
7892

79-
public static void EnableViaLogonTask()
80-
{
81-
Enable(true);
93+
return false;
8294
}
8395

84-
public static void EnableViaRegistry()
96+
public static void DisableViaLogonTaskAndRegistry()
8597
{
86-
Enable(false);
98+
Disable(true);
99+
Disable(false);
87100
}
88101

89102
public static void ChangeToViaLogonTask()

Flow.Launcher/Helper/HotKeyMapper.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
using NHotkey.Wpf;
66
using Flow.Launcher.ViewModel;
77
using ChefKeys;
8-
using Flow.Launcher.Infrastructure.Logger;
98
using CommunityToolkit.Mvvm.DependencyInjection;
109

1110
namespace Flow.Launcher.Helper;

Flow.Launcher/SettingPages/ViewModels/SettingsPaneGeneralViewModel.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,11 @@ public bool StartFlowLauncherOnSystemStartup
4848
{
4949
if (UseLogonTaskForStartup)
5050
{
51-
AutoStartup.EnableViaLogonTask();
51+
AutoStartup.ChangeToViaLogonTask();
5252
}
5353
else
5454
{
55-
AutoStartup.EnableViaRegistry();
55+
AutoStartup.ChangeToViaRegistry();
5656
}
5757
}
5858
else

0 commit comments

Comments
 (0)