Fix possible window show issue during startup

This commit is contained in:
Jack251970 2025-04-17 23:14:41 +08:00
parent 3eb9493bdd
commit 1b0c114255
3 changed files with 43 additions and 36 deletions

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

@ -16,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;
}
}
@ -69,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

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