Skip to content

Commit 1334798

Browse files
Add AutoRestartAfterChanging option
- Option and UI - New prompts and notification messages
1 parent 31131ea commit 1334798

File tree

5 files changed

+107
-20
lines changed

5 files changed

+107
-20
lines changed

Plugins/Flow.Launcher.Plugin.PluginsManager/Languages/en.xaml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
<system:String x:Key="plugin_pluginsmanager_download_success">Successfully downloaded {0}</system:String>
99
<system:String x:Key="plugin_pluginsmanager_download_error">Error: Unable to download the plugin</system:String>
1010
<system:String x:Key="plugin_pluginsmanager_uninstall_prompt">{0} by {1} {2}{3}Would you like to uninstall this plugin? After the uninstallation Flow will automatically restart.</system:String>
11+
<system:String x:Key="plugin_pluginsmanager_uninstall_prompt_no_restart">{0} by {1} {2}{2}Would you like to uninstall this plugin?</system:String>
1112
<system:String x:Key="plugin_pluginsmanager_install_prompt">{0} by {1} {2}{3}Would you like to install this plugin? After the installation Flow will automatically restart.</system:String>
13+
<system:String x:Key="plugin_pluginsmanager_install_prompt_no_restart">{0} by {1} {2}{2}Would you like to install this plugin?</system:String>
1214
<system:String x:Key="plugin_pluginsmanager_install_title">Plugin Install</system:String>
1315
<system:String x:Key="plugin_pluginsmanager_installing_plugin">Installing Plugin</system:String>
1416
<system:String x:Key="plugin_pluginsmanager_install_from_web">Download and install {0}</system:String>
@@ -21,15 +23,19 @@
2123
<system:String x:Key="plugin_pluginsmanager_update_noresult_title">No update available</system:String>
2224
<system:String x:Key="plugin_pluginsmanager_update_noresult_subtitle">All plugins are up to date</system:String>
2325
<system:String x:Key="plugin_pluginsmanager_update_prompt">{0} by {1} {2}{3}Would you like to update this plugin? After the update Flow will automatically restart.</system:String>
26+
<system:String x:Key="plugin_pluginsmanager_update_prompt_no_restart">{0} by {1} {2}{2}Would you like to update this plugin?</system:String>
2427
<system:String x:Key="plugin_pluginsmanager_update_title">Plugin Update</system:String>
2528
<system:String x:Key="plugin_pluginsmanager_update_exists">This plugin has an update, would you like to see it?</system:String>
2629
<system:String x:Key="plugin_pluginsmanager_update_alreadyexists">This plugin is already installed</system:String>
2730
<system:String x:Key="plugin_pluginsmanager_update_failed_title">Plugin Manifest Download Failed</system:String>
2831
<system:String x:Key="plugin_pluginsmanager_update_failed_subtitle">Please check if you can connect to github.com. This error means you may not be able to install or update plugins.</system:String>
32+
<system:String x:Key="plugin_pluginsmanager_update_success_restart">Plugin {0} successfully updated. Restarting Flow, please wait...</system:String>
2933
<system:String x:Key="plugin_pluginsmanager_install_unknown_source_warning_title">Installing from an unknown source</system:String>
3034
<system:String x:Key="plugin_pluginsmanager_install_unknown_source_warning">You are installing this plugin from an unknown source and it may contain potential risks!{0}{0}Please ensure you understand where this plugin is from and that it is safe.{0}{0}Would you like to continue still?{0}{0}(You can switch off this warning via settings)</system:String>
31-
32-
<!-- Controls -->
35+
36+
<system:String x:Key="plugin_pluginsmanager_install_success_no_restart">Plugin {0} successfully installed. Please manually restart Flow.</system:String>
37+
<system:String x:Key="plugin_pluginsmanager_uninstall_success_no_restart">Plugin {0} successfully uninstalled. Please manually restart Flow.</system:String>
38+
<system:String x:Key="plugin_pluginsmanager_update_success_no_restart">Plugin {0} successfully updated. Please manually restart Flow.</system:String>
3339

3440
<!-- Plugin Infos -->
3541
<system:String x:Key="plugin_pluginsmanager_plugin_name">Plugins Manager</system:String>
@@ -48,4 +54,5 @@
4854

4955
<!-- Settings menu items -->
5056
<system:String x:Key="plugin_pluginsmanager_plugin_settings_unknown_source">Install from unknown source warning</system:String>
57+
<system:String x:Key="plugin_pluginsmanager_plugin_settings_auto_restart">Automatically restart Flow Launcher after installing/uninstalling/updating plugins</system:String>
5158
</ResourceDictionary>

Plugins/Flow.Launcher.Plugin.PluginsManager/PluginsManager.cs

Lines changed: 78 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,19 @@ internal async Task InstallOrUpdateAsync(UserPlugin plugin)
117117
return;
118118
}
119119

120-
var message = string.Format(Context.API.GetTranslation("plugin_pluginsmanager_install_prompt"),
121-
plugin.Name, plugin.Author,
122-
Environment.NewLine, Environment.NewLine);
120+
string message;
121+
if (Settings.AutoRestartAfterChanging)
122+
{
123+
message = string.Format(Context.API.GetTranslation("plugin_pluginsmanager_install_prompt"),
124+
plugin.Name, plugin.Author,
125+
Environment.NewLine, Environment.NewLine);
126+
}
127+
else
128+
{
129+
message = string.Format(Context.API.GetTranslation("plugin_pluginsmanager_install_prompt_no_restart"),
130+
plugin.Name, plugin.Author,
131+
Environment.NewLine);
132+
}
123133

124134
if (MessageBox.Show(message, Context.API.GetTranslation("plugin_pluginsmanager_install_title"),
125135
MessageBoxButton.YesNo) == MessageBoxResult.No)
@@ -140,6 +150,7 @@ internal async Task InstallOrUpdateAsync(UserPlugin plugin)
140150
}
141151
catch (Exception e)
142152
{
153+
// TODO use toast to optimize error prompt
143154
if (e is HttpRequestException)
144155
MessageBox.Show(Context.API.GetTranslation("plugin_pluginsmanager_download_error"),
145156
Context.API.GetTranslation("plugin_pluginsmanager_downloading_plugin"));
@@ -153,10 +164,19 @@ internal async Task InstallOrUpdateAsync(UserPlugin plugin)
153164
return;
154165
}
155166

156-
Context.API.ShowMsg(Context.API.GetTranslation("plugin_pluginsmanager_installing_plugin"),
157-
string.Format(Context.API.GetTranslation("plugin_pluginsmanager_install_success_restart"), plugin.Name));
158-
159-
Context.API.RestartApp();
167+
if (Settings.AutoRestartAfterChanging)
168+
{
169+
Context.API.ShowMsg(Context.API.GetTranslation("plugin_pluginsmanager_installing_plugin"),
170+
string.Format(Context.API.GetTranslation("plugin_pluginsmanager_install_success_restart"),
171+
plugin.Name));
172+
Context.API.RestartApp();
173+
}
174+
else
175+
{
176+
Context.API.ShowMsg(Context.API.GetTranslation("plugin_pluginsmanager_installing_plugin"),
177+
string.Format(Context.API.GetTranslation("plugin_pluginsmanager_install_success_no_restart"),
178+
plugin.Name));
179+
}
160180
}
161181

162182
internal async ValueTask<List<Result>> RequestUpdateAsync(string search, CancellationToken token, bool usePrimaryUrlOnly = false)
@@ -201,10 +221,20 @@ where existingPlugin.Metadata.Version.CompareTo(pluginFromManifest.Version) <
201221
IcoPath = x.IcoPath,
202222
Action = e =>
203223
{
204-
string message = string.Format(
205-
Context.API.GetTranslation("plugin_pluginsmanager_update_prompt"),
206-
x.Name, x.Author,
207-
Environment.NewLine, Environment.NewLine);
224+
225+
string message;
226+
if (Settings.AutoRestartAfterChanging)
227+
{
228+
message = string.Format(Context.API.GetTranslation("plugin_pluginsmanager_update_prompt"),
229+
x.Name, x.Author,
230+
Environment.NewLine, Environment.NewLine);
231+
}
232+
else
233+
{
234+
message = string.Format(Context.API.GetTranslation("plugin_pluginsmanager_update_prompt_no_restart"),
235+
x.Name, x.Author,
236+
Environment.NewLine);
237+
}
208238

209239
if (MessageBox.Show(message,
210240
Context.API.GetTranslation("plugin_pluginsmanager_update_title"),
@@ -215,14 +245,26 @@ where existingPlugin.Metadata.Version.CompareTo(pluginFromManifest.Version) <
215245
var downloadToFilePath = Path.Combine(DataLocation.PluginsDirectory,
216246
$"{x.Name}-{x.NewVersion}.zip");
217247

218-
Task.Run(async delegate
248+
_ = Task.Run(async delegate
219249
{
220250
await Http.DownloadAsync(x.PluginNewUserPlugin.UrlDownload, downloadToFilePath)
221251
.ConfigureAwait(false);
222252

223253
Install(x.PluginNewUserPlugin, downloadToFilePath);
224254

225-
Context.API.RestartApp();
255+
if (Settings.AutoRestartAfterChanging)
256+
{
257+
Context.API.ShowMsg(Context.API.GetTranslation("plugin_pluginsmanager_update_title"),
258+
string.Format(Context.API.GetTranslation("plugin_pluginsmanager_update_success_restart"),
259+
x.Name));
260+
Context.API.RestartApp();
261+
}
262+
else
263+
{
264+
Context.API.ShowMsg(Context.API.GetTranslation("plugin_pluginsmanager_update_title"),
265+
string.Format(Context.API.GetTranslation("plugin_pluginsmanager_update_success_no_restart"),
266+
x.Name));
267+
}
226268
}).ContinueWith(t =>
227269
{
228270
Log.Exception("PluginsManager", $"Update failed for {x.Name}",
@@ -454,18 +496,36 @@ internal List<Result> RequestUninstall(string search)
454496
IcoPath = x.Metadata.IcoPath,
455497
Action = e =>
456498
{
457-
string message = string.Format(
458-
Context.API.GetTranslation("plugin_pluginsmanager_uninstall_prompt"),
459-
x.Metadata.Name, x.Metadata.Author,
460-
Environment.NewLine, Environment.NewLine);
499+
string message;
500+
if (Settings.AutoRestartAfterChanging)
501+
{
502+
message = string.Format(Context.API.GetTranslation("plugin_pluginsmanager_uninstall_prompt"),
503+
x.Metadata.Name, x.Metadata.Author,
504+
Environment.NewLine, Environment.NewLine);
505+
}
506+
else
507+
{
508+
message = string.Format(Context.API.GetTranslation("plugin_pluginsmanager_uninstall_prompt_no_restart"),
509+
x.Metadata.Name, x.Metadata.Author,
510+
Environment.NewLine);
511+
}
461512

462513
if (MessageBox.Show(message,
463514
Context.API.GetTranslation("plugin_pluginsmanager_uninstall_title"),
464515
MessageBoxButton.YesNo) == MessageBoxResult.Yes)
465516
{
466517
Application.Current.MainWindow.Hide();
467518
Uninstall(x.Metadata);
468-
Context.API.RestartApp();
519+
if (Settings.AutoRestartAfterChanging)
520+
{
521+
Context.API.RestartApp();
522+
}
523+
else
524+
{
525+
Context.API.ShowMsg(Context.API.GetTranslation("plugin_pluginsmanager_uninstall_title"),
526+
string.Format(Context.API.GetTranslation("plugin_pluginsmanager_uninstall_success_no_restart"),
527+
x.Metadata.Name));
528+
}
469529

470530
return true;
471531
}

Plugins/Flow.Launcher.Plugin.PluginsManager/Settings.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,7 @@ internal class Settings
99
internal const string UpdateCommand = "update";
1010

1111
public bool WarnFromUnknownSource { get; set; } = true;
12+
13+
public bool AutoRestartAfterChanging { get; set; } = false;
1214
}
1315
}

Plugins/Flow.Launcher.Plugin.PluginsManager/ViewModels/SettingsViewModel.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,11 @@ public bool WarnFromUnknownSource
1717
get => Settings.WarnFromUnknownSource;
1818
set => Settings.WarnFromUnknownSource = value;
1919
}
20+
21+
public bool AutoRestartAfterChanging
22+
{
23+
get => Settings.AutoRestartAfterChanging;
24+
set => Settings.AutoRestartAfterChanging = value;
25+
}
2026
}
2127
}

Plugins/Flow.Launcher.Plugin.PluginsManager/Views/PluginsManagerSettings.xaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,22 @@
1212
<ColumnDefinition Width="400" />
1313
<ColumnDefinition Width="*" />
1414
</Grid.ColumnDefinitions>
15+
<Grid.RowDefinitions>
16+
<RowDefinition Height="auto" />
17+
<RowDefinition Height="auto" />
18+
</Grid.RowDefinitions>
1519
<CheckBox
1620
Grid.Column="0"
21+
Grid.Row="0"
1722
Padding="8,0,0,0"
1823
Content="{DynamicResource plugin_pluginsmanager_plugin_settings_unknown_source}"
1924
IsChecked="{Binding WarnFromUnknownSource}" />
25+
<CheckBox
26+
Grid.Column="0"
27+
Grid.Row="1"
28+
Margin="0,20,0,0"
29+
Padding="8,0,0,0"
30+
Content="{DynamicResource plugin_pluginsmanager_plugin_settings_auto_restart}"
31+
IsChecked="{Binding AutoRestartAfterChanging}" />
2032
</Grid>
2133
</UserControl>

0 commit comments

Comments
 (0)