Skip to content

Commit 2d25fef

Browse files
committed
Initialize QuickSwitch earlier
1 parent d229bfe commit 2d25fef

File tree

2 files changed

+13
-14
lines changed

2 files changed

+13
-14
lines changed

Flow.Launcher.Infrastructure/QuickSwitch/QuickSwitch.cs

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,13 @@ public static class QuickSwitch
3333

3434
private static UnhookWinEventSafeHandle _hookWinEventSafeHandle = null;
3535

36+
private static bool _isInitialized = false;
37+
3638
public static bool Initialize()
3739
{
38-
try
39-
{
40-
_hookWinEventSafeHandle = PInvoke.SetWinEventHook(
40+
if (_isInitialized) return true;
41+
42+
_hookWinEventSafeHandle = PInvoke.SetWinEventHook(
4143
PInvoke.EVENT_SYSTEM_FOREGROUND,
4244
PInvoke.EVENT_SYSTEM_FOREGROUND,
4345
null,
@@ -46,20 +48,14 @@ public static bool Initialize()
4648
0,
4749
PInvoke.WINEVENT_OUTOFCONTEXT);
4850

49-
if (_hookWinEventSafeHandle.IsInvalid)
50-
{
51-
Log.Error("Failed to set window event hook");
52-
return false;
53-
}
54-
55-
return true;
56-
}
57-
catch (System.Exception e)
51+
if (_hookWinEventSafeHandle.IsInvalid)
5852
{
59-
Log.Exception(ClassName, "Failed to initialize QuickSwitch", e);
53+
Log.Error(ClassName, "Failed to initialize QuickSwitch");
54+
return false;
6055
}
6156

62-
return false;
57+
_isInitialized = true;
58+
return true;
6359
}
6460

6561
public static void OnToggleHotkey(object sender, HotkeyEventArgs args)

Flow.Launcher/App.xaml.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
using Flow.Launcher.Infrastructure.Http;
1616
using Flow.Launcher.Infrastructure.Image;
1717
using Flow.Launcher.Infrastructure.Logger;
18+
using Flow.Launcher.Infrastructure.QuickSwitch;
1819
using Flow.Launcher.Infrastructure.Storage;
1920
using Flow.Launcher.Infrastructure.UserSettings;
2021
using Flow.Launcher.Plugin;
@@ -184,6 +185,8 @@ await API.StopwatchLogInfoAsync(ClassName, "Startup cost", async () =>
184185
// main windows needs initialized before theme change because of blur settings
185186
Ioc.Default.GetRequiredService<Theme>().ChangeTheme();
186187

188+
QuickSwitch.Initialize();
189+
187190
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
188191

189192
RegisterExitEvents();

0 commit comments

Comments
 (0)