mirror of
https://github.com/Flow-Launcher/Flow.Launcher.git
synced 2026-03-11 08:54:32 +00:00
Add return value for api functions
This commit is contained in:
parent
a8bc55dcb5
commit
ce6c2cb1b2
5 changed files with 50 additions and 24 deletions
|
|
@ -74,7 +74,10 @@ public static class PluginInstaller
|
|||
throw new FileNotFoundException($"Plugin {newPlugin.ID} zip file not found at {filePath}", filePath);
|
||||
}
|
||||
|
||||
API.InstallPlugin(newPlugin, filePath);
|
||||
if (!API.InstallPlugin(newPlugin, filePath))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!newPlugin.IsFromLocalInstallPath)
|
||||
{
|
||||
|
|
@ -167,7 +170,10 @@ public static class PluginInstaller
|
|||
|
||||
try
|
||||
{
|
||||
await API.UninstallPluginAsync(oldPlugin, removePluginSettings);
|
||||
if (!await API.UninstallPluginAsync(oldPlugin, removePluginSettings))
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
|
@ -223,7 +229,10 @@ public static class PluginInstaller
|
|||
return;
|
||||
}
|
||||
|
||||
await API.UpdatePluginAsync(oldPlugin, newPlugin, filePath);
|
||||
if (!await API.UpdatePluginAsync(oldPlugin, newPlugin, filePath))
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -540,22 +540,24 @@ namespace Flow.Launcher.Core.Plugin
|
|||
return _modifiedPlugins.Contains(id);
|
||||
}
|
||||
|
||||
public static async Task UpdatePluginAsync(PluginMetadata existingVersion, UserPlugin newVersion, string zipFilePath)
|
||||
public static async Task<bool> UpdatePluginAsync(PluginMetadata existingVersion, UserPlugin newVersion, string zipFilePath)
|
||||
{
|
||||
var installSuccess = InstallPlugin(newVersion, zipFilePath, checkModified:false);
|
||||
if (!installSuccess) return;
|
||||
await UninstallPluginAsync(existingVersion, removePluginFromSettings:false, removePluginSettings:false, checkModified: false);
|
||||
if (!installSuccess) return false;
|
||||
var uninstallSuccess = await UninstallPluginAsync(existingVersion, removePluginFromSettings:false, removePluginSettings:false, checkModified: false);
|
||||
if (!uninstallSuccess) return false;
|
||||
_modifiedPlugins.Add(existingVersion.ID);
|
||||
return true;
|
||||
}
|
||||
|
||||
public static void InstallPlugin(UserPlugin plugin, string zipFilePath)
|
||||
public static bool InstallPlugin(UserPlugin plugin, string zipFilePath)
|
||||
{
|
||||
InstallPlugin(plugin, zipFilePath, checkModified: true);
|
||||
return InstallPlugin(plugin, zipFilePath, checkModified: true);
|
||||
}
|
||||
|
||||
public static async Task UninstallPluginAsync(PluginMetadata plugin, bool removePluginFromSettings = true, bool removePluginSettings = false)
|
||||
public static async Task<bool> UninstallPluginAsync(PluginMetadata plugin, bool removePluginFromSettings = true, bool removePluginSettings = false)
|
||||
{
|
||||
await UninstallPluginAsync(plugin, removePluginFromSettings, removePluginSettings, true);
|
||||
return await UninstallPluginAsync(plugin, removePluginFromSettings, removePluginSettings, true);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
|
|
|||
|
|
@ -547,8 +547,10 @@ namespace Flow.Launcher.Plugin
|
|||
/// <param name="zipFilePath">
|
||||
/// Path to the zip file containing the plugin. It will be unzipped to the temporary directory, removed and installed.
|
||||
/// </param>
|
||||
/// <returns></returns>
|
||||
public Task UpdatePluginAsync(PluginMetadata pluginMetadata, UserPlugin plugin, string zipFilePath);
|
||||
/// <returns>
|
||||
/// True if the plugin is updated successfully, false otherwise.
|
||||
/// </returns>
|
||||
public Task<bool> UpdatePluginAsync(PluginMetadata pluginMetadata, UserPlugin plugin, string zipFilePath);
|
||||
|
||||
/// <summary>
|
||||
/// Install a plugin. By default will remove the zip file if installation is from url,
|
||||
|
|
@ -558,7 +560,10 @@ namespace Flow.Launcher.Plugin
|
|||
/// <param name="zipFilePath">
|
||||
/// Path to the zip file containing the plugin. It will be unzipped to the temporary directory, removed and installed.
|
||||
/// </param>
|
||||
public void InstallPlugin(UserPlugin plugin, string zipFilePath);
|
||||
/// <returns>
|
||||
/// True if the plugin is installed successfully, false otherwise.
|
||||
/// </returns>
|
||||
public bool InstallPlugin(UserPlugin plugin, string zipFilePath);
|
||||
|
||||
/// <summary>
|
||||
/// Uninstall a plugin
|
||||
|
|
@ -567,8 +572,10 @@ namespace Flow.Launcher.Plugin
|
|||
/// <param name="removePluginSettings">
|
||||
/// Plugin has their own settings. If this is set to true, the plugin settings will be removed.
|
||||
/// </param>
|
||||
/// <returns></returns>
|
||||
public Task UninstallPluginAsync(PluginMetadata pluginMetadata, bool removePluginSettings = false);
|
||||
/// <returns>
|
||||
/// True if the plugin is updated successfully, false otherwise.
|
||||
/// </returns>
|
||||
public Task<bool> UninstallPluginAsync(PluginMetadata pluginMetadata, bool removePluginSettings = false);
|
||||
|
||||
/// <summary>
|
||||
/// Log debug message of the time taken to execute a method
|
||||
|
|
|
|||
|
|
@ -566,13 +566,13 @@ namespace Flow.Launcher
|
|||
|
||||
public bool PluginModified(string id) => PluginManager.PluginModified(id);
|
||||
|
||||
public Task UpdatePluginAsync(PluginMetadata pluginMetadata, UserPlugin plugin, string zipFilePath) =>
|
||||
public Task<bool> UpdatePluginAsync(PluginMetadata pluginMetadata, UserPlugin plugin, string zipFilePath) =>
|
||||
PluginManager.UpdatePluginAsync(pluginMetadata, plugin, zipFilePath);
|
||||
|
||||
public void InstallPlugin(UserPlugin plugin, string zipFilePath) =>
|
||||
public bool InstallPlugin(UserPlugin plugin, string zipFilePath) =>
|
||||
PluginManager.InstallPlugin(plugin, zipFilePath);
|
||||
|
||||
public Task UninstallPluginAsync(PluginMetadata pluginMetadata, bool removePluginSettings = false) =>
|
||||
public Task<bool> UninstallPluginAsync(PluginMetadata pluginMetadata, bool removePluginSettings = false) =>
|
||||
PluginManager.UninstallPluginAsync(pluginMetadata, removePluginSettings);
|
||||
|
||||
public long StopwatchLogDebug(string className, string message, Action action, [CallerMemberName] string methodName = "") =>
|
||||
|
|
|
|||
|
|
@ -352,8 +352,11 @@ namespace Flow.Launcher.Plugin.PluginsManager
|
|||
}
|
||||
else
|
||||
{
|
||||
await Context.API.UpdatePluginAsync(x.PluginExistingMetadata, x.PluginNewUserPlugin,
|
||||
downloadToFilePath);
|
||||
if (!await Context.API.UpdatePluginAsync(x.PluginExistingMetadata, x.PluginNewUserPlugin,
|
||||
downloadToFilePath))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (Settings.AutoRestartAfterChanging)
|
||||
{
|
||||
|
|
@ -456,8 +459,9 @@ namespace Flow.Launcher.Plugin.PluginsManager
|
|||
if (cts.IsCancellationRequested)
|
||||
return;
|
||||
else
|
||||
await Context.API.UpdatePluginAsync(plugin.PluginExistingMetadata, plugin.PluginNewUserPlugin,
|
||||
downloadToFilePath);
|
||||
if (!await Context.API.UpdatePluginAsync(plugin.PluginExistingMetadata, plugin.PluginNewUserPlugin,
|
||||
downloadToFilePath))
|
||||
return;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
|
@ -686,7 +690,8 @@ namespace Flow.Launcher.Plugin.PluginsManager
|
|||
|
||||
try
|
||||
{
|
||||
Context.API.InstallPlugin(plugin, downloadedFilePath);
|
||||
if (!Context.API.InstallPlugin(plugin, downloadedFilePath))
|
||||
return;
|
||||
|
||||
if (!plugin.IsFromLocalInstallPath)
|
||||
File.Delete(downloadedFilePath);
|
||||
|
|
@ -779,7 +784,10 @@ namespace Flow.Launcher.Plugin.PluginsManager
|
|||
Context.API.GetTranslation("plugin_pluginsmanager_keep_plugin_settings_subtitle"),
|
||||
Context.API.GetTranslation("plugin_pluginsmanager_keep_plugin_settings_title"),
|
||||
button: MessageBoxButton.YesNo) == MessageBoxResult.No;
|
||||
await Context.API.UninstallPluginAsync(plugin, removePluginSettings);
|
||||
if (!await Context.API.UninstallPluginAsync(plugin, removePluginSettings))
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
catch (ArgumentException e)
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in a new issue