Skip to content

Commit 4eeaaec

Browse files
committed
fix naming when installed from url source
1 parent 73c1031 commit 4eeaaec

File tree

2 files changed

+27
-10
lines changed

2 files changed

+27
-10
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
<system:String x:Key="plugin_pluginsmanager_downloading_plugin">Downloading plugin</system:String>
77
<system:String x:Key="plugin_pluginsmanager_please_wait">Please wait...</system:String>
88
<system:String x:Key="plugin_pluginsmanager_download_success">Successfully downloaded</system:String>
9+
<system:String x:Key="plugin_pluginsmanager_download_error">Error: Unable to download the plugin</system:String>
910
<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>
1011
<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>
1112
<system:String x:Key="plugin_pluginsmanager_install_title">Plugin Install</system:String>
@@ -29,6 +30,7 @@
2930
<!--Plugin Infos-->
3031
<system:String x:Key="plugin_pluginsmanager_plugin_name">Plugins Manager</system:String>
3132
<system:String x:Key="plugin_pluginsmanager_plugin_description">Management of installing, uninstalling or updating Flow Launcher plugins</system:String>
33+
<system:String x:Key="plugin_pluginsmanager_unknown_author">Unknown Author</system:String>
3234

3335
<!--Context menu items-->
3436
<system:String x:Key="plugin_pluginsmanager_plugin_contextmenu_openwebsite_title">Open website</system:String>

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

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
using System.Collections.Generic;
1010
using System.IO;
1111
using System.Linq;
12+
using System.Net.Http;
1213
using System.Threading;
1314
using System.Threading.Tasks;
1415
using System.Windows;
@@ -17,6 +18,8 @@ namespace Flow.Launcher.Plugin.PluginsManager
1718
{
1819
internal class PluginsManager
1920
{
21+
const string zip = "zip";
22+
2023
private PluginInitContext Context { get; set; }
2124

2225
private Settings Settings { get; set; }
@@ -161,9 +164,18 @@ internal async Task InstallOrUpdate(UserPlugin plugin)
161164
}
162165
catch (Exception e)
163166
{
164-
Context.API.ShowMsgError(Context.API.GetTranslation("plugin_pluginsmanager_install_error_title"),
167+
if (e is HttpRequestException)
168+
{
169+
MessageBox.Show(Context.API.GetTranslation("plugin_pluginsmanager_download_error"),
170+
Context.API.GetTranslation("plugin_pluginsmanager_downloading_plugin"));
171+
172+
}
173+
else
174+
{
175+
Context.API.ShowMsgError(Context.API.GetTranslation("plugin_pluginsmanager_install_error_title"),
165176
string.Format(Context.API.GetTranslation("plugin_pluginsmanager_install_error_subtitle"),
166177
plugin.Name));
178+
}
167179

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

@@ -314,19 +326,21 @@ internal List<Result> Search(IEnumerable<Result> results, string searchName)
314326

315327
internal List<Result> InstallFromWeb(string url)
316328
{
317-
var fileName = url.Split("/").Last();
318-
var filePath = Path.Combine(DataLocation.PluginsDirectory, fileName);
329+
var filename = url.Split("/").Last();
330+
var name = filename.Split(string.Format(".{0}", zip)).First();
331+
319332
var plugin = new UserPlugin
320333
{
321334
ID = "",
322-
Name = fileName.Split(".").First(),
335+
Name = name,
323336
Version = string.Empty,
324-
Author = "N/A",
337+
Author = Context.API.GetTranslation("plugin_pluginsmanager_unknown_author"),
325338
UrlDownload = url
326339
};
340+
327341
var result = new Result
328342
{
329-
Title = fileName,
343+
Title = filename,
330344
SubTitle = $"Download and Install from URL",
331345
IcoPath = icoPath,
332346
Action = e =>
@@ -342,6 +356,7 @@ internal List<Result> InstallFromWeb(string url)
342356
return ShouldHideWindow;
343357
}
344358
};
359+
345360
return new List<Result> { result };
346361
}
347362

@@ -356,6 +371,10 @@ internal async ValueTask<List<Result>> RequestInstallOrUpdate(string searchName,
356371

357372
var searchNameWithoutKeyword = searchName.Replace(Settings.HotKeyInstall, string.Empty).Trim();
358373

374+
if (Uri.IsWellFormedUriString(searchNameWithoutKeyword, UriKind.Absolute)
375+
&& searchNameWithoutKeyword.Split('.').Last() == zip)
376+
return InstallFromWeb(searchNameWithoutKeyword);
377+
359378
var results =
360379
PluginsManifest
361380
.UserPlugins
@@ -380,10 +399,6 @@ internal async ValueTask<List<Result>> RequestInstallOrUpdate(string searchName,
380399
ContextData = x
381400
});
382401

383-
if (Uri.IsWellFormedUriString(searchNameWithoutKeyword, UriKind.Absolute))
384-
{
385-
return InstallFromWeb(searchNameWithoutKeyword);
386-
}
387402
return Search(results, searchNameWithoutKeyword);
388403
}
389404

0 commit comments

Comments
 (0)