Skip to content

Commit 2741366

Browse files
committed
Improve code quality
1 parent 6e763f0 commit 2741366

File tree

2 files changed

+12
-15
lines changed

2 files changed

+12
-15
lines changed

Flow.Launcher/ActionKeywords.xaml.cs

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
using Flow.Launcher.ViewModel;
55
using Flow.Launcher.Core;
66
using System.Linq;
7-
using Flow.Launcher.Core.Plugin;
87
using System.Collections.Generic;
98

109
namespace Flow.Launcher
@@ -43,11 +42,14 @@ private void btnDone_OnClick(object sender, RoutedEventArgs _)
4342

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

46-
if (!newActionKeywords.Except(oldActionKeywords).Any(PluginManager.ActionKeywordRegistered))
45+
var addedActionKeywords = newActionKeywords.Except(oldActionKeywords).ToList();
46+
var removedActionKeywords = oldActionKeywords.Except(newActionKeywords).ToList();
47+
if (!addedActionKeywords.Any(App.API.ActionKeywordAssigned))
4748
{
4849
if (oldActionKeywords.Count != newActionKeywords.Count)
4950
{
50-
ReplaceActionKeyword(plugin.Metadata.ID, oldActionKeywords, newActionKeywords);
51+
ReplaceActionKeyword(plugin.Metadata.ID, removedActionKeywords, addedActionKeywords);
52+
return;
5153
}
5254

5355
var sortedOldActionKeywords = oldActionKeywords.OrderBy(s => s).ToList();
@@ -61,7 +63,7 @@ private void btnDone_OnClick(object sender, RoutedEventArgs _)
6163
}
6264
else
6365
{
64-
ReplaceActionKeyword(plugin.Metadata.ID, oldActionKeywords, newActionKeywords);
66+
ReplaceActionKeyword(plugin.Metadata.ID, removedActionKeywords, addedActionKeywords);
6567
}
6668
}
6769
else
@@ -71,21 +73,18 @@ private void btnDone_OnClick(object sender, RoutedEventArgs _)
7173
}
7274
}
7375

74-
private void ReplaceActionKeyword(string id, IReadOnlyList<string> oldActionKeywords, IReadOnlyList<string> newActionKeywords)
76+
private void ReplaceActionKeyword(string id, IReadOnlyList<string> removedActionKeywords, IReadOnlyList<string> addedActionKeywords)
7577
{
76-
// Because add & remove action keyword will change action keyword metadata,
77-
// so we need to clone it to fix collection modified while iterating exception
78-
var oldActionKeywordsClone = oldActionKeywords.ToList();
79-
foreach (var actionKeyword in oldActionKeywordsClone)
78+
foreach (var actionKeyword in removedActionKeywords)
8079
{
81-
PluginManager.RemoveActionKeyword(id, actionKeyword);
80+
App.API.RemoveActionKeyword(id, actionKeyword);
8281
}
83-
foreach (var actionKeyword in newActionKeywords)
82+
foreach (var actionKeyword in addedActionKeywords)
8483
{
85-
PluginManager.AddActionKeyword(id, actionKeyword);
84+
App.API.AddActionKeyword(id, actionKeyword);
8685
}
8786

88-
// Update action keywords text and close
87+
// Update action keywords text and close window
8988
pluginViewModel.OnActionKeywordsChanged();
9089
Close();
9190
}

Flow.Launcher/ViewModel/PluginViewModel.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
using CommunityToolkit.Mvvm.Input;
99
using Flow.Launcher.Core.Resource;
1010
using Flow.Launcher.Resources.Controls;
11-
using System.Collections.Generic;
1211

1312
namespace Flow.Launcher.ViewModel
1413
{
@@ -44,7 +43,6 @@ private string PluginManagerActionKeyword
4443
}
4544
}
4645

47-
4846
private async void LoadIconAsync()
4947
{
5048
Image = await ImageLoader.LoadAsync(PluginPair.Metadata.IcoPath);

0 commit comments

Comments
 (0)