Skip to content

Commit 1b0c114

Browse files
committed
Fix possible window show issue during startup
1 parent 3eb9493 commit 1b0c114

File tree

3 files changed

+42
-35
lines changed

3 files changed

+42
-35
lines changed

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 & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -16,29 +16,37 @@ public class AutoStartup
1616
private const string LogonTaskName = $"{Constant.FlowLauncher} Startup";
1717
private const string LogonTaskDesc = $"{Constant.FlowLauncher} Auto Startup";
1818

19-
public static bool IsEnabled
19+
public static void CheckIsEnabled(bool useLogonTaskForStartup)
2020
{
21-
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)
2226
{
23-
// Check if logon task is enabled
24-
if (CheckLogonTask())
27+
// Enable logon task
28+
if (!logonTaskEnabled)
2529
{
26-
return true;
30+
Enable(true);
2731
}
28-
29-
// Check if registry is enabled
30-
try
32+
// Disable registry
33+
if (registryEnabled)
3134
{
32-
using var key = Registry.CurrentUser.OpenSubKey(StartupPath, true);
33-
var path = key?.GetValue(Constant.FlowLauncher) as string;
34-
return path == Constant.ExecutablePath;
35+
Disable(false);
3536
}
36-
catch (Exception e)
37+
}
38+
else
39+
{
40+
// Enable registry
41+
if (!registryEnabled)
3742
{
38-
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);
3949
}
40-
41-
return false;
4250
}
4351
}
4452

@@ -69,20 +77,26 @@ private static bool CheckLogonTask()
6977
return false;
7078
}
7179

72-
public static void DisableViaLogonTaskAndRegistry()
80+
private static bool CheckRegistry()
7381
{
74-
Disable(true);
75-
Disable(false);
76-
}
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+
}
7792

78-
public static void EnableViaLogonTask()
79-
{
80-
Enable(true);
93+
return false;
8194
}
8295

83-
public static void EnableViaRegistry()
96+
public static void DisableViaLogonTaskAndRegistry()
8497
{
85-
Enable(false);
98+
Disable(true);
99+
Disable(false);
86100
}
87101

88102
public static void ChangeToViaLogonTask()

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)