Skip to content

Commit 2e8c919

Browse files
committed
Add local plugin installation
Signed-off-by: Florian Grabmeier <[email protected]>
1 parent f50281b commit 2e8c919

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed

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

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
using System.Threading;
1515
using System.Threading.Tasks;
1616
using System.Windows;
17+
using System.IO.Compression;
18+
using Newtonsoft.Json;
1719

1820
namespace Flow.Launcher.Plugin.PluginsManager
1921
{
@@ -138,6 +140,12 @@ internal async Task InstallOrUpdateAsync(UserPlugin plugin)
138140
MessageBoxButton.YesNo) == MessageBoxResult.No)
139141
return;
140142

143+
if (File.Exists(plugin.UrlDownload))
144+
{
145+
Install(plugin, plugin.UrlDownload);
146+
return;
147+
}
148+
141149
// at minimum should provide a name, but handle plugin that is not downloaded from plugins manifest and is a url download
142150
var downloadFilename = string.IsNullOrEmpty(plugin.Version)
143151
? $"{plugin.Name}-{Guid.NewGuid()}.zip"
@@ -470,6 +478,54 @@ internal List<Result> InstallFromWeb(string url)
470478
return new List<Result> { result };
471479
}
472480

481+
internal List<Result> InstallFromLocal(string path)
482+
{
483+
if (string.IsNullOrEmpty(path) || !File.Exists(path))
484+
{
485+
return new List<Result>();
486+
}
487+
488+
var plugin = null as UserPlugin;
489+
490+
using (ZipArchive archive = ZipFile.OpenRead(path))
491+
{
492+
var pluginJsonPath = archive.Entries.FirstOrDefault(x => x.Name == "plugin.json").ToString();
493+
ZipArchiveEntry pluginJsonEntry = archive.GetEntry(pluginJsonPath);
494+
495+
if (pluginJsonEntry != null)
496+
{
497+
using (StreamReader reader = new StreamReader(pluginJsonEntry.Open()))
498+
{
499+
string pluginJsonContent = reader.ReadToEnd();
500+
plugin = JsonConvert.DeserializeObject<UserPlugin>(pluginJsonContent);
501+
plugin.IcoPath = Path.Combine(path, pluginJsonEntry.FullName.Split('/')[0], plugin.IcoPath);
502+
}
503+
}
504+
}
505+
506+
if (plugin == null)
507+
{
508+
return new List<Result>();
509+
}
510+
511+
plugin.UrlDownload = path;
512+
513+
var result = new Result
514+
{
515+
Title = plugin.Name,
516+
SubTitle = plugin.UrlDownload,
517+
IcoPath = plugin.IcoPath,
518+
Action = e =>
519+
{
520+
Application.Current.MainWindow.Hide();
521+
_ = InstallOrUpdateAsync(plugin);
522+
523+
return ShouldHideWindow;
524+
}
525+
};
526+
return new List<Result> { result };
527+
}
528+
473529
private bool InstallSourceKnown(string url)
474530
{
475531
var author = url.Split('/')[3];
@@ -489,6 +545,9 @@ internal async ValueTask<List<Result>> RequestInstallOrUpdate(string search, Can
489545
&& search.Split('.').Last() == zip)
490546
return InstallFromWeb(search);
491547

548+
if (File.Exists(search) && search.Split('.').Last() == zip)
549+
return InstallFromLocal(search);
550+
492551
var results =
493552
PluginsManifest
494553
.UserPlugins

0 commit comments

Comments
 (0)