Skip to content

Commit 0444141

Browse files
authored
Merge pull request #3435 from Flow-Launcher/dependency_code_quality_1
Dependency Code Quality
2 parents 2e740b1 + f476998 commit 0444141

17 files changed

+75
-110
lines changed

Flow.Launcher.Core/Plugin/PluginManager.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ public static async Task InitializePluginsAsync()
205205
}
206206
catch (Exception e)
207207
{
208-
Log.Exception(nameof(PluginManager), $"Fail to Init plugin: {pair.Metadata.Name}", e);
208+
Log.Exception(ClassName, $"Fail to Init plugin: {pair.Metadata.Name}", e);
209209
pair.Metadata.Disabled = true;
210210
failedPlugins.Enqueue(pair);
211211
}

Flow.Launcher.Core/Resource/InternationalizationManager.cs

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

Flow.Launcher.Core/Updater.cs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
using System.Threading;
1010
using System.Threading.Tasks;
1111
using System.Windows;
12-
using CommunityToolkit.Mvvm.DependencyInjection;
13-
using Flow.Launcher.Core.Resource;
1412
using Flow.Launcher.Plugin.SharedCommands;
1513
using Flow.Launcher.Infrastructure;
1614
using Flow.Launcher.Infrastructure.Http;
@@ -131,7 +129,7 @@ private static async Task<UpdateManager> GitHubUpdateManagerAsync(string reposit
131129

132130
await using var jsonStream = await Http.GetStreamAsync(api).ConfigureAwait(false);
133131

134-
var releases = await System.Text.Json.JsonSerializer.DeserializeAsync<List<GithubRelease>>(jsonStream).ConfigureAwait(false);
132+
var releases = await JsonSerializer.DeserializeAsync<List<GithubRelease>>(jsonStream).ConfigureAwait(false);
135133
var latest = releases.Where(r => !r.Prerelease).OrderByDescending(r => r.PublishedAt).First();
136134
var latestUrl = latest.HtmlUrl.Replace("/tag/", "/download/");
137135

@@ -146,10 +144,9 @@ private static async Task<UpdateManager> GitHubUpdateManagerAsync(string reposit
146144
return manager;
147145
}
148146

149-
private static string NewVersionTips(string version)
147+
private string NewVersionTips(string version)
150148
{
151-
var translator = Ioc.Default.GetRequiredService<Internationalization>();
152-
var tips = string.Format(translator.GetTranslation("newVersionTips"), version);
149+
var tips = string.Format(_api.GetTranslation("newVersionTips"), version);
153150

154151
return tips;
155152
}

Flow.Launcher/ActionKeywords.xaml.cs

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,26 @@
11
using System.Windows;
2-
using Flow.Launcher.Core.Resource;
32
using Flow.Launcher.Plugin;
43
using Flow.Launcher.ViewModel;
5-
using Flow.Launcher.Core;
64
using System.Linq;
75
using System.Collections.Generic;
86

97
namespace Flow.Launcher
108
{
119
public partial class ActionKeywords
1210
{
13-
private readonly PluginPair plugin;
14-
private readonly Internationalization translater = InternationalizationManager.Instance;
15-
private readonly PluginViewModel pluginViewModel;
11+
private readonly PluginPair _plugin;
12+
private readonly PluginViewModel _pluginViewModel;
1613

1714
public ActionKeywords(PluginViewModel pluginViewModel)
1815
{
1916
InitializeComponent();
20-
plugin = pluginViewModel.PluginPair;
21-
this.pluginViewModel = pluginViewModel;
17+
_plugin = pluginViewModel.PluginPair;
18+
_pluginViewModel = pluginViewModel;
2219
}
2320

2421
private void ActionKeyword_OnLoaded(object sender, RoutedEventArgs e)
2522
{
26-
tbOldActionKeyword.Text = string.Join(Query.ActionKeywordSeparator, plugin.Metadata.ActionKeywords.ToArray());
23+
tbOldActionKeyword.Text = string.Join(Query.ActionKeywordSeparator, _plugin.Metadata.ActionKeywords.ToArray());
2724
tbAction.Focus();
2825
}
2926

@@ -34,7 +31,7 @@ private void BtnCancel_OnClick(object sender, RoutedEventArgs e)
3431

3532
private void btnDone_OnClick(object sender, RoutedEventArgs _)
3633
{
37-
var oldActionKeywords = plugin.Metadata.ActionKeywords;
34+
var oldActionKeywords = _plugin.Metadata.ActionKeywords;
3835

3936
var newActionKeywords = tbAction.Text.Split(Query.ActionKeywordSeparator).ToList();
4037
newActionKeywords.RemoveAll(string.IsNullOrEmpty);
@@ -48,7 +45,7 @@ private void btnDone_OnClick(object sender, RoutedEventArgs _)
4845
{
4946
if (oldActionKeywords.Count != newActionKeywords.Count)
5047
{
51-
ReplaceActionKeyword(plugin.Metadata.ID, removedActionKeywords, addedActionKeywords);
48+
ReplaceActionKeyword(_plugin.Metadata.ID, removedActionKeywords, addedActionKeywords);
5249
return;
5350
}
5451

@@ -58,18 +55,16 @@ private void btnDone_OnClick(object sender, RoutedEventArgs _)
5855
if (sortedOldActionKeywords.SequenceEqual(sortedNewActionKeywords))
5956
{
6057
// User just changes the sequence of action keywords
61-
var msg = translater.GetTranslation("newActionKeywordsSameAsOld");
62-
MessageBoxEx.Show(msg);
58+
App.API.ShowMsgBox(App.API.GetTranslation("newActionKeywordsSameAsOld"));
6359
}
6460
else
6561
{
66-
ReplaceActionKeyword(plugin.Metadata.ID, removedActionKeywords, addedActionKeywords);
62+
ReplaceActionKeyword(_plugin.Metadata.ID, removedActionKeywords, addedActionKeywords);
6763
}
6864
}
6965
else
7066
{
71-
string msg = translater.GetTranslation("newActionKeywordsHasBeenAssigned");
72-
App.API.ShowMsgBox(msg);
67+
App.API.ShowMsgBox(App.API.GetTranslation("newActionKeywordsHasBeenAssigned"));
7368
}
7469
}
7570

@@ -85,7 +80,7 @@ private void ReplaceActionKeyword(string id, IReadOnlyList<string> removedAction
8580
}
8681

8782
// Update action keywords text and close window
88-
pluginViewModel.OnActionKeywordsChanged();
83+
_pluginViewModel.OnActionKeywordsChanged();
8984
Close();
9085
}
9186
}

Flow.Launcher/App.xaml.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ public void Dispose()
343343

344344
public void OnSecondAppStarted()
345345
{
346-
Ioc.Default.GetRequiredService<MainViewModel>().Show();
346+
API.ShowMainWindow();
347347
}
348348

349349
#endregion

Flow.Launcher/Converters/TextConverter.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
using System;
22
using System.Globalization;
33
using System.Windows.Data;
4-
using Flow.Launcher.Core.Resource;
54
using Flow.Launcher.ViewModel;
65

76
namespace Flow.Launcher.Converters;
@@ -23,7 +22,7 @@ public object Convert(object value, Type targetType, object parameter, CultureIn
2322
if (translationKey is null)
2423
return id;
2524

26-
return InternationalizationManager.Instance.GetTranslation(translationKey);
25+
return App.API.GetTranslation(translationKey);
2726
}
2827

2928
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) => throw new InvalidOperationException();

Flow.Launcher/CustomQueryHotkeySetting.xaml.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
using Flow.Launcher.Core.Resource;
2-
using Flow.Launcher.Helper;
1+
using Flow.Launcher.Helper;
32
using Flow.Launcher.Infrastructure.UserSettings;
43
using System.Collections.ObjectModel;
54
using System.Linq;
@@ -53,22 +52,21 @@ private void btnAdd_OnClick(object sender, RoutedEventArgs e)
5352
Close();
5453
}
5554

56-
5755
public void UpdateItem(CustomPluginHotkey item)
5856
{
5957
updateCustomHotkey = _settings.CustomPluginHotkeys.FirstOrDefault(o =>
6058
o.ActionKeyword == item.ActionKeyword && o.Hotkey == item.Hotkey);
6159
if (updateCustomHotkey == null)
6260
{
63-
App.API.ShowMsgBox(InternationalizationManager.Instance.GetTranslation("invalidPluginHotkey"));
61+
App.API.ShowMsgBox(App.API.GetTranslation("invalidPluginHotkey"));
6462
Close();
6563
return;
6664
}
6765

6866
tbAction.Text = updateCustomHotkey.ActionKeyword;
6967
HotkeyControl.SetHotkey(updateCustomHotkey.Hotkey, false);
7068
update = true;
71-
lblAdd.Text = InternationalizationManager.Instance.GetTranslation("update");
69+
lblAdd.Text = App.API.GetTranslation("update");
7270
}
7371

7472
private void BtnTestActionKeyword_OnClick(object sender, RoutedEventArgs e)

Flow.Launcher/CustomShortcutSetting.xaml.cs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
using Flow.Launcher.Core.Resource;
2-
using System;
1+
using System;
32
using System.Windows;
43
using System.Windows.Input;
54
using Flow.Launcher.SettingPages.ViewModels;
6-
using Flow.Launcher.Core;
75

86
namespace Flow.Launcher
97
{
@@ -41,15 +39,15 @@ private void BtnCancel_OnClick(object sender, RoutedEventArgs e)
4139

4240
private void BtnAdd_OnClick(object sender, RoutedEventArgs e)
4341
{
44-
if (String.IsNullOrEmpty(Key) || String.IsNullOrEmpty(Value))
42+
if (string.IsNullOrEmpty(Key) || string.IsNullOrEmpty(Value))
4543
{
46-
App.API.ShowMsgBox(InternationalizationManager.Instance.GetTranslation("emptyShortcut"));
44+
App.API.ShowMsgBox(App.API.GetTranslation("emptyShortcut"));
4745
return;
4846
}
4947
// Check if key is modified or adding a new one
5048
if (((update && originalKey != Key) || !update) && _hotkeyVm.DoesShortcutExist(Key))
5149
{
52-
App.API.ShowMsgBox(InternationalizationManager.Instance.GetTranslation("duplicateShortcut"));
50+
App.API.ShowMsgBox(App.API.GetTranslation("duplicateShortcut"));
5351
return;
5452
}
5553
DialogResult = !update || originalKey != Key || originalValue != Value;

Flow.Launcher/Helper/HotKeyMapper.cs

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
using System;
44
using NHotkey;
55
using NHotkey.Wpf;
6-
using Flow.Launcher.Core.Resource;
76
using Flow.Launcher.ViewModel;
87
using ChefKeys;
98
using Flow.Launcher.Infrastructure.Logger;
@@ -56,9 +55,9 @@ private static void SetWithChefKeys(string hotkeyStr)
5655
string.Format("|HotkeyMapper.SetWithChefKeys|Error registering hotkey: {0} \nStackTrace:{1}",
5756
e.Message,
5857
e.StackTrace));
59-
string errorMsg = string.Format(InternationalizationManager.Instance.GetTranslation("registerHotkeyFailed"), hotkeyStr);
60-
string errorMsgTitle = InternationalizationManager.Instance.GetTranslation("MessageBoxTitle");
61-
MessageBoxEx.Show(errorMsg, errorMsgTitle);
58+
string errorMsg = string.Format(App.API.GetTranslation("registerHotkeyFailed"), hotkeyStr);
59+
string errorMsgTitle = App.API.GetTranslation("MessageBoxTitle");
60+
App.API.ShowMsgBox(errorMsg, errorMsgTitle);
6261
}
6362
}
6463

@@ -82,8 +81,8 @@ internal static void SetHotkey(HotkeyModel hotkey, EventHandler<HotkeyEventArgs>
8281
e.Message,
8382
e.StackTrace,
8483
hotkeyStr));
85-
string errorMsg = string.Format(InternationalizationManager.Instance.GetTranslation("registerHotkeyFailed"), hotkeyStr);
86-
string errorMsgTitle = InternationalizationManager.Instance.GetTranslation("MessageBoxTitle");
84+
string errorMsg = string.Format(App.API.GetTranslation("registerHotkeyFailed"), hotkeyStr);
85+
string errorMsgTitle = App.API.GetTranslation("MessageBoxTitle");
8786
App.API.ShowMsgBox(errorMsg, errorMsgTitle);
8887
}
8988
}
@@ -107,9 +106,9 @@ internal static void RemoveHotkey(string hotkeyStr)
107106
string.Format("|HotkeyMapper.RemoveHotkey|Error removing hotkey: {0} \nStackTrace:{1}",
108107
e.Message,
109108
e.StackTrace));
110-
string errorMsg = string.Format(InternationalizationManager.Instance.GetTranslation("unregisterHotkeyFailed"), hotkeyStr);
111-
string errorMsgTitle = InternationalizationManager.Instance.GetTranslation("MessageBoxTitle");
112-
MessageBoxEx.Show(errorMsg, errorMsgTitle);
109+
string errorMsg = string.Format(App.API.GetTranslation("unregisterHotkeyFailed"), hotkeyStr);
110+
string errorMsgTitle = App.API.GetTranslation("MessageBoxTitle");
111+
App.API.ShowMsgBox(errorMsg, errorMsgTitle);
113112
}
114113
}
115114

@@ -137,8 +136,8 @@ internal static void SetCustomQueryHotkey(CustomPluginHotkey hotkey)
137136
if (_mainViewModel.ShouldIgnoreHotkeys())
138137
return;
139138

140-
_mainViewModel.Show();
141-
_mainViewModel.ChangeQueryText(hotkey.ActionKeyword, true);
139+
App.API.ShowMainWindow();
140+
App.API.ChangeQuery(hotkey.ActionKeyword, true);
142141
});
143142
}
144143

Flow.Launcher/HotkeyControl.xaml.cs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
using System.Windows;
66
using System.Windows.Input;
77
using CommunityToolkit.Mvvm.DependencyInjection;
8-
using Flow.Launcher.Core.Resource;
98
using Flow.Launcher.Helper;
109
using Flow.Launcher.Infrastructure.Hotkey;
1110
using Flow.Launcher.Infrastructure.UserSettings;
@@ -65,7 +64,6 @@ private static void OnHotkeyChanged(DependencyObject d, DependencyPropertyChange
6564
hotkeyControl.RefreshHotkeyInterface(hotkeyControl.Hotkey);
6665
}
6766

68-
6967
public static readonly DependencyProperty ChangeHotkeyProperty = DependencyProperty.Register(
7068
nameof(ChangeHotkey),
7169
typeof(ICommand),
@@ -79,7 +77,6 @@ public ICommand? ChangeHotkey
7977
set { SetValue(ChangeHotkeyProperty, value); }
8078
}
8179

82-
8380
public static readonly DependencyProperty TypeProperty = DependencyProperty.Register(
8481
nameof(Type),
8582
typeof(HotkeyType),
@@ -227,19 +224,18 @@ private void RefreshHotkeyInterface(string hotkey)
227224
private static bool CheckHotkeyAvailability(HotkeyModel hotkey, bool validateKeyGesture) =>
228225
hotkey.Validate(validateKeyGesture) && HotKeyMapper.CheckAvailability(hotkey);
229226

230-
public string EmptyHotkey => InternationalizationManager.Instance.GetTranslation("none");
227+
public string EmptyHotkey => App.API.GetTranslation("none");
231228

232229
public ObservableCollection<string> KeysToDisplay { get; set; } = new();
233230

234231
public HotkeyModel CurrentHotkey { get; private set; } = new(false, false, false, false, Key.None);
235232

236-
237233
public void GetNewHotkey(object sender, RoutedEventArgs e)
238234
{
239-
OpenHotkeyDialog();
235+
_ = OpenHotkeyDialogAsync();
240236
}
241237

242-
private async Task OpenHotkeyDialog()
238+
private async Task OpenHotkeyDialogAsync()
243239
{
244240
if (!string.IsNullOrEmpty(Hotkey))
245241
{
@@ -262,12 +258,11 @@ private async Task OpenHotkeyDialog()
262258
}
263259
}
264260

265-
266261
private void SetHotkey(HotkeyModel keyModel, bool triggerValidate = true)
267262
{
268263
if (triggerValidate)
269264
{
270-
bool hotkeyAvailable = false;
265+
bool hotkeyAvailable;
271266
// TODO: This is a temporary way to enforce changing only the open flow hotkey to Win, and will be removed by PR #3157
272267
if (keyModel.ToString() == "LWin" || keyModel.ToString() == "RWin")
273268
{

0 commit comments

Comments
 (0)