Skip to content

Commit 4744ff7

Browse files
committed
Move PluginManager public function to api
1 parent 55d1754 commit 4744ff7

File tree

5 files changed

+87
-49
lines changed

5 files changed

+87
-49
lines changed

Flow.Launcher.Core/Plugin/PluginManager.cs

Lines changed: 16 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -454,34 +454,23 @@ private static bool SameOrLesserPluginVersionExists(string metadataPath)
454454

455455
#region Public functions
456456

457-
public static bool PluginModified(string uuid)
457+
public static bool PluginModified(string id)
458458
{
459-
return _modifiedPlugins.Contains(uuid);
459+
return _modifiedPlugins.Contains(id);
460460
}
461461

462-
463-
/// <summary>
464-
/// Update a plugin to new version, from a zip file. By default will remove the zip file if update is via url,
465-
/// unless it's a local path installation
466-
/// </summary>
467462
public static async Task UpdatePluginAsync(PluginMetadata existingVersion, UserPlugin newVersion, string zipFilePath)
468463
{
469464
InstallPlugin(newVersion, zipFilePath, checkModified:false);
470465
await UninstallPluginAsync(existingVersion, removePluginFromSettings:false, removePluginSettings:false, checkModified: false);
471466
_modifiedPlugins.Add(existingVersion.ID);
472467
}
473468

474-
/// <summary>
475-
/// Install a plugin. By default will remove the zip file if installation is from url, unless it's a local path installation
476-
/// </summary>
477469
public static void InstallPlugin(UserPlugin plugin, string zipFilePath)
478470
{
479471
InstallPlugin(plugin, zipFilePath, checkModified: true);
480472
}
481473

482-
/// <summary>
483-
/// Uninstall a plugin.
484-
/// </summary>
485474
public static async Task UninstallPluginAsync(PluginMetadata plugin, bool removePluginFromSettings = true, bool removePluginSettings = false)
486475
{
487476
await UninstallPluginAsync(plugin, removePluginFromSettings, removePluginSettings, true);
@@ -525,20 +514,20 @@ internal static void InstallPlugin(UserPlugin plugin, string zipFilePath, bool c
525514
var folderName = string.IsNullOrEmpty(plugin.Version) ? $"{plugin.Name}-{Guid.NewGuid()}" : $"{plugin.Name}-{plugin.Version}";
526515

527516
var defaultPluginIDs = new List<string>
528-
{
529-
"0ECADE17459B49F587BF81DC3A125110", // BrowserBookmark
530-
"CEA0FDFC6D3B4085823D60DC76F28855", // Calculator
531-
"572be03c74c642baae319fc283e561a8", // Explorer
532-
"6A122269676E40EB86EB543B945932B9", // PluginIndicator
533-
"9f8f9b14-2518-4907-b211-35ab6290dee7", // PluginsManager
534-
"b64d0a79-329a-48b0-b53f-d658318a1bf6", // ProcessKiller
535-
"791FC278BA414111B8D1886DFE447410", // Program
536-
"D409510CD0D2481F853690A07E6DC426", // Shell
537-
"CEA08895D2544B019B2E9C5009600DF4", // Sys
538-
"0308FD86DE0A4DEE8D62B9B535370992", // URL
539-
"565B73353DBF4806919830B9202EE3BF", // WebSearch
540-
"5043CETYU6A748679OPA02D27D99677A" // WindowsSettings
541-
};
517+
{
518+
"0ECADE17459B49F587BF81DC3A125110", // BrowserBookmark
519+
"CEA0FDFC6D3B4085823D60DC76F28855", // Calculator
520+
"572be03c74c642baae319fc283e561a8", // Explorer
521+
"6A122269676E40EB86EB543B945932B9", // PluginIndicator
522+
"9f8f9b14-2518-4907-b211-35ab6290dee7", // PluginsManager
523+
"b64d0a79-329a-48b0-b53f-d658318a1bf6", // ProcessKiller
524+
"791FC278BA414111B8D1886DFE447410", // Program
525+
"D409510CD0D2481F853690A07E6DC426", // Shell
526+
"CEA08895D2544B019B2E9C5009600DF4", // Sys
527+
"0308FD86DE0A4DEE8D62B9B535370992", // URL
528+
"565B73353DBF4806919830B9202EE3BF", // WebSearch
529+
"5043CETYU6A748679OPA02D27D99677A" // WindowsSettings
530+
};
542531

543532
// Treat default plugin differently, it needs to be removable along with each flow release
544533
var installDirectory = !defaultPluginIDs.Any(x => x == plugin.ID)

Flow.Launcher.Plugin/Interfaces/IPublicAPI.cs

Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -352,15 +352,54 @@ public interface IPublicAPI
352352
/// FL has multiple urls to download the plugin manifest. Set this to true to only use the primary url.
353353
/// </param>
354354
/// <param name="token"></param>
355-
/// <returns>
356-
/// True if the manifest is updated successfully, false otherwise.
357-
/// </returns>
355+
/// <returns>True if the manifest is updated successfully, false otherwise</returns>
358356
public Task<bool> UpdatePluginManifestAsync(bool usePrimaryUrlOnly = false, CancellationToken token = default);
359357

360358
/// <summary>
361359
/// Get the plugin manifest
362360
/// </summary>
363361
/// <returns></returns>
364-
public IReadOnlyList<UserPlugin> GetUserPlugins();
362+
public IReadOnlyList<UserPlugin> GetPluginManifest();
363+
364+
/// <summary>
365+
/// Check if the plugin has been modified.
366+
/// If this plugin is updated, installed or uninstalled and users do not restart the app,
367+
/// it will be marked as modified
368+
/// </summary>
369+
/// <param name="id">Plugin id</param>
370+
/// <returns></returns>
371+
public bool PluginModified(string id);
372+
373+
/// <summary>
374+
/// Update a plugin to new version, from a zip file. By default will remove the zip file if update is via url,
375+
/// unless it's a local path installation
376+
/// </summary>
377+
/// <param name="pluginMetadata">The metadata of the old plugin to update</param>
378+
/// <param name="plugin">The new plugin to update</param>
379+
/// <param name="zipFilePath">
380+
/// Path to the zip file containing the plugin. It will be unzipped to the temporary directory, removed and installed.
381+
/// </param>
382+
/// <returns></returns>
383+
public Task UpdatePluginAsync(PluginMetadata pluginMetadata, UserPlugin plugin, string zipFilePath);
384+
385+
/// <summary>
386+
/// Install a plugin. By default will remove the zip file if installation is from url,
387+
/// unless it's a local path installation
388+
/// </summary>
389+
/// <param name="plugin">The plugin to install</param>
390+
/// <param name="zipFilePath">
391+
/// Path to the zip file containing the plugin. It will be unzipped to the temporary directory, removed and installed.
392+
/// </param>
393+
public void InstallPlugin(UserPlugin plugin, string zipFilePath);
394+
395+
/// <summary>
396+
/// Uninstall a plugin
397+
/// </summary>
398+
/// <param name="pluginMetadata">The metadata of the plugin to uninstall</param>
399+
/// <param name="removePluginSettings">
400+
/// Plugin has their own settings. If this is set to true, the plugin settings will be removed.
401+
/// </param>
402+
/// <returns></returns>
403+
public Task UninstallPluginAsync(PluginMetadata pluginMetadata, bool removePluginSettings = false);
365404
}
366405
}

Flow.Launcher/PublicAPIInstance.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,18 @@ public MessageBoxResult ShowMsgBox(string messageBoxText, string caption = "", M
358358
public Task<bool> UpdatePluginManifestAsync(bool usePrimaryUrlOnly = false, CancellationToken token = default) =>
359359
PluginsManifest.UpdateManifestAsync(usePrimaryUrlOnly, token);
360360

361-
public IReadOnlyList<UserPlugin> GetUserPlugins() => PluginsManifest.UserPlugins;
361+
public IReadOnlyList<UserPlugin> GetPluginManifest() => PluginsManifest.UserPlugins;
362+
363+
public bool PluginModified(string id) => PluginManager.PluginModified(id);
364+
365+
public Task UpdatePluginAsync(PluginMetadata pluginMetadata, UserPlugin plugin, string zipFilePath) =>
366+
PluginManager.UpdatePluginAsync(pluginMetadata, plugin, zipFilePath);
367+
368+
public void InstallPlugin(UserPlugin plugin, string zipFilePath) =>
369+
PluginManager.InstallPlugin(plugin, zipFilePath);
370+
371+
public Task UninstallPluginAsync(PluginMetadata pluginMetadata, bool removePluginSettings = false) =>
372+
PluginManager.UninstallPluginAsync(pluginMetadata, removePluginSettings);
362373

363374
#endregion
364375

Flow.Launcher/SettingPages/ViewModels/SettingsPanePluginStoreViewModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public partial class SettingsPanePluginStoreViewModel : BaseModel
1313
public string FilterText { get; set; } = string.Empty;
1414

1515
public IList<PluginStoreItemViewModel> ExternalPlugins =>
16-
App.API.GetUserPlugins()?.Select(p => new PluginStoreItemViewModel(p))
16+
App.API.GetPluginManifest()?.Select(p => new PluginStoreItemViewModel(p))
1717
.OrderByDescending(p => p.Category == PluginStoreItemViewModel.NewRelease)
1818
.ThenByDescending(p => p.Category == PluginStoreItemViewModel.RecentlyUpdated)
1919
.ThenByDescending(p => p.Category == PluginStoreItemViewModel.None)

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

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
1-
using Flow.Launcher.Core.Plugin;
2-
using Flow.Launcher.Plugin.SharedCommands;
3-
using System;
1+
using System;
42
using System.Collections.Generic;
53
using System.IO;
64
using System.Linq;
75
using System.Net.Http;
86
using System.Threading;
97
using System.Threading.Tasks;
108
using System.Windows;
9+
using Flow.Launcher.Plugin.SharedCommands;
1110

1211
namespace Flow.Launcher.Plugin.PluginsManager
1312
{
@@ -49,7 +48,7 @@ internal List<Result> GetDefaultHotKeys()
4948
{
5049
return new List<Result>()
5150
{
52-
new Result()
51+
new()
5352
{
5453
Title = Settings.InstallCommand,
5554
IcoPath = icoPath,
@@ -61,7 +60,7 @@ internal List<Result> GetDefaultHotKeys()
6160
return false;
6261
}
6362
},
64-
new Result()
63+
new()
6564
{
6665
Title = Settings.UninstallCommand,
6766
IcoPath = icoPath,
@@ -73,7 +72,7 @@ internal List<Result> GetDefaultHotKeys()
7372
return false;
7473
}
7574
},
76-
new Result()
75+
new()
7776
{
7877
Title = Settings.UpdateCommand,
7978
IcoPath = icoPath,
@@ -248,7 +247,7 @@ internal async ValueTask<List<Result>> RequestUpdateAsync(string search, Cancell
248247
}
249248

250249
var updateSource = !updateFromLocalPath
251-
? Context.API.GetUserPlugins()
250+
? Context.API.GetPluginManifest()
252251
: new List<UserPlugin> { pluginFromLocalPath };
253252

254253
var resultsForUpdate = (
@@ -258,7 +257,7 @@ on existingPlugin.Metadata.ID equals pluginUpdateSource.ID
258257
where string.Compare(existingPlugin.Metadata.Version, pluginUpdateSource.Version,
259258
StringComparison.InvariantCulture) <
260259
0 // if current version precedes version of the plugin from update source (e.g. PluginsManifest)
261-
&& !PluginManager.PluginModified(existingPlugin.Metadata.ID)
260+
&& !Context.API.PluginModified(existingPlugin.Metadata.ID)
262261
select
263262
new
264263
{
@@ -274,7 +273,7 @@ where string.Compare(existingPlugin.Metadata.Version, pluginUpdateSource.Version
274273
if (!resultsForUpdate.Any())
275274
return new List<Result>
276275
{
277-
new Result
276+
new()
278277
{
279278
Title = Context.API.GetTranslation("plugin_pluginsmanager_update_noresult_title"),
280279
SubTitle = Context.API.GetTranslation("plugin_pluginsmanager_update_noresult_subtitle"),
@@ -339,7 +338,7 @@ await DownloadFileAsync(
339338
}
340339
else
341340
{
342-
await PluginManager.UpdatePluginAsync(x.PluginExistingMetadata, x.PluginNewUserPlugin,
341+
await Context.API.UpdatePluginAsync(x.PluginExistingMetadata, x.PluginNewUserPlugin,
343342
downloadToFilePath);
344343

345344
if (Settings.AutoRestartAfterChanging)
@@ -431,7 +430,7 @@ await DownloadFileAsync(
431430
if (cts.IsCancellationRequested)
432431
return;
433432
else
434-
await PluginManager.UpdatePluginAsync(plugin.PluginExistingMetadata, plugin.PluginNewUserPlugin,
433+
await Context.API.UpdatePluginAsync(plugin.PluginExistingMetadata, plugin.PluginNewUserPlugin,
435434
downloadToFilePath);
436435
}
437436
catch (Exception ex)
@@ -550,7 +549,7 @@ internal List<Result> InstallFromLocalPath(string localPath)
550549

551550
return new List<Result>
552551
{
553-
new Result
552+
new()
554553
{
555554
Title = $"{plugin.Name} by {plugin.Author}",
556555
SubTitle = plugin.Description,
@@ -610,8 +609,8 @@ internal async ValueTask<List<Result>> RequestInstallOrUpdateAsync(string search
610609
return InstallFromLocalPath(search);
611610

612611
var results =
613-
Context.API.GetUserPlugins()
614-
.Where(x => !PluginExists(x.ID) && !PluginManager.PluginModified(x.ID))
612+
Context.API.GetPluginManifest()
613+
.Where(x => !PluginExists(x.ID) && !Context.API.PluginModified(x.ID))
615614
.Select(x =>
616615
new Result
617616
{
@@ -644,7 +643,7 @@ private void Install(UserPlugin plugin, string downloadedFilePath)
644643

645644
try
646645
{
647-
PluginManager.InstallPlugin(plugin, downloadedFilePath);
646+
Context.API.InstallPlugin(plugin, downloadedFilePath);
648647

649648
if (!plugin.IsFromLocalInstallPath)
650649
File.Delete(downloadedFilePath);
@@ -737,7 +736,7 @@ private async Task UninstallAsync(PluginMetadata plugin)
737736
Context.API.GetTranslation("plugin_pluginsmanager_keep_plugin_settings_subtitle"),
738737
Context.API.GetTranslation("plugin_pluginsmanager_keep_plugin_settings_title"),
739738
button: MessageBoxButton.YesNo) == MessageBoxResult.No;
740-
await PluginManager.UninstallPluginAsync(plugin, removePluginFromSettings: true, removePluginSettings: removePluginSettings);
739+
await Context.API.UninstallPluginAsync(plugin, removePluginSettings);
741740
}
742741
catch (ArgumentException e)
743742
{

0 commit comments

Comments
 (0)