@@ -16,29 +16,37 @@ public class AutoStartup
16
16
private const string LogonTaskName = $ "{ Constant . FlowLauncher } Startup";
17
17
private const string LogonTaskDesc = $ "{ Constant . FlowLauncher } Auto Startup";
18
18
19
- public static bool IsEnabled
19
+ public static void CheckIsEnabled ( bool useLogonTaskForStartup )
20
20
{
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 )
22
26
{
23
- // Check if logon task is enabled
24
- if ( CheckLogonTask ( ) )
27
+ // Enable logon task
28
+ if ( ! logonTaskEnabled )
25
29
{
26
- return true ;
30
+ Enable ( true ) ;
27
31
}
28
-
29
- // Check if registry is enabled
30
- try
32
+ // Disable registry
33
+ if ( registryEnabled )
31
34
{
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 ) ;
35
36
}
36
- catch ( Exception e )
37
+ }
38
+ else
39
+ {
40
+ // Enable registry
41
+ if ( ! registryEnabled )
37
42
{
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 ) ;
39
49
}
40
-
41
- return false ;
42
50
}
43
51
}
44
52
@@ -69,20 +77,26 @@ private static bool CheckLogonTask()
69
77
return false ;
70
78
}
71
79
72
- public static void DisableViaLogonTaskAndRegistry ( )
80
+ private static bool CheckRegistry ( )
73
81
{
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
+ }
77
92
78
- public static void EnableViaLogonTask ( )
79
- {
80
- Enable ( true ) ;
93
+ return false ;
81
94
}
82
95
83
- public static void EnableViaRegistry ( )
96
+ public static void DisableViaLogonTaskAndRegistry ( )
84
97
{
85
- Enable ( false ) ;
98
+ Disable ( true ) ;
99
+ Disable ( false ) ;
86
100
}
87
101
88
102
public static void ChangeToViaLogonTask ( )
0 commit comments