Skip to content

Commit eb26070

Browse files
committed
Merge branch 'warnings' of https://github.com/nachmore/Flow.Launcher into warnings
2 parents a3197f8 + 1d02c30 commit eb26070

File tree

12 files changed

+145
-63
lines changed

12 files changed

+145
-63
lines changed

Flow.Launcher.Core/Plugin/JsonPRCModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,4 +93,4 @@ public class JsonRPCResult : Result
9393

9494
public Dictionary<string, object> SettingsChange { get; set; }
9595
}
96-
}
96+
}

Flow.Launcher.Core/Resource/Theme.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,13 @@ public bool ChangeTheme(string theme)
8585

8686
Settings.Theme = theme;
8787

88+
// reload all resources even if the theme itself hasn't changed in order to pickup changes
89+
// to things like fonts
90+
UpdateResourceDictionary(GetResourceDictionary());
91+
8892
//always allow re-loading default theme, in case of failure of switching to a new theme from default theme
8993
if (_oldTheme != theme || theme == defaultTheme)
9094
{
91-
UpdateResourceDictionary(GetResourceDictionary());
9295
_oldTheme = Path.GetFileNameWithoutExtension(_oldResource.Source.AbsolutePath);
9396
}
9497

Flow.Launcher/App.xaml.cs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using System.Diagnostics;
33
using System.Text;
44
using System.Threading.Tasks;
@@ -104,14 +104,22 @@ await Stopwatch.NormalAsync("|App.OnStartup|Startup cost", async () =>
104104
});
105105
}
106106

107-
108107
private void AutoStartup()
109108
{
110-
if (_settings.StartFlowLauncherOnSystemStartup)
109+
// we try to enable auto-startup on first launch, or reenable if it was removed
110+
// but the user still has the setting set
111+
if (_settings.StartFlowLauncherOnSystemStartup && !Helper.AutoStartup.IsEnabled)
111112
{
112-
if (!SettingWindow.StartupSet())
113+
try
114+
{
115+
Helper.AutoStartup.Enable();
116+
}
117+
catch (Exception e)
113118
{
114-
SettingWindow.SetStartup();
119+
// but if it fails (permissions, etc) then don't keep retrying
120+
// this also gives the user a visual indication in the Settings widget
121+
_settings.StartFlowLauncherOnSystemStartup = false;
122+
Notification.Show(InternationalizationManager.Instance.GetTranslation("setAutoStartFailed"), e.Message);
115123
}
116124
}
117125
}

Flow.Launcher/Helper/AutoStartup.cs

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
using Flow.Launcher.Infrastructure;
7+
using Flow.Launcher.Infrastructure.Logger;
8+
using Microsoft.Win32;
9+
10+
namespace Flow.Launcher.Helper
11+
{
12+
public class AutoStartup
13+
{
14+
private const string StartupPath = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run";
15+
16+
public static bool IsEnabled
17+
{
18+
get
19+
{
20+
try
21+
{
22+
using var key = Registry.CurrentUser.OpenSubKey(StartupPath, true);
23+
var path = key?.GetValue(Constant.FlowLauncher) as string;
24+
return path == Constant.ExecutablePath;
25+
}
26+
catch (Exception e)
27+
{
28+
Log.Error("AutoStartup", $"Ignoring non-critical registry error (querying if enabled): {e}");
29+
}
30+
31+
return false;
32+
}
33+
}
34+
35+
public static void Disable()
36+
{
37+
try
38+
{
39+
using var key = Registry.CurrentUser.OpenSubKey(StartupPath, true);
40+
key?.DeleteValue(Constant.FlowLauncher, false);
41+
}
42+
catch (Exception e)
43+
{
44+
Log.Error("AutoStartup", $"Failed to disable auto-startup: {e}");
45+
throw;
46+
}
47+
}
48+
49+
internal static void Enable()
50+
{
51+
try
52+
{
53+
using var key = Registry.CurrentUser.OpenSubKey(StartupPath, true);
54+
key?.SetValue(Constant.FlowLauncher, Constant.ExecutablePath);
55+
}
56+
catch (Exception e)
57+
{
58+
Log.Error("AutoStartup", $"Failed to enable auto-startup: {e}");
59+
throw;
60+
}
61+
}
62+
}
63+
}

Flow.Launcher/Languages/en.xaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
<system:String x:Key="portableMode">Portable Mode</system:String>
3131
<system:String x:Key="portableModeToolTIp">Store all settings and user data in one folder (Useful when used with removable drives or cloud services).</system:String>
3232
<system:String x:Key="startFlowLauncherOnSystemStartup">Start Flow Launcher on system startup</system:String>
33+
<system:String x:Key="setAutoStartFailed">Error setting launch on startup</system:String>
3334
<system:String x:Key="hideFlowLauncherWhenLoseFocus">Hide Flow Launcher when focus is lost</system:String>
3435
<system:String x:Key="dontPromptUpdateMsg">Do not show new version notifications</system:String>
3536
<system:String x:Key="rememberLastLocation">Remember last launch location</system:String>

Flow.Launcher/Notification.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ internal static void Uninstall()
1818
}
1919

2020
[System.Diagnostics.CodeAnalysis.SuppressMessage("Interoperability", "CA1416:Validate platform compatibility", Justification = "<Pending>")]
21-
public static void Show(string title, string subTitle, string iconPath)
21+
public static void Show(string title, string subTitle, string iconPath = null)
2222
{
2323
// Handle notification for win7/8/early win10
2424
if (legacy)
@@ -45,4 +45,4 @@ private static void LegacyShow(string title, string subTitle, string iconPath)
4545
msg.Show(title, subTitle, iconPath);
4646
}
4747
}
48-
}
48+
}

Flow.Launcher/PublicAPIInstance.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using System.Collections.Generic;
33
using System.Linq;
44
using System.Net;
@@ -285,4 +285,4 @@ private bool KListener_hookedKeyboardCallback(KeyEvent keyevent, int vkcode, Spe
285285

286286
#endregion
287287
}
288-
}
288+
}

Flow.Launcher/SettingWindow.xaml

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -598,10 +598,8 @@
598598
<TextBlock Style="{DynamicResource SettingTitleLabel}" Text="{DynamicResource startFlowLauncherOnSystemStartup}" />
599599
</StackPanel>
600600
<CheckBox
601-
Checked="OnAutoStartupChecked"
602-
IsChecked="{Binding Settings.StartFlowLauncherOnSystemStartup}"
603-
Style="{DynamicResource SideControlCheckBox}"
604-
Unchecked="OnAutoStartupUncheck" />
601+
IsChecked="{Binding StartFlowLauncherOnSystemStartup}"
602+
Style="{DynamicResource SideControlCheckBox}" />
605603
<TextBlock Style="{StaticResource Glyph}">
606604
&#xe8fc;
607605
</TextBlock>
@@ -917,6 +915,7 @@
917915
Padding="0,0,0,0"
918916
Background="{DynamicResource Color01B}">
919917
<ListBox
918+
Name="Plugins"
920919
Width="Auto"
921920
Margin="5,0,0,0"
922921
Padding="0,0,7,0"
@@ -928,8 +927,7 @@
928927
ScrollViewer.HorizontalScrollBarVisibility="Disabled"
929928
SelectedItem="{Binding SelectedPlugin}"
930929
SelectionChanged="SelectedPluginChanged"
931-
SnapsToDevicePixels="True"
932-
Name="Plugins">
930+
SnapsToDevicePixels="True">
933931
<ListBox.ItemsPanel>
934932
<ItemsPanelTemplate>
935933
<StackPanel Margin="0,0,0,18" />
@@ -1118,8 +1116,8 @@
11181116
Margin="0"
11191117
Padding="1"
11201118
VerticalAlignment="Stretch"
1121-
Content="{Binding SettingControl}"
1122-
SizeChanged="ItemSizeChanged"/>
1119+
Content="{Binding SettingControl}"
1120+
SizeChanged="ItemSizeChanged" />
11231121
</StackPanel>
11241122

11251123
<StackPanel>
@@ -1129,8 +1127,7 @@
11291127
VerticalAlignment="Center"
11301128
BorderThickness="0,1,0,0"
11311129
CornerRadius="0"
1132-
Style="{DynamicResource SettingGroupBox}"
1133-
Visibility="{Binding ActionKeywordsVisibility}">
1130+
Style="{DynamicResource SettingGroupBox}">
11341131
<ItemsControl Style="{DynamicResource SettingGrid}">
11351132
<StackPanel
11361133
Margin="0,0,-14,0"

Flow.Launcher/SettingWindow.xaml.cs

Lines changed: 1 addition & 35 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;
@@ -30,8 +31,6 @@ namespace Flow.Launcher
3031
{
3132
public partial class SettingWindow
3233
{
33-
private const string StartupPath = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run";
34-
3534
public readonly IPublicAPI API;
3635
private Settings settings;
3736
private SettingWindowViewModel viewModel;
@@ -57,39 +56,6 @@ private void OnLoaded(object sender, RoutedEventArgs e)
5756
hwndTarget.RenderMode = RenderMode.SoftwareOnly;
5857
}
5958

60-
private void OnAutoStartupChecked(object sender, RoutedEventArgs e)
61-
{
62-
SetStartup();
63-
}
64-
65-
private void OnAutoStartupUncheck(object sender, RoutedEventArgs e)
66-
{
67-
RemoveStartup();
68-
}
69-
70-
public static void SetStartup()
71-
{
72-
using var key = Registry.CurrentUser.OpenSubKey(StartupPath, true);
73-
key?.SetValue(Constant.FlowLauncher, Constant.ExecutablePath);
74-
}
75-
76-
private void RemoveStartup()
77-
{
78-
using var key = Registry.CurrentUser.OpenSubKey(StartupPath, true);
79-
key?.DeleteValue(Constant.FlowLauncher, false);
80-
}
81-
82-
public static bool StartupSet()
83-
{
84-
using var key = Registry.CurrentUser.OpenSubKey(StartupPath, true);
85-
var path = key?.GetValue(Constant.FlowLauncher) as string;
86-
if (path != null)
87-
{
88-
return path == Constant.ExecutablePath;
89-
}
90-
return false;
91-
}
92-
9359
private void OnSelectPythonDirectoryClick(object sender, RoutedEventArgs e)
9460
{
9561
var dlg = new FolderBrowserDialog

Flow.Launcher/ViewModel/MainViewModel.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -306,8 +306,8 @@ private void InitializeKeyCommands()
306306
{
307307
Notification.Show(
308308
InternationalizationManager.Instance.GetTranslation("success"),
309-
InternationalizationManager.Instance.GetTranslation("completedSuccessfully"),
310-
"");
309+
InternationalizationManager.Instance.GetTranslation("completedSuccessfully")
310+
);
311311
}), TaskScheduler.Default)
312312
.ConfigureAwait(false);
313313
});

0 commit comments

Comments
 (0)