Skip to content

Commit 53f3e73

Browse files
authored
Merge branch 'dev' into 250320BookmarkFavicon
2 parents a845e68 + d33e751 commit 53f3e73

File tree

183 files changed

+3124
-1463
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

183 files changed

+3124
-1463
lines changed

Flow.Launcher.Core/Configuration/Portable.cs

Lines changed: 15 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public class Portable : IPortable
2222
/// As at Squirrel.Windows version 1.5.2, UpdateManager needs to be disposed after finish
2323
/// </summary>
2424
/// <returns></returns>
25-
private UpdateManager NewUpdateManager()
25+
private static UpdateManager NewUpdateManager()
2626
{
2727
var applicationFolderName = Constant.ApplicationDirectory
2828
.Split(new[] { Path.DirectorySeparatorChar }, StringSplitOptions.None)
@@ -81,20 +81,16 @@ public void EnablePortableMode()
8181

8282
public void RemoveShortcuts()
8383
{
84-
using (var portabilityUpdater = NewUpdateManager())
85-
{
86-
portabilityUpdater.RemoveShortcutsForExecutable(Constant.ApplicationFileName, ShortcutLocation.StartMenu);
87-
portabilityUpdater.RemoveShortcutsForExecutable(Constant.ApplicationFileName, ShortcutLocation.Desktop);
88-
portabilityUpdater.RemoveShortcutsForExecutable(Constant.ApplicationFileName, ShortcutLocation.Startup);
89-
}
84+
using var portabilityUpdater = NewUpdateManager();
85+
portabilityUpdater.RemoveShortcutsForExecutable(Constant.ApplicationFileName, ShortcutLocation.StartMenu);
86+
portabilityUpdater.RemoveShortcutsForExecutable(Constant.ApplicationFileName, ShortcutLocation.Desktop);
87+
portabilityUpdater.RemoveShortcutsForExecutable(Constant.ApplicationFileName, ShortcutLocation.Startup);
9088
}
9189

9290
public void RemoveUninstallerEntry()
9391
{
94-
using (var portabilityUpdater = NewUpdateManager())
95-
{
96-
portabilityUpdater.RemoveUninstallerRegistryEntry();
97-
}
92+
using var portabilityUpdater = NewUpdateManager();
93+
portabilityUpdater.RemoveUninstallerRegistryEntry();
9894
}
9995

10096
public void MoveUserDataFolder(string fromLocation, string toLocation)
@@ -110,12 +106,10 @@ public void VerifyUserDataAfterMove(string fromLocation, string toLocation)
110106

111107
public void CreateShortcuts()
112108
{
113-
using (var portabilityUpdater = NewUpdateManager())
114-
{
115-
portabilityUpdater.CreateShortcutsForExecutable(Constant.ApplicationFileName, ShortcutLocation.StartMenu, false);
116-
portabilityUpdater.CreateShortcutsForExecutable(Constant.ApplicationFileName, ShortcutLocation.Desktop, false);
117-
portabilityUpdater.CreateShortcutsForExecutable(Constant.ApplicationFileName, ShortcutLocation.Startup, false);
118-
}
109+
using var portabilityUpdater = NewUpdateManager();
110+
portabilityUpdater.CreateShortcutsForExecutable(Constant.ApplicationFileName, ShortcutLocation.StartMenu, false);
111+
portabilityUpdater.CreateShortcutsForExecutable(Constant.ApplicationFileName, ShortcutLocation.Desktop, false);
112+
portabilityUpdater.CreateShortcutsForExecutable(Constant.ApplicationFileName, ShortcutLocation.Startup, false);
119113
}
120114

121115
public void CreateUninstallerEntry()
@@ -129,18 +123,14 @@ public void CreateUninstallerEntry()
129123
subKey2.SetValue("DisplayIcon", Path.Combine(Constant.ApplicationDirectory, "app.ico"), RegistryValueKind.String);
130124
}
131125

132-
using (var portabilityUpdater = NewUpdateManager())
133-
{
134-
_ = portabilityUpdater.CreateUninstallerRegistryEntry();
135-
}
126+
using var portabilityUpdater = NewUpdateManager();
127+
_ = portabilityUpdater.CreateUninstallerRegistryEntry();
136128
}
137129

138-
internal void IndicateDeletion(string filePathTodelete)
130+
private static void IndicateDeletion(string filePathTodelete)
139131
{
140132
var deleteFilePath = Path.Combine(filePathTodelete, DataLocation.DeletionIndicatorFile);
141-
using (var _ = File.CreateText(deleteFilePath))
142-
{
143-
}
133+
using var _ = File.CreateText(deleteFilePath);
144134
}
145135

146136
///<summary>

Flow.Launcher.Core/ExternalPlugins/CommunityPluginSource.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using Flow.Launcher.Infrastructure.Http;
22
using Flow.Launcher.Infrastructure.Logger;
3+
using Flow.Launcher.Plugin;
34
using System;
45
using System.Collections.Generic;
56
using System.Net;

Flow.Launcher.Core/ExternalPlugins/CommunityPluginStore.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Linq;
33
using System.Threading;
44
using System.Threading.Tasks;
5+
using Flow.Launcher.Plugin;
56

67
namespace Flow.Launcher.Core.ExternalPlugins
78
{

Flow.Launcher.Core/ExternalPlugins/PluginsManifest.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
using Flow.Launcher.Infrastructure.Logger;
2-
using System;
1+
using System;
32
using System.Collections.Generic;
43
using System.Threading;
54
using System.Threading.Tasks;
5+
using CommunityToolkit.Mvvm.DependencyInjection;
6+
using Flow.Launcher.Plugin;
67

78
namespace Flow.Launcher.Core.ExternalPlugins
89
{
@@ -17,11 +18,11 @@ public static class PluginsManifest
1718
private static readonly SemaphoreSlim manifestUpdateLock = new(1);
1819

1920
private static DateTime lastFetchedAt = DateTime.MinValue;
20-
private static TimeSpan fetchTimeout = TimeSpan.FromMinutes(2);
21+
private static readonly TimeSpan fetchTimeout = TimeSpan.FromMinutes(2);
2122

2223
public static List<UserPlugin> UserPlugins { get; private set; }
2324

24-
public static async Task<bool> UpdateManifestAsync(CancellationToken token = default, bool usePrimaryUrlOnly = false)
25+
public static async Task<bool> UpdateManifestAsync(bool usePrimaryUrlOnly = false, CancellationToken token = default)
2526
{
2627
try
2728
{
@@ -43,7 +44,7 @@ public static async Task<bool> UpdateManifestAsync(CancellationToken token = def
4344
}
4445
catch (Exception e)
4546
{
46-
Log.Exception($"|PluginsManifest.{nameof(UpdateManifestAsync)}|Http request failed", e);
47+
Ioc.Default.GetRequiredService<IPublicAPI>().LogException(nameof(PluginsManifest), "Http request failed", e);
4748
}
4849
finally
4950
{

Flow.Launcher.Core/ExternalPlugins/UserPlugin.cs

Lines changed: 0 additions & 23 deletions
This file was deleted.

Flow.Launcher.Core/Plugin/JsonRPCPluginSettings.cs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ public class JsonRPCPluginSettings
2323
protected ConcurrentDictionary<string, object?> Settings { get; set; } = null!;
2424
public required IPublicAPI API { get; init; }
2525

26+
private static readonly string ClassName = nameof(JsonRPCPluginSettings);
27+
2628
private JsonStorage<ConcurrentDictionary<string, object?>> _storage = null!;
2729

2830
private static readonly Thickness SettingPanelMargin = (Thickness)Application.Current.FindResource("SettingPanelMargin");
@@ -122,12 +124,26 @@ public void UpdateSettings(IReadOnlyDictionary<string, object> settings)
122124

123125
public async Task SaveAsync()
124126
{
125-
await _storage.SaveAsync();
127+
try
128+
{
129+
await _storage.SaveAsync();
130+
}
131+
catch (System.Exception e)
132+
{
133+
API.LogException(ClassName, $"Failed to save plugin settings to path: {SettingPath}", e);
134+
}
126135
}
127136

128137
public void Save()
129138
{
130-
_storage.Save();
139+
try
140+
{
141+
_storage.Save();
142+
}
143+
catch (System.Exception e)
144+
{
145+
API.LogException(ClassName, $"Failed to save plugin settings to path: {SettingPath}", e);
146+
}
131147
}
132148

133149
public bool NeedCreateSettingPanel()

Flow.Launcher.Core/Plugin/JsonRPCV2Models/JsonRPCPublicAPI.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ namespace Flow.Launcher.Core.Plugin.JsonRPCV2Models
1212
{
1313
public class JsonRPCPublicAPI
1414
{
15-
private IPublicAPI _api;
15+
private readonly IPublicAPI _api;
1616

1717
public JsonRPCPublicAPI(IPublicAPI api)
1818
{
@@ -104,7 +104,6 @@ public List<PluginPair> GetAllPlugins()
104104
return _api.GetAllPlugins();
105105
}
106106

107-
108107
public MatchResult FuzzySearch(string query, string stringToCompare)
109108
{
110109
return _api.FuzzySearch(query, stringToCompare);
@@ -156,6 +155,11 @@ public void LogWarn(string className, string message, [CallerMemberName] string
156155
_api.LogWarn(className, message, methodName);
157156
}
158157

158+
public void LogError(string className, string message, [CallerMemberName] string methodName = "")
159+
{
160+
_api.LogError(className, message, methodName);
161+
}
162+
159163
public void OpenDirectory(string DirectoryPath, string FileNameOrFilePath = null)
160164
{
161165
_api.OpenDirectory(DirectoryPath, FileNameOrFilePath);
@@ -185,5 +189,10 @@ public void StopLoadingBar()
185189
{
186190
_api.StopLoadingBar();
187191
}
192+
193+
public void SavePluginCaches()
194+
{
195+
_api.SavePluginCaches();
196+
}
188197
}
189198
}

Flow.Launcher.Core/Plugin/PluginManager.cs

Lines changed: 22 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
using Flow.Launcher.Infrastructure.UserSettings;
1414
using Flow.Launcher.Plugin;
1515
using Flow.Launcher.Plugin.SharedCommands;
16+
using IRemovable = Flow.Launcher.Core.Storage.IRemovable;
1617
using ISavable = Flow.Launcher.Plugin.ISavable;
1718

1819
namespace Flow.Launcher.Core.Plugin
@@ -65,6 +66,7 @@ public static void Save()
6566
}
6667

6768
API.SavePluginSettings();
69+
API.SavePluginCaches();
6870
}
6971

7072
public static async ValueTask DisposePluginsAsync()
@@ -454,34 +456,23 @@ private static bool SameOrLesserPluginVersionExists(string metadataPath)
454456

455457
#region Public functions
456458

457-
public static bool PluginModified(string uuid)
459+
public static bool PluginModified(string id)
458460
{
459-
return _modifiedPlugins.Contains(uuid);
461+
return _modifiedPlugins.Contains(id);
460462
}
461463

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>
467464
public static async Task UpdatePluginAsync(PluginMetadata existingVersion, UserPlugin newVersion, string zipFilePath)
468465
{
469466
InstallPlugin(newVersion, zipFilePath, checkModified:false);
470467
await UninstallPluginAsync(existingVersion, removePluginFromSettings:false, removePluginSettings:false, checkModified: false);
471468
_modifiedPlugins.Add(existingVersion.ID);
472469
}
473470

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>
477471
public static void InstallPlugin(UserPlugin plugin, string zipFilePath)
478472
{
479473
InstallPlugin(plugin, zipFilePath, checkModified: true);
480474
}
481475

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

527518
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-
};
519+
{
520+
"0ECADE17459B49F587BF81DC3A125110", // BrowserBookmark
521+
"CEA0FDFC6D3B4085823D60DC76F28855", // Calculator
522+
"572be03c74c642baae319fc283e561a8", // Explorer
523+
"6A122269676E40EB86EB543B945932B9", // PluginIndicator
524+
"9f8f9b14-2518-4907-b211-35ab6290dee7", // PluginsManager
525+
"b64d0a79-329a-48b0-b53f-d658318a1bf6", // ProcessKiller
526+
"791FC278BA414111B8D1886DFE447410", // Program
527+
"D409510CD0D2481F853690A07E6DC426", // Shell
528+
"CEA08895D2544B019B2E9C5009600DF4", // Sys
529+
"0308FD86DE0A4DEE8D62B9B535370992", // URL
530+
"565B73353DBF4806919830B9202EE3BF", // WebSearch
531+
"5043CETYU6A748679OPA02D27D99677A" // WindowsSettings
532+
};
542533

543534
// Treat default plugin differently, it needs to be removable along with each flow release
544535
var installDirectory = !defaultPluginIDs.Any(x => x == plugin.ID)
@@ -586,11 +577,11 @@ internal static async Task UninstallPluginAsync(PluginMetadata plugin, bool remo
586577

587578
if (removePluginSettings)
588579
{
589-
// For dotnet plugins, we need to remove their PluginJsonStorage instance
590-
if (AllowedLanguage.IsDotNet(plugin.Language))
580+
// For dotnet plugins, we need to remove their PluginJsonStorage and PluginBinaryStorage instances
581+
if (AllowedLanguage.IsDotNet(plugin.Language) && API is IRemovable removable)
591582
{
592-
var method = API.GetType().GetMethod("RemovePluginSettings");
593-
method?.Invoke(API, new object[] { plugin.AssemblyName });
583+
removable.RemovePluginSettings(plugin.AssemblyName);
584+
removable.RemovePluginCaches(plugin.PluginCacheDirectoryPath);
594585
}
595586

596587
try

0 commit comments

Comments
 (0)