Skip to content

Commit bae0fa5

Browse files
committed
Improve code quality
1 parent 3aa324d commit bae0fa5

File tree

3 files changed

+20
-19
lines changed

3 files changed

+20
-19
lines changed

Flow.Launcher.Core/Plugin/PluginManager.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public static class PluginManager
3737

3838
private static PluginsSettings Settings;
3939
private static List<PluginMetadata> _metadatas;
40-
private static List<string> _modifiedPlugins = new();
40+
private static readonly List<string> _modifiedPlugins = new();
4141

4242
/// <summary>
4343
/// Directories that will hold Flow Launcher plugin directory
@@ -299,7 +299,7 @@ public static async Task<List<Result>> QueryForPluginAsync(PluginPair pair, Quer
299299
{
300300
Title = $"{metadata.Name}: Failed to respond!",
301301
SubTitle = "Select this result for more info",
302-
IcoPath = Flow.Launcher.Infrastructure.Constant.ErrorIcon,
302+
IcoPath = Constant.ErrorIcon,
303303
PluginDirectory = metadata.PluginDirectory,
304304
ActionKeywordAssigned = query.ActionKeyword,
305305
PluginID = metadata.ID,
@@ -376,8 +376,8 @@ public static bool ActionKeywordRegistered(string actionKeyword)
376376
{
377377
// this method is only checking for action keywords (defined as not '*') registration
378378
// hence the actionKeyword != Query.GlobalPluginWildcardSign logic
379-
return actionKeyword != Query.GlobalPluginWildcardSign
380-
&& NonGlobalPlugins.ContainsKey(actionKeyword);
379+
return actionKeyword != Query.GlobalPluginWildcardSign
380+
&& NonGlobalPlugins.ContainsKey(actionKeyword);
381381
}
382382

383383
/// <summary>

Flow.Launcher.Core/Resource/Internationalization.cs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ public class Internationalization
2222
private const string DefaultFile = "en.xaml";
2323
private const string Extension = ".xaml";
2424
private readonly Settings _settings;
25-
private readonly List<string> _languageDirectories = new List<string>();
26-
private readonly List<ResourceDictionary> _oldResources = new List<ResourceDictionary>();
25+
private readonly List<string> _languageDirectories = new();
26+
private readonly List<ResourceDictionary> _oldResources = new();
2727
private readonly string SystemLanguageCode;
2828

2929
public Internationalization(Settings settings)
@@ -144,7 +144,7 @@ public void ChangeLanguage(string languageCode)
144144
_settings.Language = isSystem ? Constant.SystemLanguageCode : language.LanguageCode;
145145
}
146146

147-
private Language GetLanguageByLanguageCode(string languageCode)
147+
private static Language GetLanguageByLanguageCode(string languageCode)
148148
{
149149
var lowercase = languageCode.ToLower();
150150
var language = AvailableLanguages.GetAvailableLanguages().FirstOrDefault(o => o.LanguageCode.ToLower() == lowercase);
@@ -239,7 +239,7 @@ public List<Language> LoadAvailableLanguages()
239239
return list;
240240
}
241241

242-
public string GetTranslation(string key)
242+
public static string GetTranslation(string key)
243243
{
244244
var translation = Application.Current.TryFindResource(key);
245245
if (translation is string)
@@ -257,8 +257,7 @@ private void UpdatePluginMetadataTranslations()
257257
{
258258
foreach (var p in PluginManager.GetPluginsForInterface<IPluginI18n>())
259259
{
260-
var pluginI18N = p.Plugin as IPluginI18n;
261-
if (pluginI18N == null) return;
260+
if (p.Plugin is not IPluginI18n pluginI18N) return;
262261
try
263262
{
264263
p.Metadata.Name = pluginI18N.GetTranslatedPluginTitle();
@@ -272,19 +271,19 @@ private void UpdatePluginMetadataTranslations()
272271
}
273272
}
274273

275-
public string LanguageFile(string folder, string language)
274+
private static string LanguageFile(string folder, string language)
276275
{
277276
if (Directory.Exists(folder))
278277
{
279-
string path = Path.Combine(folder, language);
278+
var path = Path.Combine(folder, language);
280279
if (File.Exists(path))
281280
{
282281
return path;
283282
}
284283
else
285284
{
286285
Log.Error($"|Internationalization.LanguageFile|Language path can't be found <{path}>");
287-
string english = Path.Combine(folder, DefaultFile);
286+
var english = Path.Combine(folder, DefaultFile);
288287
if (File.Exists(english))
289288
{
290289
return english;

Flow.Launcher/PublicAPIInstance.cs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,20 +38,23 @@ namespace Flow.Launcher
3838
public class PublicAPIInstance : IPublicAPI, IRemovable
3939
{
4040
private readonly Settings _settings;
41-
private readonly Internationalization _translater;
4241
private readonly MainViewModel _mainVM;
4342

43+
// Must use getter to access Application.Current.Resources.MergedDictionaries so earlier
4444
private Theme _theme;
4545
private Theme Theme => _theme ??= Ioc.Default.GetRequiredService<Theme>();
4646

47+
// Must use getter to avoid circular dependency
48+
private Updater _updater;
49+
private Updater Updater => _updater ??= Ioc.Default.GetRequiredService<Updater>();
50+
4751
private readonly object _saveSettingsLock = new();
4852

4953
#region Constructor
5054

51-
public PublicAPIInstance(Settings settings, Internationalization translater, MainViewModel mainVM)
55+
public PublicAPIInstance(Settings settings, MainViewModel mainVM)
5256
{
5357
_settings = settings;
54-
_translater = translater;
5558
_mainVM = mainVM;
5659
GlobalHotkey.hookedKeyboardCallback = KListener_hookedKeyboardCallback;
5760
WebRequest.RegisterPrefix("data", new DataWebRequestFactory());
@@ -100,8 +103,7 @@ public event VisibilityChangedEventHandler VisibilityChanged
100103
remove => _mainVM.VisibilityChanged -= value;
101104
}
102105

103-
// Must use Ioc.Default.GetRequiredService<Updater>() to avoid circular dependency
104-
public void CheckForNewUpdate() => _ = Ioc.Default.GetRequiredService<Updater>().UpdateAppAsync(false);
106+
public void CheckForNewUpdate() => _ = Updater.UpdateAppAsync(false);
105107

106108
public void SaveAppAllSettings()
107109
{
@@ -178,7 +180,7 @@ public void CopyToClipboard(string stringToCopy, bool directCopy = false, bool s
178180

179181
public void StopLoadingBar() => _mainVM.ProgressBarVisibility = Visibility.Collapsed;
180182

181-
public string GetTranslation(string key) => _translater.GetTranslation(key);
183+
public string GetTranslation(string key) => Internationalization.GetTranslation(key);
182184

183185
public List<PluginPair> GetAllPlugins() => PluginManager.AllPlugins.ToList();
184186

0 commit comments

Comments
 (0)