From 87febda78f7842ff018fe0718492e850ce164414 Mon Sep 17 00:00:00 2001
From: Jack251970 <1160210343@qq.com>
Date: Sun, 23 Feb 2025 12:49:21 +0800
Subject: [PATCH] Add ReplaceActionKeyword api function
---
Flow.Launcher.Plugin/Interfaces/IPublicAPI.cs | 9 ++++++++-
Flow.Launcher/PublicAPIInstance.cs | 4 +++-
.../Flow.Launcher.Plugin.WebSearch.csproj | 1 -
.../SearchSourceSetting.xaml.cs | 3 +--
.../SettingsControl.xaml.cs | 1 -
5 files changed, 12 insertions(+), 6 deletions(-)
diff --git a/Flow.Launcher.Plugin/Interfaces/IPublicAPI.cs b/Flow.Launcher.Plugin/Interfaces/IPublicAPI.cs
index 8376fd07b..da6bb598b 100644
--- a/Flow.Launcher.Plugin/Interfaces/IPublicAPI.cs
+++ b/Flow.Launcher.Plugin/Interfaces/IPublicAPI.cs
@@ -151,7 +151,6 @@ namespace Flow.Launcher.Plugin
///
public void RemoveGlobalKeyboardCallback(Func callback);
-
///
/// Fuzzy Search the string with the given query. This is the core search mechanism Flow uses
///
@@ -334,5 +333,13 @@ namespace Flow.Launcher.Plugin
/// When user closes the progress box manually by button or esc key, this action will be called.
/// A progress box interface.
public Task ShowProgressBoxAsync(string caption, Func, Task> reportProgressAsync, Action forceClosed = null);
+
+ ///
+ /// Replace ActionKeyword for specific plugin
+ ///
+ /// ID for plugin that needs to remove action keyword
+ /// The actionkeyword that is supposed to be removed
+ /// The actionkeyword that is supposed to be added
+ public void ReplaceActionKeyword(string pluginId, string oldActionKeyword, string newActionKeyword);
}
}
diff --git a/Flow.Launcher/PublicAPIInstance.cs b/Flow.Launcher/PublicAPIInstance.cs
index 7706a64ba..b6f3b0d27 100644
--- a/Flow.Launcher/PublicAPIInstance.cs
+++ b/Flow.Launcher/PublicAPIInstance.cs
@@ -26,6 +26,7 @@ using System.Collections.Concurrent;
using System.Diagnostics;
using System.Collections.Specialized;
using Flow.Launcher.Core;
+using Flow.Launcher.Infrastructure.UserSettings;
namespace Flow.Launcher
{
@@ -311,7 +312,6 @@ namespace Flow.Launcher
return _mainVM.GameModeStatus;
}
-
private readonly List> _globalKeyboardHandlers = new();
public void RegisterGlobalKeyboardCallback(Func callback) => _globalKeyboardHandlers.Add(callback);
@@ -326,6 +326,8 @@ namespace Flow.Launcher
public Task ShowProgressBoxAsync(string caption, Func, Task> reportProgressAsync, Action forceClosed = null) => ProgressBoxEx.ShowAsync(caption, reportProgressAsync, forceClosed);
+ public void ReplaceActionKeyword(string pluginId, string oldActionKeyword, string newActionKeyword) => PluginManager.ReplaceActionKeyword(pluginId, oldActionKeyword, newActionKeyword);
+
#endregion
#region Private Methods
diff --git a/Plugins/Flow.Launcher.Plugin.WebSearch/Flow.Launcher.Plugin.WebSearch.csproj b/Plugins/Flow.Launcher.Plugin.WebSearch/Flow.Launcher.Plugin.WebSearch.csproj
index 55d69d526..c2d0a46a0 100644
--- a/Plugins/Flow.Launcher.Plugin.WebSearch/Flow.Launcher.Plugin.WebSearch.csproj
+++ b/Plugins/Flow.Launcher.Plugin.WebSearch/Flow.Launcher.Plugin.WebSearch.csproj
@@ -51,7 +51,6 @@
-
diff --git a/Plugins/Flow.Launcher.Plugin.WebSearch/SearchSourceSetting.xaml.cs b/Plugins/Flow.Launcher.Plugin.WebSearch/SearchSourceSetting.xaml.cs
index fa53e5f5a..d3d18d0d2 100644
--- a/Plugins/Flow.Launcher.Plugin.WebSearch/SearchSourceSetting.xaml.cs
+++ b/Plugins/Flow.Launcher.Plugin.WebSearch/SearchSourceSetting.xaml.cs
@@ -1,7 +1,6 @@
using System.Collections.Generic;
using System.Windows;
using Microsoft.Win32;
-using Flow.Launcher.Core.Plugin;
namespace Flow.Launcher.Plugin.WebSearch
{
@@ -103,7 +102,7 @@ namespace Flow.Launcher.Plugin.WebSearch
if (!_context.API.ActionKeywordAssigned(newKeyword) || oldKeyword == newKeyword)
{
var id = _context.CurrentPluginMetadata.ID;
- PluginManager.ReplaceActionKeyword(id, oldKeyword, newKeyword);
+ _context.API.ReplaceActionKeyword(id, oldKeyword, newKeyword);
var index = _searchSources.IndexOf(_oldSearchSource);
_searchSources[index] = _searchSource;
diff --git a/Plugins/Flow.Launcher.Plugin.WebSearch/SettingsControl.xaml.cs b/Plugins/Flow.Launcher.Plugin.WebSearch/SettingsControl.xaml.cs
index 5efe46a9d..e53f4ec75 100644
--- a/Plugins/Flow.Launcher.Plugin.WebSearch/SettingsControl.xaml.cs
+++ b/Plugins/Flow.Launcher.Plugin.WebSearch/SettingsControl.xaml.cs
@@ -1,6 +1,5 @@
using System.Windows;
using System.Windows.Controls;
-using Flow.Launcher.Core.Plugin;
using System.ComponentModel;
using System.Windows.Data;