Skip to content

Commit c3a67d4

Browse files
committed
Fix crash when user does not have access to registry startup keys
Instead log an error about non-critical functionality and continue on.
1 parent b079aa3 commit c3a67d4

File tree

1 file changed

+27
-7
lines changed

1 file changed

+27
-7
lines changed

Flow.Launcher/SettingWindow.xaml.cs

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using Flow.Launcher.Helper;
55
using Flow.Launcher.Infrastructure;
66
using Flow.Launcher.Infrastructure.Hotkey;
7+
using Flow.Launcher.Infrastructure.Logger;
78
using Flow.Launcher.Infrastructure.UserSettings;
89
using Flow.Launcher.Plugin;
910
using Flow.Launcher.Plugin.SharedCommands;
@@ -70,24 +71,43 @@ private void OnAutoStartupUncheck(object sender, RoutedEventArgs e)
7071

7172
public static void SetStartup()
7273
{
73-
using var key = Registry.CurrentUser.OpenSubKey(StartupPath, true);
74-
key?.SetValue(Constant.FlowLauncher, Constant.ExecutablePath);
74+
try
75+
{
76+
using var key = Registry.CurrentUser.OpenSubKey(StartupPath, true);
77+
key?.SetValue(Constant.FlowLauncher, Constant.ExecutablePath);
78+
}
79+
catch (Exception e)
80+
{
81+
Log.Error("SettingsWindow", $"Ignoring non-critical registry error (user permissions?): {e}");
82+
}
7583
}
7684

7785
private void RemoveStartup()
7886
{
79-
using var key = Registry.CurrentUser.OpenSubKey(StartupPath, true);
80-
key?.DeleteValue(Constant.FlowLauncher, false);
87+
try
88+
{
89+
using var key = Registry.CurrentUser.OpenSubKey(StartupPath, true);
90+
key?.DeleteValue(Constant.FlowLauncher, false);
91+
}
92+
catch (Exception e)
93+
{
94+
Log.Error("SettingsWindow", $"Ignoring non-critical registry error (user permissions?): {e}");
95+
}
8196
}
8297

8398
public static bool StartupSet()
8499
{
85-
using var key = Registry.CurrentUser.OpenSubKey(StartupPath, true);
86-
var path = key?.GetValue(Constant.FlowLauncher) as string;
87-
if (path != null)
100+
try
88101
{
102+
using var key = Registry.CurrentUser.OpenSubKey(StartupPath, true);
103+
var path = key?.GetValue(Constant.FlowLauncher) as string;
89104
return path == Constant.ExecutablePath;
90105
}
106+
catch (Exception e)
107+
{
108+
Log.Error("SettingsWindow", $"Ignoring non-critical registry error (user permissions?): {e}");
109+
}
110+
91111
return false;
92112
}
93113

0 commit comments

Comments
 (0)