Skip to content

Commit df84e02

Browse files
committed
Improve code quality
1 parent 67cc1e2 commit df84e02

File tree

3 files changed

+21
-24
lines changed

3 files changed

+21
-24
lines changed

Plugins/Flow.Launcher.Plugin.PluginsManager/Flow.Launcher.Plugin.PluginsManager.csproj

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@
1818
</PropertyGroup>
1919

2020
<ItemGroup>
21-
<ProjectReference Include="..\..\Flow.Launcher.Infrastructure\Flow.Launcher.Infrastructure.csproj" />
22-
<ProjectReference Include="..\..\Flow.Launcher.Core\Flow.Launcher.Core.csproj" />
21+
<ProjectReference Include="..\..\Flow.Launcher.Core\Flow.Launcher.Core.csproj" />
2322
<ProjectReference Include="..\..\Flow.Launcher.Plugin\Flow.Launcher.Plugin.csproj" />
2423
</ItemGroup>
2524

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

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
1-
using Flow.Launcher.Core.ExternalPlugins;
2-
using Flow.Launcher.Plugin.PluginsManager.ViewModels;
3-
using Flow.Launcher.Plugin.PluginsManager.Views;
4-
using System.Collections.Generic;
1+
using System.Collections.Generic;
52
using System.Linq;
63
using System.Windows.Controls;
7-
using Flow.Launcher.Infrastructure;
84
using System.Threading.Tasks;
95
using System.Threading;
6+
using Flow.Launcher.Core.ExternalPlugins;
7+
using Flow.Launcher.Plugin.PluginsManager.ViewModels;
8+
using Flow.Launcher.Plugin.PluginsManager.Views;
109

1110
namespace Flow.Launcher.Plugin.PluginsManager
1211
{
1312
public class Main : ISettingProvider, IAsyncPlugin, IContextMenu, IPluginI18n
1413
{
15-
internal PluginInitContext Context { get; set; }
14+
internal static PluginInitContext Context { get; set; }
1615

1716
internal Settings Settings;
1817

@@ -56,7 +55,7 @@ public async Task<List<Result>> QueryAsync(Query query, CancellationToken token)
5655
Settings.UpdateCommand => await pluginManager.RequestUpdateAsync(query.SecondToEndSearch, token, query.IsReQuery),
5756
_ => pluginManager.GetDefaultHotKeys().Where(hotkey =>
5857
{
59-
hotkey.Score = StringMatcher.FuzzySearch(query.Search, hotkey.Title).Score;
58+
hotkey.Score = Context.API.FuzzySearch(query.Search, hotkey.Title).Score;
6059
return hotkey.Score > 0;
6160
}).ToList()
6261
};

Plugins/Flow.Launcher.Plugin.PluginsManager/PluginsManager.cs

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
using Flow.Launcher.Core.ExternalPlugins;
22
using Flow.Launcher.Core.Plugin;
3-
using Flow.Launcher.Infrastructure;
4-
using Flow.Launcher.Infrastructure.Http;
5-
using Flow.Launcher.Infrastructure.Logger;
63
using Flow.Launcher.Plugin.SharedCommands;
74
using System;
85
using System.Collections.Generic;
@@ -17,7 +14,9 @@ namespace Flow.Launcher.Plugin.PluginsManager
1714
{
1815
internal class PluginsManager
1916
{
20-
private const string zip = "zip";
17+
private const string ZipSuffix = "zip";
18+
19+
private static readonly string ClassName = nameof(PluginsManager);
2120

2221
private PluginInitContext Context { get; set; }
2322

@@ -169,7 +168,7 @@ await DownloadFileAsync(
169168
Context.API.ShowMsgError(
170169
string.Format(Context.API.GetTranslation("plugin_pluginsmanager_downloading_plugin"), plugin.Name),
171170
Context.API.GetTranslation("plugin_pluginsmanager_download_error"));
172-
Log.Exception("PluginsManager", "An error occurred while downloading plugin", e);
171+
Context.API.LogException(ClassName, "An error occurred while downloading plugin", e);
173172

174173
return;
175174
}
@@ -179,7 +178,7 @@ await DownloadFileAsync(
179178
Context.API.ShowMsgError(Context.API.GetTranslation("plugin_pluginsmanager_install_error_title"),
180179
string.Format(Context.API.GetTranslation("plugin_pluginsmanager_install_error_subtitle"),
181180
plugin.Name));
182-
Log.Exception("PluginsManager", "An error occurred while downloading plugin", e);
181+
Context.API.LogException(ClassName, "An error occurred while downloading plugin", e);
183182

184183
return;
185184
}
@@ -366,7 +365,7 @@ await PluginManager.UpdatePluginAsync(x.PluginExistingMetadata, x.PluginNewUserP
366365
}
367366
}).ContinueWith(t =>
368367
{
369-
Log.Exception("PluginsManager", $"Update failed for {x.Name}",
368+
Context.API.LogException(ClassName, $"Update failed for {x.Name}",
370369
t.Exception.InnerException);
371370
Context.API.ShowMsg(
372371
Context.API.GetTranslation("plugin_pluginsmanager_install_error_title"),
@@ -438,7 +437,7 @@ await PluginManager.UpdatePluginAsync(plugin.PluginExistingMetadata, plugin.Plug
438437
}
439438
catch (Exception ex)
440439
{
441-
Log.Exception("PluginsManager", $"Update failed for {plugin.Name}", ex.InnerException);
440+
Context.API.LogException(ClassName, $"Update failed for {plugin.Name}", ex.InnerException);
442441
Context.API.ShowMsg(
443442
Context.API.GetTranslation("plugin_pluginsmanager_install_error_title"),
444443
string.Format(
@@ -486,7 +485,7 @@ internal List<Result> Search(IEnumerable<Result> results, string searchName)
486485
return results
487486
.Where(x =>
488487
{
489-
var matchResult = StringMatcher.FuzzySearch(searchName, x.Title);
488+
var matchResult = Context.API.FuzzySearch(searchName, x.Title);
490489
if (matchResult.IsSearchPrecisionScoreMet())
491490
x.Score = matchResult.Score;
492491

@@ -498,7 +497,7 @@ internal List<Result> Search(IEnumerable<Result> results, string searchName)
498497
internal List<Result> InstallFromWeb(string url)
499498
{
500499
var filename = url.Split("/").Last();
501-
var name = filename.Split(string.Format(".{0}", zip)).First();
500+
var name = filename.Split(string.Format(".{0}", ZipSuffix)).First();
502501

503502
var plugin = new UserPlugin
504503
{
@@ -605,7 +604,7 @@ internal async ValueTask<List<Result>> RequestInstallOrUpdateAsync(string search
605604
await PluginsManifest.UpdateManifestAsync(token, usePrimaryUrlOnly);
606605

607606
if (Uri.IsWellFormedUriString(search, UriKind.Absolute)
608-
&& search.Split('.').Last() == zip)
607+
&& search.Split('.').Last() == ZipSuffix)
609608
return InstallFromWeb(search);
610609

611610
if (FilesFolders.IsZipFilePath(search, checkFileExists: true))
@@ -656,21 +655,21 @@ private void Install(UserPlugin plugin, string downloadedFilePath)
656655
{
657656
Context.API.ShowMsgError(Context.API.GetTranslation("plugin_pluginsmanager_install_error_title"),
658657
Context.API.GetTranslation("plugin_pluginsmanager_install_errormetadatafile"));
659-
Log.Exception("Flow.Launcher.Plugin.PluginsManager", e.Message, e);
658+
Context.API.LogException(ClassName, e.Message, e);
660659
}
661660
catch (InvalidOperationException e)
662661
{
663662
Context.API.ShowMsgError(Context.API.GetTranslation("plugin_pluginsmanager_install_error_title"),
664663
string.Format(Context.API.GetTranslation("plugin_pluginsmanager_install_error_duplicate"),
665664
plugin.Name));
666-
Log.Exception("Flow.Launcher.Plugin.PluginsManager", e.Message, e);
665+
Context.API.LogException(ClassName, e.Message, e);
667666
}
668667
catch (ArgumentException e)
669668
{
670669
Context.API.ShowMsgError(Context.API.GetTranslation("plugin_pluginsmanager_install_error_title"),
671670
string.Format(Context.API.GetTranslation("plugin_pluginsmanager_plugin_modified_error"),
672671
plugin.Name));
673-
Log.Exception("Flow.Launcher.Plugin.PluginsManager", e.Message, e);
672+
Context.API.LogException(ClassName, e.Message, e);
674673
}
675674
}
676675

@@ -744,7 +743,7 @@ private async Task UninstallAsync(PluginMetadata plugin)
744743
}
745744
catch (ArgumentException e)
746745
{
747-
Log.Exception("Flow.Launcher.Plugin.PluginsManager", e.Message, e);
746+
Context.API.LogException(ClassName, e.Message, e);
748747
Context.API.ShowMsgError(Context.API.GetTranslation("plugin_pluginsmanager_uninstall_error_title"),
749748
Context.API.GetTranslation("plugin_pluginsmanager_plugin_modified_error"));
750749
}

0 commit comments

Comments
 (0)