Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
6e4d9a5
Remove useless blank lines
Jack251970 Feb 21, 2025
26b2b59
Merge branch 'Flow-Launcher:dev' into multiple_keywords
Jack251970 Feb 21, 2025
8f6bed4
Remove useless * keywords
Jack251970 Feb 21, 2025
e1f1b97
Support allow modify action keywords & WebSearch does not let user ch…
Jack251970 Feb 21, 2025
abfeee1
Support multiple action keywords
Jack251970 Feb 21, 2025
d9ba38b
Fix issue that plugin cannot update ActionKeyword after changing its …
Jack251970 Feb 21, 2025
f999b97
Fix build issue
Jack251970 Feb 21, 2025
37ad5aa
Fix issue that ActionKeywordRegistered will not exclude old action key
Jack251970 Feb 21, 2025
300d64d
Remove action keyword first
Jack251970 Feb 21, 2025
cab3eb7
Update string resource
Jack251970 Feb 21, 2025
414684c
Replace action keyword function with api
Jack251970 Feb 21, 2025
4632932
Revert "Remove useless * keywords" and do not let users change action…
Jack251970 Feb 23, 2025
87febda
Add ReplaceActionKeyword api function
Jack251970 Feb 23, 2025
34cb078
Check old action keyword out of PluginManager
Jack251970 Feb 23, 2025
4ebc19a
Check action keywords without order
Jack251970 Feb 23, 2025
5d67eef
Improve code quality
Jack251970 Feb 23, 2025
3840284
Improve code quality for project references
Jack251970 Feb 23, 2025
6e763f0
Remove ReplaceActionKeyword api function & Add action keyword same no…
Jack251970 Feb 24, 2025
2741366
Improve code quality
Jack251970 Feb 24, 2025
afce702
Improve documents
Jack251970 Feb 25, 2025
f7b1190
Add global search panel
Jack251970 Feb 26, 2025
0c6b89f
Revert "Add global search panel"
Jack251970 Feb 26, 2025
c9f2a14
Remove useless usings
Jack251970 Feb 27, 2025
ca79994
Change to HideActionKeywordPanel
Jack251970 Feb 28, 2025
9ec8681
Remove useless project reference
Jack251970 Feb 28, 2025
ba0d412
Merge branch 'dev' into multiple_keywords
Jack251970 Mar 1, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 16 additions & 9 deletions Flow.Launcher.Core/Plugin/PluginManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,6 @@ public static ICollection<PluginPair> ValidPluginsForQuery(Query query)
if (!NonGlobalPlugins.ContainsKey(query.ActionKeyword))
return GlobalPlugins;


var plugin = NonGlobalPlugins[query.ActionKeyword];
return new List<PluginPair>
{
Expand Down Expand Up @@ -367,7 +366,16 @@ public static void AddActionKeyword(string id, string newActionKeyword)
NonGlobalPlugins[newActionKeyword] = plugin;
}

// Update action keywords and action keyword in plugin metadata
plugin.Metadata.ActionKeywords.Add(newActionKeyword);
if (plugin.Metadata.ActionKeywords.Count > 0)
{
plugin.Metadata.ActionKeyword = plugin.Metadata.ActionKeywords[0];
}
else
{
plugin.Metadata.ActionKeyword = string.Empty;
}
}

/// <summary>
Expand All @@ -388,16 +396,15 @@ public static void RemoveActionKeyword(string id, string oldActionkeyword)
if (oldActionkeyword != Query.GlobalPluginWildcardSign)
NonGlobalPlugins.Remove(oldActionkeyword);


// Update action keywords and action keyword in plugin metadata
plugin.Metadata.ActionKeywords.Remove(oldActionkeyword);
}

public static void ReplaceActionKeyword(string id, string oldActionKeyword, string newActionKeyword)
{
if (oldActionKeyword != newActionKeyword)
if (plugin.Metadata.ActionKeywords.Count > 0)
{
plugin.Metadata.ActionKeyword = plugin.Metadata.ActionKeywords[0];
}
else
{
AddActionKeyword(id, newActionKeyword);
RemoveActionKeyword(id, oldActionKeyword);
plugin.Metadata.ActionKeyword = string.Empty;
}
}

Expand Down
6 changes: 3 additions & 3 deletions Flow.Launcher.Plugin/Interfaces/IPublicAPI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,6 @@ public interface IPublicAPI
/// <param name="callback"></param>
public void RemoveGlobalKeyboardCallback(Func<int, int, SpecialKeyState, bool> callback);


/// <summary>
/// Fuzzy Search the string with the given query. This is the core search mechanism Flow uses
/// </summary>
Expand Down Expand Up @@ -191,14 +190,15 @@ public interface IPublicAPI
Task HttpDownloadAsync([NotNull] string url, [NotNull] string filePath, Action<double> reportProgress = null, CancellationToken token = default);

/// <summary>
/// Add ActionKeyword for specific plugin
/// Add ActionKeyword and update action keyword metadata for specific plugin
/// Before adding, please check if action keyword is already assigned by <see cref="ActionKeywordAssigned"/>
/// </summary>
/// <param name="pluginId">ID for plugin that needs to add action keyword</param>
/// <param name="newActionKeyword">The actionkeyword that is supposed to be added</param>
void AddActionKeyword(string pluginId, string newActionKeyword);

/// <summary>
/// Remove ActionKeyword for specific plugin
/// Remove ActionKeyword and update action keyword metadata for specific plugin
/// </summary>
/// <param name="pluginId">ID for plugin that needs to remove action keyword</param>
/// <param name="oldActionKeyword">The actionkeyword that is supposed to be removed</param>
Expand Down
2 changes: 2 additions & 0 deletions Flow.Launcher.Plugin/PluginMetadata.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ internal set

public List<string> ActionKeywords { get; set; }

public bool HideActionKeywordPanel { get; set; }

public string IcoPath { get; set;}

public override string ToString()
Expand Down
5 changes: 2 additions & 3 deletions Flow.Launcher.Plugin/Query.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,9 @@ public Query() { }
public const string TermSeparator = " ";

/// <summary>
/// User can set multiple action keywords seperated by ';'
/// User can set multiple action keywords seperated by whitespace
/// </summary>
public const string ActionKeywordSeparator = ";";

public const string ActionKeywordSeparator = TermSeparator;

/// <summary>
/// Wildcard action keyword. Plugins using this value will be queried on every search.
Expand Down
55 changes: 48 additions & 7 deletions Flow.Launcher/ActionKeywords.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
using Flow.Launcher.Plugin;
using Flow.Launcher.ViewModel;
using Flow.Launcher.Core;
using System.Linq;
using System.Collections.Generic;

namespace Flow.Launcher
{
Expand Down Expand Up @@ -32,20 +34,59 @@ private void BtnCancel_OnClick(object sender, RoutedEventArgs e)

private void btnDone_OnClick(object sender, RoutedEventArgs _)
{
var oldActionKeyword = plugin.Metadata.ActionKeywords[0];
var newActionKeyword = tbAction.Text.Trim();
newActionKeyword = newActionKeyword.Length > 0 ? newActionKeyword : "*";

if (!PluginViewModel.IsActionKeywordRegistered(newActionKeyword))
var oldActionKeywords = plugin.Metadata.ActionKeywords;

var newActionKeywords = tbAction.Text.Split(Query.ActionKeywordSeparator).ToList();
newActionKeywords.RemoveAll(string.IsNullOrEmpty);
newActionKeywords = newActionKeywords.Distinct().ToList();

newActionKeywords = newActionKeywords.Count > 0 ? newActionKeywords : new() { Query.GlobalPluginWildcardSign };

var addedActionKeywords = newActionKeywords.Except(oldActionKeywords).ToList();
var removedActionKeywords = oldActionKeywords.Except(newActionKeywords).ToList();
if (!addedActionKeywords.Any(App.API.ActionKeywordAssigned))
{
pluginViewModel.ChangeActionKeyword(newActionKeyword, oldActionKeyword);
Close();
if (oldActionKeywords.Count != newActionKeywords.Count)
{
ReplaceActionKeyword(plugin.Metadata.ID, removedActionKeywords, addedActionKeywords);
return;
}

var sortedOldActionKeywords = oldActionKeywords.OrderBy(s => s).ToList();
var sortedNewActionKeywords = newActionKeywords.OrderBy(s => s).ToList();

if (sortedOldActionKeywords.SequenceEqual(sortedNewActionKeywords))
{
// User just changes the sequence of action keywords
var msg = translater.GetTranslation("newActionKeywordsSameAsOld");
MessageBoxEx.Show(msg);
}
else
{
ReplaceActionKeyword(plugin.Metadata.ID, removedActionKeywords, addedActionKeywords);
}
}
else
{
string msg = translater.GetTranslation("newActionKeywordsHasBeenAssigned");
App.API.ShowMsgBox(msg);
}
}

private void ReplaceActionKeyword(string id, IReadOnlyList<string> removedActionKeywords, IReadOnlyList<string> addedActionKeywords)
{
foreach (var actionKeyword in removedActionKeywords)
{
App.API.RemoveActionKeyword(id, actionKeyword);
}
foreach (var actionKeyword in addedActionKeywords)
{
App.API.AddActionKeyword(id, actionKeyword);
}

// Update action keywords text and close window
pluginViewModel.OnActionKeywordsChanged();
Close();
}
}
}
3 changes: 2 additions & 1 deletion Flow.Launcher/Languages/en.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -334,9 +334,10 @@
<system:String x:Key="cannotFindSpecifiedPlugin">Can't find specified plugin</system:String>
<system:String x:Key="newActionKeywordsCannotBeEmpty">New Action Keyword can't be empty</system:String>
<system:String x:Key="newActionKeywordsHasBeenAssigned">This new Action Keyword is already assigned to another plugin, please choose a different one</system:String>
<system:String x:Key="newActionKeywordsSameAsOld">This new Action Keyword is the same as old, please choose a different one</system:String>
<system:String x:Key="success">Success</system:String>
<system:String x:Key="completedSuccessfully">Completed successfully</system:String>
<system:String x:Key="actionkeyword_tips">Enter the action keyword you like to use to start the plugin. Use * if you don't want to specify any, and the plugin will be triggered without any action keywords.</system:String>
<system:String x:Key="actionkeyword_tips">Enter the action keywords you like to use to start the plugin and use whitespace to divide them. Use * if you don't want to specify any, and the plugin will be triggered without any action keywords.</system:String>

<!-- Custom Query Hotkey Dialog -->
<system:String x:Key="customeQueryHotkeyTitle">Custom Query Hotkey</system:String>
Expand Down
1 change: 0 additions & 1 deletion Flow.Launcher/PublicAPIInstance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,6 @@ public bool IsGameModeOn()
return _mainVM.GameModeStatus;
}


private readonly List<Func<int, int, SpecialKeyState, bool>> _globalKeyboardHandlers = new();

public void RegisterGlobalKeyboardCallback(Func<int, int, SpecialKeyState, bool> callback) => _globalKeyboardHandlers.Add(callback);
Expand Down
2 changes: 0 additions & 2 deletions Flow.Launcher/ViewModel/MainViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1135,7 +1135,6 @@ private async void QueryResults(bool isReQuery = false, bool reSelect = true)
SearchIconVisibility = Visibility.Visible;
}


if (query.ActionKeyword == Plugin.Query.GlobalPluginWildcardSign)
{
// Wait 45 millisecond for query change in global query
Expand All @@ -1162,7 +1161,6 @@ private async void QueryResults(bool isReQuery = false, bool reSelect = true)
true => Task.CompletedTask
}).ToArray();


try
{
// Check the code, WhenAll will translate all type of IEnumerable or Collection to Array, so make an array at first
Expand Down
8 changes: 2 additions & 6 deletions Flow.Launcher/ViewModel/PluginViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ private string PluginManagerActionKeyword
}
}


private async void LoadIconAsync()
{
Image = await ImageLoader.LoadAsync(PluginPair.Metadata.IcoPath);
Expand Down Expand Up @@ -100,7 +99,7 @@ public Control SettingControl
: null;
private ImageSource _image = ImageLoader.MissingImage;

public Visibility ActionKeywordsVisibility => PluginPair.Metadata.ActionKeywords.Count == 1 ? Visibility.Visible : Visibility.Collapsed;
public Visibility ActionKeywordsVisibility => PluginPair.Metadata.HideActionKeywordPanel ? Visibility.Collapsed : Visibility.Visible;
public string InitilizaTime => PluginPair.Metadata.InitTime + "ms";
public string QueryTime => PluginPair.Metadata.AvgQueryTime + "ms";
public string Version => InternationalizationManager.Instance.GetTranslation("plugin_query_version") + " " + PluginPair.Metadata.Version;
Expand All @@ -109,9 +108,8 @@ public Control SettingControl
public int Priority => PluginPair.Metadata.Priority;
public Infrastructure.UserSettings.Plugin PluginSettingsObject { get; set; }

public void ChangeActionKeyword(string newActionKeyword, string oldActionKeyword)
public void OnActionKeywordsChanged()
{
PluginManager.ReplaceActionKeyword(PluginPair.Metadata.ID, oldActionKeyword, newActionKeyword);
OnPropertyChanged(nameof(ActionKeywordsText));
}

Expand Down Expand Up @@ -150,8 +148,6 @@ private void OpenDeletePluginWindow()
App.API.ShowMainWindow();
}

public static bool IsActionKeywordRegistered(string newActionKeyword) => PluginManager.ActionKeywordRegistered(newActionKeyword);

[RelayCommand]
private void SetActionKeywords()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@

<ItemGroup>
<ProjectReference Include="..\..\Flow.Launcher.Core\Flow.Launcher.Core.csproj" />
<ProjectReference Include="..\..\Flow.Launcher.Plugin\Flow.Launcher.Plugin.csproj" />
</ItemGroup>

<ItemGroup>
Expand Down
1 change: 1 addition & 0 deletions Plugins/Flow.Launcher.Plugin.Explorer/plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"*",
"*"
],
"HideActionKeywordPanel": true,
"Name": "Explorer",
"Description": "Find and manage files and folders via Windows Search or Everything",
"Author": "Jeremy Wu",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

<ItemGroup>
<ProjectReference Include="..\..\Flow.Launcher.Infrastructure\Flow.Launcher.Infrastructure.csproj" />
<ProjectReference Include="..\..\Flow.Launcher.Core\Flow.Launcher.Core.csproj" />
<ProjectReference Include="..\..\Flow.Launcher.Core\Flow.Launcher.Core.csproj" />
<ProjectReference Include="..\..\Flow.Launcher.Plugin\Flow.Launcher.Plugin.csproj" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\Flow.Launcher.Core\Flow.Launcher.Core.csproj" />
<ProjectReference Include="..\..\Flow.Launcher.Infrastructure\Flow.Launcher.Infrastructure.csproj" />
<ProjectReference Include="..\..\Flow.Launcher.Plugin\Flow.Launcher.Plugin.csproj" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System.Collections.Generic;
using System.Windows;
using Microsoft.Win32;
using Flow.Launcher.Core.Plugin;

namespace Flow.Launcher.Plugin.WebSearch
{
Expand All @@ -16,7 +15,6 @@ public partial class SearchSourceSettingWindow
private SearchSourceViewModel _viewModel;
private string selectedNewIconImageFullPath;


public SearchSourceSettingWindow(IList<SearchSource> sources, PluginInitContext context, SearchSource old)
{
_oldSearchSource = old;
Expand Down Expand Up @@ -80,10 +78,10 @@ private void OnConfirmButtonClick(object sender, RoutedEventArgs e)
private void AddSearchSource()
{
var keyword = _searchSource.ActionKeyword;
if (!PluginManager.ActionKeywordRegistered(keyword))
if (!_context.API.ActionKeywordAssigned(keyword))
{
var id = _context.CurrentPluginMetadata.ID;
PluginManager.AddActionKeyword(id, keyword);
_context.API.AddActionKeyword(id, keyword);

_searchSources.Add(_searchSource);

Expand All @@ -100,10 +98,11 @@ private void EditSearchSource()
{
var newKeyword = _searchSource.ActionKeyword;
var oldKeyword = _oldSearchSource.ActionKeyword;
if (!PluginManager.ActionKeywordRegistered(newKeyword) || oldKeyword == newKeyword)
if (!_context.API.ActionKeywordAssigned(newKeyword) || oldKeyword == newKeyword)
{
var id = _context.CurrentPluginMetadata.ID;
PluginManager.ReplaceActionKeyword(id, oldKeyword, newKeyword);
_context.API.RemoveActionKeyword(id, oldKeyword);
_context.API.AddActionKeyword(id, newKeyword);

var index = _searchSources.IndexOf(_oldSearchSource);
_searchSources[index] = _searchSource;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System.Windows;
using System.Windows.Controls;
using Flow.Launcher.Core.Plugin;
using System.ComponentModel;
using System.Windows.Data;

Expand Down Expand Up @@ -40,7 +39,7 @@ private void OnDeleteSearchSearchClick(object sender, RoutedEventArgs e)
if (result == MessageBoxResult.Yes)
{
var id = _context.CurrentPluginMetadata.ID;
PluginManager.RemoveActionKeyword(id, selected.ActionKeyword);
_context.API.RemoveActionKeyword(id, selected.ActionKeyword);
_settings.SearchSources.Remove(selected);
}
}
Expand Down
1 change: 1 addition & 0 deletions Plugins/Flow.Launcher.Plugin.WebSearch/plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"yahoo",
"bd"
],
"HideActionKeywordPanel": true,
"Name": "Web Searches",
"Description": "Provide the web search ability",
"Author": "qianlifeng",
Expand Down
Loading