Skip to content

Commit a07252c

Browse files
committed
add ability to switch off warning when unknown source
fixed search terms to show with out to lower
1 parent ebf9ef1 commit a07252c

File tree

7 files changed

+64
-23
lines changed

7 files changed

+64
-23
lines changed

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
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>
1111
<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>
1212
<system:String x:Key="plugin_pluginsmanager_install_title">Plugin Install</system:String>
13+
<system:String x:Key="plugin_pluginsmanager_install_from_web">Download and install {0}</system:String>
1314
<system:String x:Key="plugin_pluginsmanager_uninstall_title">Plugin Uninstall</system:String>
1415
<system:String x:Key="plugin_pluginsmanager_install_in_progress">Plugin installation in progress. Please wait...</system:String>
1516
<system:String x:Key="plugin_pluginsmanager_install_success_restart">Plugin successfully installed. Restarting Flow, please wait...</system:String>
@@ -25,7 +26,9 @@
2526
<system:String x:Key="plugin_pluginsmanager_update_alreadyexists">This plugin is already installed</system:String>
2627
<system:String x:Key="plugin_pluginsmanager_update_failed_title">Plugin Manifest Download Failed</system:String>
2728
<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>
28-
29+
<system:String x:Key="plugin_pluginsmanager_install_unknown_source_warning_title">Installing from an unknown source</system:String>
30+
<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+
2932
<!--Controls-->
3033

3134
<!--Plugin Infos-->
@@ -42,5 +45,7 @@
4245
<system:String x:Key="plugin_pluginsmanager_plugin_contextmenu_newissue_subtitle">Suggest an enhancement or submit an issue to the plugin developer</system:String>
4346
<system:String x:Key="plugin_pluginsmanager_plugin_contextmenu_pluginsmanifest_title">Go to Flow's plugins repository</system:String>
4447
<system:String x:Key="plugin_pluginsmanager_plugin_contextmenu_pluginsmanifest_subtitle">Visit the PluginsManifest repository to see community-made plugin submissions</system:String>
45-
48+
49+
<!--Settings menu items-->
50+
<system:String x:Key="plugin_pluginsmanager_plugin_settings_unknown_source">Install from unknown source warning</system:String>
4651
</ResourceDictionary>

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public List<Result> LoadContextMenus(Result selectedResult)
5555

5656
public async Task<List<Result>> QueryAsync(Query query, CancellationToken token)
5757
{
58-
var search = query.Search.ToLower();
58+
var search = query.Search;
5959

6060
if (string.IsNullOrWhiteSpace(search))
6161
return pluginManager.GetDefaultHotKeys();
@@ -70,9 +70,13 @@ public async Task<List<Result>> QueryAsync(Query query, CancellationToken token)
7070

7171
return search switch
7272
{
73-
var s when s.StartsWith(Settings.HotKeyInstall) => await pluginManager.RequestInstallOrUpdate(s, token),
74-
var s when s.StartsWith(Settings.HotkeyUninstall) => pluginManager.RequestUninstall(s),
75-
var s when s.StartsWith(Settings.HotkeyUpdate) => await pluginManager.RequestUpdate(s, token),
73+
//search could be url, no need ToLower() when passed in
74+
var s when s.StartsWith(Settings.HotKeyInstall, StringComparison.OrdinalIgnoreCase)
75+
=> await pluginManager.RequestInstallOrUpdate(search, token),
76+
var s when s.StartsWith(Settings.HotkeyUninstall, StringComparison.OrdinalIgnoreCase)
77+
=> pluginManager.RequestUninstall(search),
78+
var s when s.StartsWith(Settings.HotkeyUpdate, StringComparison.OrdinalIgnoreCase)
79+
=> await pluginManager.RequestUpdate(search, token),
7680
_ => pluginManager.GetDefaultHotKeys().Where(hotkey =>
7781
{
7882
hotkey.Score = StringMatcher.FuzzySearch(search, hotkey.Title).Score;

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

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -166,17 +166,12 @@ internal async Task InstallOrUpdate(UserPlugin plugin)
166166
catch (Exception e)
167167
{
168168
if (e is HttpRequestException)
169-
{
170169
MessageBox.Show(Context.API.GetTranslation("plugin_pluginsmanager_download_error"),
171170
Context.API.GetTranslation("plugin_pluginsmanager_downloading_plugin"));
172171

173-
}
174-
else
175-
{
176-
Context.API.ShowMsgError(Context.API.GetTranslation("plugin_pluginsmanager_install_error_title"),
172+
Context.API.ShowMsgError(Context.API.GetTranslation("plugin_pluginsmanager_install_error_title"),
177173
string.Format(Context.API.GetTranslation("plugin_pluginsmanager_install_error_subtitle"),
178174
plugin.Name));
179-
}
180175

181176
Log.Exception("PluginsManager", "An error occured while downloading plugin", e, "InstallOrUpdate");
182177

@@ -206,7 +201,7 @@ internal async ValueTask<List<Result>> RequestUpdate(string search, Cancellation
206201
if (autocompletedResults.Any())
207202
return autocompletedResults;
208203

209-
var uninstallSearch = search.Replace(Settings.HotkeyUpdate, string.Empty).TrimStart();
204+
var uninstallSearch = search.Replace(Settings.HotkeyUpdate, string.Empty, StringComparison.OrdinalIgnoreCase).TrimStart();
210205

211206
var resultsForUpdate =
212207
from existingPlugin in Context.API.GetAllPlugins()
@@ -341,26 +336,46 @@ internal List<Result> InstallFromWeb(string url)
341336

342337
var result = new Result
343338
{
344-
Title = filename,
345-
SubTitle = $"Download and Install from URL",
339+
Title = string.Format(Context.API.GetTranslation("plugin_pluginsmanager_install_from_web"), filename),
340+
SubTitle = plugin.UrlDownload,
346341
IcoPath = icoPath,
347342
Action = e =>
348343
{
349344
if (e.SpecialKeyState.CtrlPressed)
350345
{
351-
SearchWeb.NewTabInBrowser(url);
346+
SearchWeb.NewTabInBrowser(plugin.UrlDownload);
352347
return ShouldHideWindow;
353348
}
354349

350+
if (Settings.WarnFromUnknownSource)
351+
{
352+
if (!InstallSourceKnown(plugin.UrlDownload)
353+
&& MessageBox.Show(string.Format(Context.API.GetTranslation("plugin_pluginsmanager_install_unknown_source_warning"),
354+
Environment.NewLine),
355+
Context.API.GetTranslation("plugin_pluginsmanager_install_unknown_source_warning_title"),
356+
MessageBoxButton.YesNo) == MessageBoxResult.No)
357+
return false;
358+
}
359+
355360
Application.Current.MainWindow.Hide();
356361
_ = InstallOrUpdate(plugin);
362+
357363
return ShouldHideWindow;
358364
}
359365
};
360366

361367
return new List<Result> { result };
362368
}
363-
369+
370+
private bool InstallSourceKnown(string url)
371+
{
372+
var author = url.Split('/')[3];
373+
var acceptedSource = "https://github.com";
374+
var contructedUrlPart = string.Format("{0}/{1}/", acceptedSource, author);
375+
376+
return url.StartsWith(acceptedSource) && Context.API.GetAllPlugins().Any(x => x.Metadata.Website.StartsWith(contructedUrlPart));
377+
}
378+
364379
internal async ValueTask<List<Result>> RequestInstallOrUpdate(string searchName, CancellationToken token)
365380
{
366381
if (!PluginsManifest.UserPlugins.Any())
@@ -370,7 +385,7 @@ internal async ValueTask<List<Result>> RequestInstallOrUpdate(string searchName,
370385

371386
token.ThrowIfCancellationRequested();
372387

373-
var searchNameWithoutKeyword = searchName.Replace(Settings.HotKeyInstall, string.Empty).Trim();
388+
var searchNameWithoutKeyword = searchName.Replace(Settings.HotKeyInstall, string.Empty, StringComparison.OrdinalIgnoreCase).Trim();
374389

375390
if (Uri.IsWellFormedUriString(searchNameWithoutKeyword, UriKind.Absolute)
376391
&& searchNameWithoutKeyword.Split('.').Last() == zip)
@@ -468,7 +483,7 @@ internal List<Result> RequestUninstall(string search)
468483
if (autocompletedResults.Any())
469484
return autocompletedResults;
470485

471-
var uninstallSearch = search.Replace(Settings.HotkeyUninstall, string.Empty).TrimStart();
486+
var uninstallSearch = search.Replace(Settings.HotkeyUninstall, string.Empty, StringComparison.OrdinalIgnoreCase).TrimStart();
472487

473488
var results = Context.API
474489
.GetAllPlugins()

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,11 @@ namespace Flow.Launcher.Plugin.PluginsManager
77
internal class Settings
88
{
99
internal string HotKeyInstall { get; set; } = "install";
10+
1011
internal string HotkeyUninstall { get; set; } = "uninstall";
1112

1213
internal string HotkeyUpdate { get; set; } = "update";
14+
15+
public bool WarnFromUnknownSource { get; set; } = true;
1316
}
1417
}

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,11 @@ public SettingsViewModel(PluginInitContext context, Settings settings)
1414
Context = context;
1515
Settings = settings;
1616
}
17+
18+
public bool WarnFromUnknownSource
19+
{
20+
get => Settings.WarnFromUnknownSource;
21+
set => Settings.WarnFromUnknownSource = value;
22+
}
1723
}
1824
}

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

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,18 @@
33
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
44
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
55
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
6-
xmlns:local="clr-namespace:Flow.Launcher.Plugin.PluginsManager.ViewModels"
76
mc:Ignorable="d"
87
d:DesignHeight="450" d:DesignWidth="800">
9-
<Grid>
10-
8+
<Grid Margin="70 15 0 15">
9+
<Grid.ColumnDefinitions>
10+
<ColumnDefinition Width="250"/>
11+
<ColumnDefinition Width="*"/>
12+
</Grid.ColumnDefinitions>
13+
14+
<TextBlock Grid.Column="0"
15+
Text="{DynamicResource plugin_pluginsmanager_plugin_settings_unknown_source}"
16+
VerticalAlignment="Center"
17+
FontSize="14"/>
18+
<CheckBox Grid.Column="1" IsChecked="{Binding WarnFromUnknownSource}" />
1119
</Grid>
1220
</UserControl>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ internal PluginsManagerSettings(SettingsViewModel viewModel)
1616

1717
this.viewModel = viewModel;
1818

19-
//RefreshView();
19+
this.DataContext = viewModel;
2020
}
2121
}
2222
}

0 commit comments

Comments
 (0)