Merge branch 'dev' into versionbump_plugin

This commit is contained in:
Jeremy Wu 2021-01-18 07:57:56 +11:00
commit 72e40dee1f
3 changed files with 69 additions and 37 deletions

View file

@ -37,8 +37,17 @@ namespace Flow.Launcher.Plugin.PluginsManager
Settings = viewModel.Settings;
contextMenu = new ContextMenu(Context);
pluginManager = new PluginsManager(Context, Settings);
await pluginManager.UpdateManifest();
lastUpdateTime = DateTime.Now;
var updateManifestTask = pluginManager.UpdateManifest();
if (await Task.WhenAny(updateManifestTask, Task.Delay(500)) == updateManifestTask)
{
lastUpdateTime = DateTime.Now;
}
else
{
context.API.ShowMsg("Plugin Manifest Download Fail.",
@"Please check internet transmission with Github.com.
You may not be able to Install and Update Plugin.", pluginManager.icoPath);
}
}
public List<Result> LoadContextMenus(Result selectedResult)
@ -61,7 +70,7 @@ namespace Flow.Launcher.Plugin.PluginsManager
return search switch
{
var s when s.StartsWith(Settings.HotKeyInstall) => pluginManager.RequestInstallOrUpdate(s),
var s when s.StartsWith(Settings.HotKeyInstall) => await pluginManager.RequestInstallOrUpdate(s, token),
var s when s.StartsWith(Settings.HotkeyUninstall) => pluginManager.RequestUninstall(s),
var s when s.StartsWith(Settings.HotkeyUpdate) => pluginManager.RequestUpdate(s),
_ => pluginManager.GetDefaultHotKeys().Where(hotkey =>
@ -93,4 +102,4 @@ namespace Flow.Launcher.Plugin.PluginsManager
lastUpdateTime = DateTime.Now;
}
}
}
}

View file

@ -7,6 +7,7 @@ using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
@ -36,7 +37,7 @@ namespace Flow.Launcher.Plugin.PluginsManager
}
}
private readonly string icoPath = "Images\\pluginsmanager.png";
internal readonly string icoPath = "Images\\pluginsmanager.png";
internal PluginsManager(PluginInitContext context, Settings settings)
{
@ -64,27 +65,27 @@ namespace Flow.Launcher.Plugin.PluginsManager
return false;
}
},
new Result()
new Result()
{
Title = Settings.HotkeyUninstall,
IcoPath = icoPath,
Action = _ =>
{
Title = Settings.HotkeyUninstall,
IcoPath = icoPath,
Action = _ =>
{
Context.API.ChangeQuery("pm uninstall ");
return false;
}
},
new Result()
{
Title = Settings.HotkeyUpdate,
IcoPath = icoPath,
Action = _ =>
{
Context.API.ChangeQuery("pm update ");
return false;
}
Context.API.ChangeQuery("pm uninstall ");
return false;
}
};
},
new Result()
{
Title = Settings.HotkeyUpdate,
IcoPath = icoPath,
Action = _ =>
{
Context.API.ChangeQuery("pm update ");
return false;
}
}
};
}
internal async Task InstallOrUpdate(UserPlugin plugin)
@ -137,7 +138,8 @@ namespace Flow.Launcher.Plugin.PluginsManager
catch (Exception e)
{
Context.API.ShowMsg(Context.API.GetTranslation("plugin_pluginsmanager_install_error_title"),
string.Format(Context.API.GetTranslation("plugin_pluginsmanager_install_error_subtitle"), plugin.Name));
string.Format(Context.API.GetTranslation("plugin_pluginsmanager_install_error_subtitle"),
plugin.Name));
Log.Exception("PluginsManager", "An error occured while downloading plugin", e, "InstallOrUpdate");
@ -164,7 +166,8 @@ namespace Flow.Launcher.Plugin.PluginsManager
from existingPlugin in Context.API.GetAllPlugins()
join pluginFromManifest in pluginsManifest.UserPlugins
on existingPlugin.Metadata.ID equals pluginFromManifest.ID
where existingPlugin.Metadata.Version.CompareTo(pluginFromManifest.Version) < 0 // if current version precedes manifest version
where existingPlugin.Metadata.Version.CompareTo(pluginFromManifest.Version) <
0 // if current version precedes manifest version
select
new
{
@ -214,22 +217,29 @@ namespace Flow.Launcher.Plugin.PluginsManager
Task.Run(async delegate
{
Context.API.ShowMsg(Context.API.GetTranslation("plugin_pluginsmanager_downloading_plugin"),
Context.API.GetTranslation("plugin_pluginsmanager_please_wait"));
Context.API.ShowMsg(
Context.API.GetTranslation("plugin_pluginsmanager_downloading_plugin"),
Context.API.GetTranslation("plugin_pluginsmanager_please_wait"));
await Http.DownloadAsync(x.PluginNewUserPlugin.UrlDownload, downloadToFilePath).ConfigureAwait(false);
await Http.DownloadAsync(x.PluginNewUserPlugin.UrlDownload, downloadToFilePath)
.ConfigureAwait(false);
Context.API.ShowMsg(Context.API.GetTranslation("plugin_pluginsmanager_downloading_plugin"),
Context.API.GetTranslation("plugin_pluginsmanager_download_success"));
Context.API.ShowMsg(
Context.API.GetTranslation("plugin_pluginsmanager_downloading_plugin"),
Context.API.GetTranslation("plugin_pluginsmanager_download_success"));
Install(x.PluginNewUserPlugin, downloadToFilePath);
Context.API.RestartApp();
}).ContinueWith(t =>
{
Log.Exception("PluginsManager", $"Update failed for {x.Name}", t.Exception.InnerException, "RequestUpdate");
Context.API.ShowMsg(Context.API.GetTranslation("plugin_pluginsmanager_install_error_title"),
string.Format(Context.API.GetTranslation("plugin_pluginsmanager_install_error_subtitle"), x.Name));
Log.Exception("PluginsManager", $"Update failed for {x.Name}",
t.Exception.InnerException, "RequestUpdate");
Context.API.ShowMsg(
Context.API.GetTranslation("plugin_pluginsmanager_install_error_title"),
string.Format(
Context.API.GetTranslation("plugin_pluginsmanager_install_error_subtitle"),
x.Name));
}, TaskContinuationOptions.OnlyOnFaulted);
return true;
@ -264,8 +274,21 @@ namespace Flow.Launcher.Plugin.PluginsManager
.ToList();
}
internal List<Result> RequestInstallOrUpdate(string searchName)
private Task _downloadManifestTask = Task.CompletedTask;
internal async ValueTask<List<Result>> RequestInstallOrUpdate(string searchName, CancellationToken token)
{
if (!pluginsManifest.UserPlugins.Any() &&
_downloadManifestTask.Status != TaskStatus.Running)
{
_downloadManifestTask = pluginsManifest.DownloadManifest();
}
await _downloadManifestTask;
if (token.IsCancellationRequested)
return null;
var searchNameWithoutKeyword = searchName.Replace(Settings.HotKeyInstall, string.Empty).Trim();
var results =
@ -406,4 +429,4 @@ namespace Flow.Launcher.Plugin.PluginsManager
return new List<Result>();
}
}
}
}

View file

@ -6,7 +6,7 @@
"Name": "Plugins Manager",
"Description": "Management of installing, uninstalling or updating Flow Launcher plugins",
"Author": "Jeremy Wu",
"Version": "1.5.0",
"Version": "1.5.1",
"Language": "csharp",
"Website": "https://github.com/Flow-Launcher/Flow.Launcher",
"ExecuteFileName": "Flow.Launcher.Plugin.PluginsManager.dll",