mirror of
https://github.com/Flow-Launcher/Flow.Launcher.git
synced 2026-03-11 08:54:32 +00:00
Merge branch 'dev' into versionbump_plugin
This commit is contained in:
commit
72e40dee1f
3 changed files with 69 additions and 37 deletions
|
|
@ -37,8 +37,17 @@ namespace Flow.Launcher.Plugin.PluginsManager
|
||||||
Settings = viewModel.Settings;
|
Settings = viewModel.Settings;
|
||||||
contextMenu = new ContextMenu(Context);
|
contextMenu = new ContextMenu(Context);
|
||||||
pluginManager = new PluginsManager(Context, Settings);
|
pluginManager = new PluginsManager(Context, Settings);
|
||||||
await pluginManager.UpdateManifest();
|
var updateManifestTask = pluginManager.UpdateManifest();
|
||||||
lastUpdateTime = DateTime.Now;
|
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)
|
public List<Result> LoadContextMenus(Result selectedResult)
|
||||||
|
|
@ -61,7 +70,7 @@ namespace Flow.Launcher.Plugin.PluginsManager
|
||||||
|
|
||||||
return search switch
|
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.HotkeyUninstall) => pluginManager.RequestUninstall(s),
|
||||||
var s when s.StartsWith(Settings.HotkeyUpdate) => pluginManager.RequestUpdate(s),
|
var s when s.StartsWith(Settings.HotkeyUpdate) => pluginManager.RequestUpdate(s),
|
||||||
_ => pluginManager.GetDefaultHotKeys().Where(hotkey =>
|
_ => pluginManager.GetDefaultHotKeys().Where(hotkey =>
|
||||||
|
|
@ -93,4 +102,4 @@ namespace Flow.Launcher.Plugin.PluginsManager
|
||||||
lastUpdateTime = DateTime.Now;
|
lastUpdateTime = DateTime.Now;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -7,6 +7,7 @@ using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.Windows;
|
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)
|
internal PluginsManager(PluginInitContext context, Settings settings)
|
||||||
{
|
{
|
||||||
|
|
@ -64,27 +65,27 @@ namespace Flow.Launcher.Plugin.PluginsManager
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
new Result()
|
new Result()
|
||||||
|
{
|
||||||
|
Title = Settings.HotkeyUninstall,
|
||||||
|
IcoPath = icoPath,
|
||||||
|
Action = _ =>
|
||||||
{
|
{
|
||||||
Title = Settings.HotkeyUninstall,
|
Context.API.ChangeQuery("pm uninstall ");
|
||||||
IcoPath = icoPath,
|
return false;
|
||||||
Action = _ =>
|
|
||||||
{
|
|
||||||
Context.API.ChangeQuery("pm uninstall ");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
new Result()
|
|
||||||
{
|
|
||||||
Title = Settings.HotkeyUpdate,
|
|
||||||
IcoPath = icoPath,
|
|
||||||
Action = _ =>
|
|
||||||
{
|
|
||||||
Context.API.ChangeQuery("pm update ");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
},
|
||||||
|
new Result()
|
||||||
|
{
|
||||||
|
Title = Settings.HotkeyUpdate,
|
||||||
|
IcoPath = icoPath,
|
||||||
|
Action = _ =>
|
||||||
|
{
|
||||||
|
Context.API.ChangeQuery("pm update ");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
internal async Task InstallOrUpdate(UserPlugin plugin)
|
internal async Task InstallOrUpdate(UserPlugin plugin)
|
||||||
|
|
@ -137,7 +138,8 @@ namespace Flow.Launcher.Plugin.PluginsManager
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
Context.API.ShowMsg(Context.API.GetTranslation("plugin_pluginsmanager_install_error_title"),
|
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");
|
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()
|
from existingPlugin in Context.API.GetAllPlugins()
|
||||||
join pluginFromManifest in pluginsManifest.UserPlugins
|
join pluginFromManifest in pluginsManifest.UserPlugins
|
||||||
on existingPlugin.Metadata.ID equals pluginFromManifest.ID
|
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
|
select
|
||||||
new
|
new
|
||||||
{
|
{
|
||||||
|
|
@ -214,22 +217,29 @@ namespace Flow.Launcher.Plugin.PluginsManager
|
||||||
|
|
||||||
Task.Run(async delegate
|
Task.Run(async delegate
|
||||||
{
|
{
|
||||||
Context.API.ShowMsg(Context.API.GetTranslation("plugin_pluginsmanager_downloading_plugin"),
|
Context.API.ShowMsg(
|
||||||
Context.API.GetTranslation("plugin_pluginsmanager_please_wait"));
|
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.ShowMsg(
|
||||||
Context.API.GetTranslation("plugin_pluginsmanager_download_success"));
|
Context.API.GetTranslation("plugin_pluginsmanager_downloading_plugin"),
|
||||||
|
Context.API.GetTranslation("plugin_pluginsmanager_download_success"));
|
||||||
|
|
||||||
Install(x.PluginNewUserPlugin, downloadToFilePath);
|
Install(x.PluginNewUserPlugin, downloadToFilePath);
|
||||||
|
|
||||||
Context.API.RestartApp();
|
Context.API.RestartApp();
|
||||||
}).ContinueWith(t =>
|
}).ContinueWith(t =>
|
||||||
{
|
{
|
||||||
Log.Exception("PluginsManager", $"Update failed for {x.Name}", t.Exception.InnerException, "RequestUpdate");
|
Log.Exception("PluginsManager", $"Update failed for {x.Name}",
|
||||||
Context.API.ShowMsg(Context.API.GetTranslation("plugin_pluginsmanager_install_error_title"),
|
t.Exception.InnerException, "RequestUpdate");
|
||||||
string.Format(Context.API.GetTranslation("plugin_pluginsmanager_install_error_subtitle"), x.Name));
|
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);
|
}, TaskContinuationOptions.OnlyOnFaulted);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
@ -264,8 +274,21 @@ namespace Flow.Launcher.Plugin.PluginsManager
|
||||||
.ToList();
|
.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 searchNameWithoutKeyword = searchName.Replace(Settings.HotKeyInstall, string.Empty).Trim();
|
||||||
|
|
||||||
var results =
|
var results =
|
||||||
|
|
@ -406,4 +429,4 @@ namespace Flow.Launcher.Plugin.PluginsManager
|
||||||
return new List<Result>();
|
return new List<Result>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
"Name": "Plugins Manager",
|
"Name": "Plugins Manager",
|
||||||
"Description": "Management of installing, uninstalling or updating Flow Launcher plugins",
|
"Description": "Management of installing, uninstalling or updating Flow Launcher plugins",
|
||||||
"Author": "Jeremy Wu",
|
"Author": "Jeremy Wu",
|
||||||
"Version": "1.5.0",
|
"Version": "1.5.1",
|
||||||
"Language": "csharp",
|
"Language": "csharp",
|
||||||
"Website": "https://github.com/Flow-Launcher/Flow.Launcher",
|
"Website": "https://github.com/Flow-Launcher/Flow.Launcher",
|
||||||
"ExecuteFileName": "Flow.Launcher.Plugin.PluginsManager.dll",
|
"ExecuteFileName": "Flow.Launcher.Plugin.PluginsManager.dll",
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue