Skip to content

Commit 826bc42

Browse files
committed
Improve code quality
1 parent f71e746 commit 826bc42

File tree

3 files changed

+28
-30
lines changed

3 files changed

+28
-30
lines changed

Plugins/Flow.Launcher.Plugin.Program/Main.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ static void MoveFile(string sourcePath, string destinationPath)
275275
static void WatchProgramUpdate()
276276
{
277277
Win32.WatchProgramUpdate(_settings);
278-
_ = UWPPackage.WatchPackageChange();
278+
_ = UWPPackage.WatchPackageChangeAsync();
279279
}
280280
}
281281

Plugins/Flow.Launcher.Plugin.Program/Programs/UWPPackage.cs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
using System.Windows.Media.Imaging;
99
using Windows.ApplicationModel;
1010
using Windows.Management.Deployment;
11-
using Flow.Launcher.Infrastructure;
1211
using Flow.Launcher.Plugin.Program.Logger;
1312
using Flow.Launcher.Plugin.SharedModels;
1413
using System.Threading.Channels;
@@ -290,9 +289,9 @@ private static IEnumerable<Package> CurrentUserPackages()
290289
}
291290
}
292291

293-
private static Channel<byte> PackageChangeChannel = Channel.CreateBounded<byte>(1);
292+
private static readonly Channel<byte> PackageChangeChannel = Channel.CreateBounded<byte>(1);
294293

295-
public static async Task WatchPackageChange()
294+
public static async Task WatchPackageChangeAsync()
296295
{
297296
if (Environment.OSVersion.Version.Major >= 10)
298297
{
@@ -403,13 +402,13 @@ public Result Result(string query, IPublicAPI api)
403402
if (!Main._settings.EnableDescription || string.IsNullOrWhiteSpace(Description) || Name.Equals(Description))
404403
{
405404
title = Name;
406-
matchResult = StringMatcher.FuzzySearch(query, Name);
405+
matchResult = Main.Context.API.FuzzySearch(query, Name);
407406
}
408407
else
409408
{
410409
title = $"{Name}: {Description}";
411-
var nameMatch = StringMatcher.FuzzySearch(query, Name);
412-
var descriptionMatch = StringMatcher.FuzzySearch(query, Description);
410+
var nameMatch = Main.Context.API.FuzzySearch(query, Name);
411+
var descriptionMatch = Main.Context.API.FuzzySearch(query, Description);
413412
if (descriptionMatch.Score > nameMatch.Score)
414413
{
415414
for (int i = 0; i < descriptionMatch.MatchData.Count; i++)
@@ -477,7 +476,7 @@ public List<Result> ContextMenus(IPublicAPI api)
477476
{
478477
var contextMenus = new List<Result>
479478
{
480-
new Result
479+
new()
481480
{
482481
Title = api.GetTranslation("flowlauncher_plugin_program_open_containing_folder"),
483482
Action = _ =>
@@ -496,9 +495,9 @@ public List<Result> ContextMenus(IPublicAPI api)
496495
contextMenus.Add(new Result
497496
{
498497
Title = api.GetTranslation("flowlauncher_plugin_program_run_as_administrator"),
499-
Action = _ =>
498+
Action = c =>
500499
{
501-
Task.Run(() => Launch(true)).ConfigureAwait(false);
500+
_ = Task.Run(() => Launch(true)).ConfigureAwait(false);
502501
return true;
503502
},
504503
IcoPath = "Images/cmd.png",
@@ -539,7 +538,7 @@ internal string LogoPathFromUri(string uri, (int, int) desiredSize)
539538
{
540539
ProgramLogger.LogException($"|UWP|LogoPathFromUri|{Location}" +
541540
$"|{UserModelId} 's logo uri is null or empty: {Location}",
542-
new ArgumentException("uri"));
541+
new ArgumentException(null, nameof(uri)));
543542
return string.Empty;
544543
}
545544

Plugins/Flow.Launcher.Plugin.Program/Programs/Win32.cs

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
using System.Text;
77
using System.Threading.Tasks;
88
using Microsoft.Win32;
9-
using Flow.Launcher.Infrastructure;
109
using Flow.Launcher.Plugin.Program.Logger;
1110
using Flow.Launcher.Plugin.SharedCommands;
1211
using Flow.Launcher.Plugin.SharedModels;
@@ -73,7 +72,7 @@ public string UniqueIdentifier
7372
private const string ExeExtension = "exe";
7473
private string _uid = string.Empty;
7574

76-
private static readonly Win32 Default = new Win32()
75+
private static readonly Win32 Default = new()
7776
{
7877
Name = string.Empty,
7978
Description = string.Empty,
@@ -92,7 +91,7 @@ private static MatchResult Match(string query, IReadOnlyCollection<string> candi
9291
if (candidates.Count == 0)
9392
return null;
9493

95-
var match = candidates.Select(candidate => StringMatcher.FuzzySearch(query, candidate))
94+
var match = candidates.Select(candidate => Main.Context.API.FuzzySearch(query, candidate))
9695
.MaxBy(match => match.Score);
9796

9897
return match?.IsSearchPrecisionScoreMet() ?? false ? match : null;
@@ -112,14 +111,14 @@ public Result Result(string query, IPublicAPI api)
112111
resultName.Equals(Description))
113112
{
114113
title = resultName;
115-
matchResult = StringMatcher.FuzzySearch(query, resultName);
114+
matchResult = Main.Context.API.FuzzySearch(query, resultName);
116115
}
117116
else
118117
{
119118
// Search in both
120119
title = $"{resultName}: {Description}";
121-
var nameMatch = StringMatcher.FuzzySearch(query, resultName);
122-
var descriptionMatch = StringMatcher.FuzzySearch(query, Description);
120+
var nameMatch = Main.Context.API.FuzzySearch(query, resultName);
121+
var descriptionMatch = Main.Context.API.FuzzySearch(query, Description);
123122
if (descriptionMatch.Score > nameMatch.Score)
124123
{
125124
for (int i = 0; i < descriptionMatch.MatchData.Count; i++)
@@ -219,27 +218,27 @@ public List<Result> ContextMenus(IPublicAPI api)
219218
{
220219
var contextMenus = new List<Result>
221220
{
222-
new Result
221+
new()
223222
{
224223
Title = api.GetTranslation("flowlauncher_plugin_program_run_as_different_user"),
225-
Action = _ =>
224+
Action = c =>
226225
{
227226
var info = new ProcessStartInfo
228227
{
229228
FileName = FullPath, WorkingDirectory = ParentDirectory, UseShellExecute = true
230229
};
231230

232-
Task.Run(() => Main.StartProcess(ShellCommand.RunAsDifferentUser, info));
231+
_ = Task.Run(() => Main.StartProcess(ShellCommand.RunAsDifferentUser, info));
233232

234233
return true;
235234
},
236235
IcoPath = "Images/user.png",
237236
Glyph = new GlyphInfo(FontFamily: "/Resources/#Segoe Fluent Icons", Glyph: "\xe7ee"),
238237
},
239-
new Result
238+
new()
240239
{
241240
Title = api.GetTranslation("flowlauncher_plugin_program_run_as_administrator"),
242-
Action = _ =>
241+
Action = c =>
243242
{
244243
var info = new ProcessStartInfo
245244
{
@@ -249,14 +248,14 @@ public List<Result> ContextMenus(IPublicAPI api)
249248
UseShellExecute = true
250249
};
251250

252-
Task.Run(() => Main.StartProcess(Process.Start, info));
251+
_ = Task.Run(() => Main.StartProcess(Process.Start, info));
253252

254253
return true;
255254
},
256255
IcoPath = "Images/cmd.png",
257256
Glyph = new GlyphInfo(FontFamily: "/Resources/#Segoe Fluent Icons", Glyph: "\xe7ef"),
258257
},
259-
new Result
258+
new()
260259
{
261260
Title = api.GetTranslation("flowlauncher_plugin_program_open_containing_folder"),
262261
Action = _ =>
@@ -296,7 +295,7 @@ public override string ToString()
296295
return Name;
297296
}
298297

299-
private static List<FileSystemWatcher> Watchers = new List<FileSystemWatcher>();
298+
private static readonly List<FileSystemWatcher> Watchers = new();
300299

301300
private static Win32 Win32Program(string path)
302301
{
@@ -402,7 +401,7 @@ private static Win32 UrlProgram(string path, string[] protocols)
402401
var data = parser.ReadFile(path);
403402
var urlSection = data["InternetShortcut"];
404403
var url = urlSection?["URL"];
405-
if (String.IsNullOrEmpty(url))
404+
if (string.IsNullOrEmpty(url))
406405
{
407406
return program;
408407
}
@@ -418,12 +417,12 @@ private static Win32 UrlProgram(string path, string[] protocols)
418417
}
419418

420419
var iconPath = urlSection?["IconFile"];
421-
if (!String.IsNullOrEmpty(iconPath))
420+
if (!string.IsNullOrEmpty(iconPath))
422421
{
423422
program.IcoPath = iconPath;
424423
}
425424
}
426-
catch (Exception e)
425+
catch (Exception)
427426
{
428427
// Many files do not have the required fields, so no logging is done.
429428
}
@@ -474,7 +473,7 @@ private static string Extension(string path)
474473
var extension = Path.GetExtension(path)?.ToLowerInvariant();
475474
if (!string.IsNullOrEmpty(extension))
476475
{
477-
return extension.Substring(1); // remove dot
476+
return extension[1..]; // remove dot
478477
}
479478
else
480479
{
@@ -785,7 +784,7 @@ public static void WatchProgramUpdate(Settings settings)
785784
_ = Task.Run(MonitorDirectoryChangeAsync);
786785
}
787786

788-
private static Channel<byte> indexQueue = Channel.CreateBounded<byte>(1);
787+
private static readonly Channel<byte> indexQueue = Channel.CreateBounded<byte>(1);
789788

790789
public static async Task MonitorDirectoryChangeAsync()
791790
{

0 commit comments

Comments
 (0)