Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Flow.Launcher.Core/ExternalPlugins/PluginsManifest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public static Task UpdateManifestAsync()
return UpdateTask = DownloadManifestAsync();
}

private async static Task DownloadManifestAsync()
private static async Task DownloadManifestAsync()
{
try
{
Expand Down
7 changes: 4 additions & 3 deletions Flow.Launcher.Core/Updater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,9 @@ public async Task UpdateAppAsync(IPublicAPI api, bool silentUpdate = true)
catch (Exception e) when (e is HttpRequestException or WebException or SocketException || e.InnerException is TimeoutException)
{
Log.Exception($"|Updater.UpdateApp|Check your connection and proxy settings to github-cloud.s3.amazonaws.com.", e);
api.ShowMsg(api.GetTranslation("update_flowlauncher_fail"),
api.GetTranslation("update_flowlauncher_check_connection"));
if (!silentUpdate)
api.ShowMsg(api.GetTranslation("update_flowlauncher_fail"),
api.GetTranslation("update_flowlauncher_check_connection"));
}
finally
{
Expand Down Expand Up @@ -124,7 +125,7 @@ private async Task<UpdateManager> GitHubUpdateManager(string repository)
var releases = await System.Text.Json.JsonSerializer.DeserializeAsync<List<GithubRelease>>(jsonStream).ConfigureAwait(false);
var latest = releases.Where(r => !r.Prerelease).OrderByDescending(r => r.PublishedAt).First();
var latestUrl = latest.HtmlUrl.Replace("/tag/", "/download/");

var client = new WebClient
{
Proxy = Http.WebProxy
Expand Down
20 changes: 11 additions & 9 deletions Plugins/Flow.Launcher.Plugin.PluginsManager/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,12 @@ public Task InitAsync(PluginInitContext context)
viewModel = new SettingsViewModel(context, Settings);
contextMenu = new ContextMenu(Context);
pluginManager = new PluginsManager(Context, Settings);
_manifestUpdateTask = pluginManager.UpdateManifestAsync().ContinueWith(_ =>
{
lastUpdateTime = DateTime.Now;
}, TaskContinuationOptions.OnlyOnRanToCompletion);
_manifestUpdateTask = pluginManager
.UpdateManifestAsync(true)
.ContinueWith(_ =>
{
lastUpdateTime = DateTime.Now;
}, TaskContinuationOptions.OnlyOnRanToCompletion);

return Task.CompletedTask;
}
Expand All @@ -50,7 +52,7 @@ public List<Result> LoadContextMenus(Result selectedResult)
{
return contextMenu.LoadContextMenus(selectedResult);
}

private Task _manifestUpdateTask = Task.CompletedTask;

public async Task<List<Result>> QueryAsync(Query query, CancellationToken token)
Expand All @@ -72,11 +74,11 @@ public async Task<List<Result>> QueryAsync(Query query, CancellationToken token)
{
//search could be url, no need ToLower() when passed in
var s when s.StartsWith(Settings.HotKeyInstall, StringComparison.OrdinalIgnoreCase)
=> await pluginManager.RequestInstallOrUpdate(search, token),
=> await pluginManager.RequestInstallOrUpdate(search, token),
var s when s.StartsWith(Settings.HotkeyUninstall, StringComparison.OrdinalIgnoreCase)
=> pluginManager.RequestUninstall(search),
var s when s.StartsWith(Settings.HotkeyUpdate, StringComparison.OrdinalIgnoreCase)
=> await pluginManager.RequestUpdate(search, token),
=> pluginManager.RequestUninstall(search),
var s when s.StartsWith(Settings.HotkeyUpdate, StringComparison.OrdinalIgnoreCase)
=> await pluginManager.RequestUpdate(search, token),
_ => pluginManager.GetDefaultHotKeys().Where(hotkey =>
{
hotkey.Score = StringMatcher.FuzzySearch(search, hotkey.Title).Score;
Expand Down
73 changes: 38 additions & 35 deletions Plugins/Flow.Launcher.Plugin.PluginsManager/PluginsManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ internal PluginsManager(PluginInitContext context, Settings settings)

private Task _downloadManifestTask = Task.CompletedTask;

internal Task UpdateManifestAsync()
internal Task UpdateManifestAsync(bool silent = false)
{
if (_downloadManifestTask.Status == TaskStatus.Running)
{
Expand All @@ -60,10 +60,11 @@ internal Task UpdateManifestAsync()
else
{
_downloadManifestTask = PluginsManifest.UpdateTask;
_downloadManifestTask.ContinueWith(_ =>
Context.API.ShowMsg(Context.API.GetTranslation("plugin_pluginsmanager_update_failed_title"),
Context.API.GetTranslation("plugin_pluginsmanager_update_failed_subtitle"), icoPath, false),
TaskContinuationOptions.OnlyOnFaulted);
if (!silent)
_downloadManifestTask.ContinueWith(_ =>
Context.API.ShowMsg(Context.API.GetTranslation("plugin_pluginsmanager_update_failed_title"),
Context.API.GetTranslation("plugin_pluginsmanager_update_failed_subtitle"), icoPath, false),
TaskContinuationOptions.OnlyOnFaulted);
return _downloadManifestTask;
}
}
Expand Down Expand Up @@ -113,8 +114,8 @@ internal async Task InstallOrUpdate(UserPlugin plugin)
.Any(x => x.Metadata.ID == plugin.ID && x.Metadata.Version.CompareTo(plugin.Version) < 0))
{
if (MessageBox.Show(Context.API.GetTranslation("plugin_pluginsmanager_update_exists"),
Context.API.GetTranslation("plugin_pluginsmanager_update_title"),
MessageBoxButton.YesNo) == MessageBoxResult.Yes)
Context.API.GetTranslation("plugin_pluginsmanager_update_title"),
MessageBoxButton.YesNo) == MessageBoxResult.Yes)
Context
.API
.ChangeQuery(
Expand All @@ -138,13 +139,13 @@ internal async Task InstallOrUpdate(UserPlugin plugin)
Environment.NewLine, Environment.NewLine);

if (MessageBox.Show(message, Context.API.GetTranslation("plugin_pluginsmanager_install_title"),
MessageBoxButton.YesNo) == MessageBoxResult.No)
MessageBoxButton.YesNo) == MessageBoxResult.No)
return;

// at minimum should provide a name, but handle plugin that is not downloaded from plugins manifest and is a url download
var downloadFilename = string.IsNullOrEmpty(plugin.Version)
? $"{plugin.Name}-{Guid.NewGuid()}.zip"
: $"{plugin.Name}-{plugin.Version}.zip";
? $"{plugin.Name}-{Guid.NewGuid()}.zip"
: $"{plugin.Name}-{plugin.Version}.zip";

var filePath = Path.Combine(DataLocation.PluginsDirectory, downloadFilename);

Expand All @@ -161,7 +162,7 @@ internal async Task InstallOrUpdate(UserPlugin plugin)
{
if (e is HttpRequestException)
MessageBox.Show(Context.API.GetTranslation("plugin_pluginsmanager_download_error"),
Context.API.GetTranslation("plugin_pluginsmanager_downloading_plugin"));
Context.API.GetTranslation("plugin_pluginsmanager_downloading_plugin"));

Context.API.ShowMsgError(Context.API.GetTranslation("plugin_pluginsmanager_install_error_title"),
string.Format(Context.API.GetTranslation("plugin_pluginsmanager_install_error_subtitle"),
Expand All @@ -173,7 +174,7 @@ internal async Task InstallOrUpdate(UserPlugin plugin)
}

Context.API.ShowMsg(Context.API.GetTranslation("plugin_pluginsmanager_install_title"),
Context.API.GetTranslation("plugin_pluginsmanager_install_success_restart"));
Context.API.GetTranslation("plugin_pluginsmanager_install_success_restart"));

Context.API.RestartApp();
}
Expand Down Expand Up @@ -241,8 +242,8 @@ where existingPlugin.Metadata.Version.CompareTo(pluginFromManifest.Version) <
Environment.NewLine, Environment.NewLine);

if (MessageBox.Show(message,
Context.API.GetTranslation("plugin_pluginsmanager_update_title"),
MessageBoxButton.YesNo) == MessageBoxResult.Yes)
Context.API.GetTranslation("plugin_pluginsmanager_update_title"),
MessageBoxButton.YesNo) == MessageBoxResult.Yes)
{
Uninstall(x.PluginExistingMetadata, false);

Expand Down Expand Up @@ -277,11 +278,10 @@ await Http.DownloadAsync(x.PluginNewUserPlugin.UrlDownload, downloadToFilePath)

return false;
},
ContextData =
ContextData =
new UserPlugin
{
Website = x.PluginNewUserPlugin.Website,
UrlSourceCode = x.PluginNewUserPlugin.UrlSourceCode
Website = x.PluginNewUserPlugin.Website, UrlSourceCode = x.PluginNewUserPlugin.UrlSourceCode
}
});

Expand Down Expand Up @@ -340,21 +340,24 @@ internal List<Result> InstallFromWeb(string url)
if (Settings.WarnFromUnknownSource)
{
if (!InstallSourceKnown(plugin.UrlDownload)
&& MessageBox.Show(string.Format(Context.API.GetTranslation("plugin_pluginsmanager_install_unknown_source_warning"),
Environment.NewLine),
Context.API.GetTranslation("plugin_pluginsmanager_install_unknown_source_warning_title"),
MessageBoxButton.YesNo) == MessageBoxResult.No)
&& MessageBox.Show(string.Format(Context.API.GetTranslation("plugin_pluginsmanager_install_unknown_source_warning"),
Environment.NewLine),
Context.API.GetTranslation("plugin_pluginsmanager_install_unknown_source_warning_title"),
MessageBoxButton.YesNo) == MessageBoxResult.No)
return false;
}

Application.Current.MainWindow.Hide();
_ = InstallOrUpdate(plugin);

return ShouldHideWindow;
}
};

return new List<Result> { result };
return new List<Result>
{
result
};
}

private bool InstallSourceKnown(string url)
Expand All @@ -377,7 +380,7 @@ internal async ValueTask<List<Result>> RequestInstallOrUpdate(string searchName,

var searchNameWithoutKeyword = searchName.Replace(Settings.HotKeyInstall, string.Empty, StringComparison.OrdinalIgnoreCase).Trim();

if (Uri.IsWellFormedUriString(searchNameWithoutKeyword, UriKind.Absolute)
if (Uri.IsWellFormedUriString(searchNameWithoutKeyword, UriKind.Absolute)
&& searchNameWithoutKeyword.Split('.').Last() == zip)
return InstallFromWeb(searchNameWithoutKeyword);

Expand Down Expand Up @@ -438,21 +441,21 @@ private void Install(UserPlugin plugin, string downloadedFilePath)
if (string.IsNullOrEmpty(metadataJsonFilePath) || string.IsNullOrEmpty(pluginFolderPath))
{
MessageBox.Show(Context.API.GetTranslation("plugin_pluginsmanager_install_errormetadatafile"),
Context.API.GetTranslation("plugin_pluginsmanager_install_error_title"));
throw new FileNotFoundException (
Context.API.GetTranslation("plugin_pluginsmanager_install_error_title"));

throw new FileNotFoundException(
string.Format("Unable to find plugin.json from the extracted zip file, or this path {0} does not exist", pluginFolderPath));
}

if (SameOrLesserPluginVersionExists(metadataJsonFilePath))
{
MessageBox.Show(string.Format(Context.API.GetTranslation("plugin_pluginsmanager_install_error_duplicate"), plugin.Name),
Context.API.GetTranslation("plugin_pluginsmanager_install_error_title"));
Context.API.GetTranslation("plugin_pluginsmanager_install_error_title"));

throw new InvalidOperationException(
string.Format("A plugin with the same ID and version already exists, " +
"or the version is greater than this downloaded plugin {0}",
plugin.Name));
"or the version is greater than this downloaded plugin {0}",
plugin.Name));
}

var directory = string.IsNullOrEmpty(plugin.Version) ? $"{plugin.Name}-{Guid.NewGuid()}" : $"{plugin.Name}-{plugin.Version}";
Expand Down Expand Up @@ -491,8 +494,8 @@ internal List<Result> RequestUninstall(string search)
Environment.NewLine, Environment.NewLine);

if (MessageBox.Show(message,
Context.API.GetTranslation("plugin_pluginsmanager_uninstall_title"),
MessageBoxButton.YesNo) == MessageBoxResult.Yes)
Context.API.GetTranslation("plugin_pluginsmanager_uninstall_title"),
MessageBoxButton.YesNo) == MessageBoxResult.Yes)
{
Application.Current.MainWindow.Hide();
Uninstall(x.Metadata);
Expand Down Expand Up @@ -554,8 +557,8 @@ private bool SameOrLesserPluginVersionExists(string metadataPath)
{
var newMetadata = JsonSerializer.Deserialize<PluginMetadata>(File.ReadAllText(metadataPath));
return Context.API.GetAllPlugins()
.Any(x => x.Metadata.ID == newMetadata.ID
&& newMetadata.Version.CompareTo(x.Metadata.Version) <= 0);
.Any(x => x.Metadata.ID == newMetadata.ID
&& newMetadata.Version.CompareTo(x.Metadata.Version) <= 0);
}
}
}
}