Skip to content

Commit cdf02d5

Browse files
committed
Resolve conflicts
2 parents 8b6dcd0 + 2bc9203 commit cdf02d5

40 files changed

+484
-265
lines changed

Flow.Launcher.Core/Plugin/JsonRPCPluginBase.cs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,10 @@ internal abstract class JsonRPCPluginBase : IAsyncPlugin, IContextMenu, ISetting
4444
private string SettingConfigurationPath =>
4545
Path.Combine(Context.CurrentPluginMetadata.PluginDirectory, "SettingsTemplate.yaml");
4646

47-
private string SettingPath => Path.Combine(DataLocation.PluginSettingsDirectory,
48-
Context.CurrentPluginMetadata.Name, "Settings.json");
47+
private string SettingDirectory => Path.Combine(DataLocation.PluginSettingsDirectory,
48+
Context.CurrentPluginMetadata.Name);
49+
50+
private string SettingPath => Path.Combine(SettingDirectory, "Settings.json");
4951

5052
public abstract List<Result> LoadContextMenus(Result selectedResult);
5153

@@ -159,5 +161,13 @@ public Control CreateSettingPanel()
159161
{
160162
return Settings.CreateSettingPanel();
161163
}
164+
165+
public void DeletePluginSettingsDirectory()
166+
{
167+
if (Directory.Exists(SettingDirectory))
168+
{
169+
Directory.Delete(SettingDirectory, true);
170+
}
171+
}
162172
}
163173
}

Flow.Launcher.Core/Plugin/JsonRPCPluginSettings.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ public void Save()
112112
public Control CreateSettingPanel()
113113
{
114114
if (Settings == null || Settings.Count == 0)
115-
return new();
115+
return null;
116116

117117
var settingWindow = new UserControl();
118118
var mainPanel = new Grid { Margin = settingPanelMargin, VerticalAlignment = VerticalAlignment.Center };

Flow.Launcher.Core/Plugin/JsonRPCPluginV2.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,15 @@ private void SetupJsonRPC()
112112
RPC.StartListening();
113113
}
114114

115-
public virtual Task ReloadDataAsync()
115+
public virtual async Task ReloadDataAsync()
116116
{
117-
SetupJsonRPC();
118-
return Task.CompletedTask;
117+
try
118+
{
119+
await RPC.InvokeAsync("reload_data", Context);
120+
}
121+
catch (RemoteMethodNotFoundException e)
122+
{
123+
}
119124
}
120125

121126
public virtual async ValueTask DisposeAsync()

Flow.Launcher.Core/Plugin/PluginManager.cs

Lines changed: 65 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -210,9 +210,9 @@ public static async Task InitializePluginsAsync()
210210
{
211211
var failed = string.Join(",", failedPlugins.Select(x => x.Metadata.Name));
212212
API.ShowMsg(
213-
InternationalizationManager.Instance.GetTranslation("failedToInitializePluginsTitle"),
213+
API.GetTranslation("failedToInitializePluginsTitle"),
214214
string.Format(
215-
InternationalizationManager.Instance.GetTranslation("failedToInitializePluginsMessage"),
215+
API.GetTranslation("failedToInitializePluginsMessage"),
216216
failed
217217
),
218218
"",
@@ -281,7 +281,7 @@ public static async Task<List<Result>> QueryForPluginAsync(PluginPair pair, Quer
281281
return results;
282282
}
283283

284-
public static void UpdatePluginMetadata(List<Result> results, PluginMetadata metadata, Query query)
284+
public static void UpdatePluginMetadata(IReadOnlyList<Result> results, PluginMetadata metadata, Query query)
285285
{
286286
foreach (var r in results)
287287
{
@@ -439,7 +439,7 @@ public static bool PluginModified(string uuid)
439439
public static void UpdatePlugin(PluginMetadata existingVersion, UserPlugin newVersion, string zipFilePath)
440440
{
441441
InstallPlugin(newVersion, zipFilePath, checkModified:false);
442-
UninstallPlugin(existingVersion, removeSettings:false, checkModified:false);
442+
UninstallPlugin(existingVersion, removePluginFromSettings:false, removePluginSettings:false, checkModified: false);
443443
_modifiedPlugins.Add(existingVersion.ID);
444444
}
445445

@@ -454,9 +454,9 @@ public static void InstallPlugin(UserPlugin plugin, string zipFilePath)
454454
/// <summary>
455455
/// Uninstall a plugin.
456456
/// </summary>
457-
public static void UninstallPlugin(PluginMetadata plugin, bool removeSettings = true)
457+
public static void UninstallPlugin(PluginMetadata plugin, bool removePluginFromSettings = true, bool removePluginSettings = false)
458458
{
459-
UninstallPlugin(plugin, removeSettings, true);
459+
UninstallPlugin(plugin, removePluginFromSettings, removePluginSettings, true);
460460
}
461461

462462
#endregion
@@ -521,22 +521,78 @@ internal static void InstallPlugin(UserPlugin plugin, string zipFilePath, bool c
521521

522522
FilesFolders.CopyAll(pluginFolderPath, newPluginPath, (s) => API.ShowMsgBox(s));
523523

524-
Directory.Delete(tempFolderPluginPath, true);
524+
try
525+
{
526+
if (Directory.Exists(tempFolderPluginPath))
527+
Directory.Delete(tempFolderPluginPath, true);
528+
}
529+
catch (Exception e)
530+
{
531+
Log.Exception($"|PluginManager.InstallPlugin|Failed to delete temp folder {tempFolderPluginPath}", e);
532+
}
525533

526534
if (checkModified)
527535
{
528536
_modifiedPlugins.Add(plugin.ID);
529537
}
530538
}
531539

532-
internal static void UninstallPlugin(PluginMetadata plugin, bool removeSettings, bool checkModified)
540+
internal static void UninstallPlugin(PluginMetadata plugin, bool removePluginFromSettings, bool removePluginSettings, bool checkModified)
533541
{
534542
if (checkModified && PluginModified(plugin.ID))
535543
{
536544
throw new ArgumentException($"Plugin {plugin.Name} has been modified");
537545
}
538546

539-
if (removeSettings)
547+
if (removePluginSettings)
548+
{
549+
if (AllowedLanguage.IsDotNet(plugin.Language)) // for the plugin in .NET, we can use assembly loader
550+
{
551+
var assemblyLoader = new PluginAssemblyLoader(plugin.ExecuteFilePath);
552+
var assembly = assemblyLoader.LoadAssemblyAndDependencies();
553+
var assemblyName = assembly.GetName().Name;
554+
555+
// if user want to remove the plugin settings, we cannot call save method for the plugin json storage instance of this plugin
556+
// so we need to remove it from the api instance
557+
var method = API.GetType().GetMethod("RemovePluginSettings");
558+
var pluginJsonStorage = method?.Invoke(API, new object[] { assemblyName });
559+
560+
// if there exists a json storage for current plugin, we need to delete the directory path
561+
if (pluginJsonStorage != null)
562+
{
563+
var deleteMethod = pluginJsonStorage.GetType().GetMethod("DeleteDirectory");
564+
try
565+
{
566+
deleteMethod?.Invoke(pluginJsonStorage, null);
567+
}
568+
catch (Exception e)
569+
{
570+
Log.Exception($"|PluginManager.UninstallPlugin|Failed to delete plugin json folder for {plugin.Name}", e);
571+
API.ShowMsg(API.GetTranslation("failedToRemovePluginSettingsTitle"),
572+
string.Format(API.GetTranslation("failedToRemovePluginSettingsMessage"), plugin.Name));
573+
}
574+
}
575+
}
576+
else // the plugin with json prc interface
577+
{
578+
var pluginPair = AllPlugins.FirstOrDefault(p => p.Metadata.ID == plugin.ID);
579+
if (pluginPair != null && pluginPair.Plugin is JsonRPCPlugin jsonRpcPlugin)
580+
{
581+
try
582+
{
583+
jsonRpcPlugin.DeletePluginSettingsDirectory();
584+
}
585+
catch (Exception e)
586+
{
587+
Log.Exception($"|PluginManager.UninstallPlugin|Failed to delete plugin json folder for {plugin.Name}", e);
588+
API.ShowMsg(API.GetTranslation("failedToRemovePluginSettingsTitle"),
589+
string.Format(API.GetTranslation("failedToRemovePluginSettingsMessage"), plugin.Name));
590+
}
591+
}
592+
}
593+
}
594+
595+
if (removePluginFromSettings)
540596
{
541597
Settings.Plugins.Remove(plugin.ID);
542598
AllPlugins.RemoveAll(p => p.Metadata.ID == plugin.ID);

Flow.Launcher.Infrastructure/Storage/PluginJsonStorage.cs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,17 @@
33

44
namespace Flow.Launcher.Infrastructure.Storage
55
{
6-
public class PluginJsonStorage<T> :JsonStorage<T> where T : new()
6+
public class PluginJsonStorage<T> : JsonStorage<T> where T : new()
77
{
8+
// Use assembly name to check which plugin is using this storage
9+
public readonly string AssemblyName;
10+
811
public PluginJsonStorage()
912
{
1013
// C# related, add python related below
1114
var dataType = typeof(T);
12-
var assemblyName = dataType.Assembly.GetName().Name;
13-
DirectoryPath = Path.Combine(DataLocation.DataDirectory(), DirectoryName, Constant.Plugins, assemblyName);
15+
AssemblyName = dataType.Assembly.GetName().Name;
16+
DirectoryPath = Path.Combine(DataLocation.DataDirectory(), DirectoryName, Constant.Plugins, AssemblyName);
1417
Helper.ValidateDirectory(DirectoryPath);
1518

1619
FilePath = Path.Combine(DirectoryPath, $"{dataType.Name}{FileSuffix}");
@@ -20,6 +23,13 @@ public PluginJsonStorage(T data) : this()
2023
{
2124
Data = data;
2225
}
26+
27+
public void DeleteDirectory()
28+
{
29+
if (Directory.Exists(DirectoryPath))
30+
{
31+
Directory.Delete(DirectoryPath, true);
32+
}
33+
}
2334
}
2435
}
25-

Flow.Launcher.Plugin/Interfaces/IPublicAPI.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ namespace Flow.Launcher.Plugin
1717
public interface IPublicAPI
1818
{
1919
/// <summary>
20-
/// Change Flow.Launcher query
20+
/// Change Flow.Launcher query.
21+
/// When current results are from context menu or history, it will go back to query results before changing query.
2122
/// </summary>
2223
/// <param name="query">query text</param>
2324
/// <param name="requery">
@@ -299,7 +300,7 @@ public interface IPublicAPI
299300

300301
/// <summary>
301302
/// Reloads the query.
302-
/// This method should run when selected item is from query results.
303+
/// When current results are from context menu or history, it will go back to query results before requerying.
303304
/// </summary>
304305
/// <param name="reselect">Choose the first result after reload if true; keep the last selected result if false. Default is true.</param>
305306
public void ReQuery(bool reselect = true);

Flow.Launcher.Plugin/Result.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,8 +266,9 @@ public ValueTask<bool> ExecuteAsync(ActionContext context)
266266
/// The key to identify the record. This is used when FL checks whether the result is the topmost record. Or FL calculates the hashcode of the result for user selected records.
267267
/// This can be useful when your plugin will change the Title or SubTitle of the result dynamically.
268268
/// If the plugin does not specific this, FL just uses Title and SubTitle to identify this result.
269+
/// Note: Because old data does not have this key, we should use null as the default value for consistency.
269270
/// </summary>
270-
public string RecordKey { get; set; } = string.Empty;
271+
public string RecordKey { get; set; } = null;
271272

272273
/// <summary>
273274
/// Info of the preview section of a <see cref="Result"/>

Flow.Launcher.Test/FilesFoldersTest.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using Flow.Launcher.Plugin.SharedCommands;
22
using NUnit.Framework;
3+
using NUnit.Framework.Legacy;
34

45
namespace Flow.Launcher.Test
56
{
@@ -35,7 +36,7 @@ public class FilesFoldersTest
3536
[TestCase(@"c:\barr", @"c:\foo\..\bar\baz", false)]
3637
public void GivenTwoPaths_WhenCheckPathContains_ThenShouldBeExpectedResult(string parentPath, string path, bool expectedResult)
3738
{
38-
Assert.AreEqual(expectedResult, FilesFolders.PathContains(parentPath, path));
39+
ClassicAssert.AreEqual(expectedResult, FilesFolders.PathContains(parentPath, path));
3940
}
4041

4142
// Equality
@@ -47,7 +48,7 @@ public void GivenTwoPaths_WhenCheckPathContains_ThenShouldBeExpectedResult(strin
4748
[TestCase(@"c:\foo", @"c:\foo\", true)]
4849
public void GivenTwoPathsAreTheSame_WhenCheckPathContains_ThenShouldBeExpectedResult(string parentPath, string path, bool expectedResult)
4950
{
50-
Assert.AreEqual(expectedResult, FilesFolders.PathContains(parentPath, path, allowEqual: expectedResult));
51+
ClassicAssert.AreEqual(expectedResult, FilesFolders.PathContains(parentPath, path, allowEqual: expectedResult));
5152
}
5253
}
5354
}

Flow.Launcher.Test/Flow.Launcher.Test.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949

5050
<ItemGroup>
5151
<PackageReference Include="Moq" Version="4.18.4" />
52-
<PackageReference Include="nunit" Version="3.14.0" />
52+
<PackageReference Include="nunit" Version="4.3.2" />
5353
<PackageReference Include="NUnit3TestAdapter" Version="4.6.0">
5454
<PrivateAssets>all</PrivateAssets>
5555
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>

0 commit comments

Comments
 (0)