1
1
using Flow . Launcher . Core . ExternalPlugins ;
2
2
using Flow . Launcher . Core . Plugin ;
3
- using Flow . Launcher . Infrastructure ;
4
- using Flow . Launcher . Infrastructure . Http ;
5
- using Flow . Launcher . Infrastructure . Logger ;
6
3
using Flow . Launcher . Plugin . SharedCommands ;
7
4
using System ;
8
5
using System . Collections . Generic ;
@@ -17,7 +14,9 @@ namespace Flow.Launcher.Plugin.PluginsManager
17
14
{
18
15
internal class PluginsManager
19
16
{
20
- private const string zip = "zip" ;
17
+ private const string ZipSuffix = "zip" ;
18
+
19
+ private static readonly string ClassName = nameof ( PluginsManager ) ;
21
20
22
21
private PluginInitContext Context { get ; set ; }
23
22
@@ -169,7 +168,7 @@ await DownloadFileAsync(
169
168
Context . API . ShowMsgError (
170
169
string . Format ( Context . API . GetTranslation ( "plugin_pluginsmanager_downloading_plugin" ) , plugin . Name ) ,
171
170
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 ) ;
173
172
174
173
return ;
175
174
}
@@ -179,7 +178,7 @@ await DownloadFileAsync(
179
178
Context . API . ShowMsgError ( Context . API . GetTranslation ( "plugin_pluginsmanager_install_error_title" ) ,
180
179
string . Format ( Context . API . GetTranslation ( "plugin_pluginsmanager_install_error_subtitle" ) ,
181
180
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 ) ;
183
182
184
183
return ;
185
184
}
@@ -366,7 +365,7 @@ await PluginManager.UpdatePluginAsync(x.PluginExistingMetadata, x.PluginNewUserP
366
365
}
367
366
} ) . ContinueWith ( t =>
368
367
{
369
- Log . Exception ( "PluginsManager" , $ "Update failed for { x . Name } ",
368
+ Context . API . LogException ( ClassName , $ "Update failed for { x . Name } ",
370
369
t . Exception . InnerException ) ;
371
370
Context . API . ShowMsg (
372
371
Context . API . GetTranslation ( "plugin_pluginsmanager_install_error_title" ) ,
@@ -438,7 +437,7 @@ await PluginManager.UpdatePluginAsync(plugin.PluginExistingMetadata, plugin.Plug
438
437
}
439
438
catch ( Exception ex )
440
439
{
441
- Log . Exception ( "PluginsManager" , $ "Update failed for { plugin . Name } ", ex . InnerException ) ;
440
+ Context . API . LogException ( ClassName , $ "Update failed for { plugin . Name } ", ex . InnerException ) ;
442
441
Context . API . ShowMsg (
443
442
Context . API . GetTranslation ( "plugin_pluginsmanager_install_error_title" ) ,
444
443
string . Format (
@@ -486,7 +485,7 @@ internal List<Result> Search(IEnumerable<Result> results, string searchName)
486
485
return results
487
486
. Where ( x =>
488
487
{
489
- var matchResult = StringMatcher . FuzzySearch ( searchName , x . Title ) ;
488
+ var matchResult = Context . API . FuzzySearch ( searchName , x . Title ) ;
490
489
if ( matchResult . IsSearchPrecisionScoreMet ( ) )
491
490
x . Score = matchResult . Score ;
492
491
@@ -498,7 +497,7 @@ internal List<Result> Search(IEnumerable<Result> results, string searchName)
498
497
internal List < Result > InstallFromWeb ( string url )
499
498
{
500
499
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 ( ) ;
502
501
503
502
var plugin = new UserPlugin
504
503
{
@@ -605,7 +604,7 @@ internal async ValueTask<List<Result>> RequestInstallOrUpdateAsync(string search
605
604
await PluginsManifest . UpdateManifestAsync ( token , usePrimaryUrlOnly ) ;
606
605
607
606
if ( Uri . IsWellFormedUriString ( search , UriKind . Absolute )
608
- && search . Split ( '.' ) . Last ( ) == zip )
607
+ && search . Split ( '.' ) . Last ( ) == ZipSuffix )
609
608
return InstallFromWeb ( search ) ;
610
609
611
610
if ( FilesFolders . IsZipFilePath ( search , checkFileExists : true ) )
@@ -656,21 +655,21 @@ private void Install(UserPlugin plugin, string downloadedFilePath)
656
655
{
657
656
Context . API . ShowMsgError ( Context . API . GetTranslation ( "plugin_pluginsmanager_install_error_title" ) ,
658
657
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 ) ;
660
659
}
661
660
catch ( InvalidOperationException e )
662
661
{
663
662
Context . API . ShowMsgError ( Context . API . GetTranslation ( "plugin_pluginsmanager_install_error_title" ) ,
664
663
string . Format ( Context . API . GetTranslation ( "plugin_pluginsmanager_install_error_duplicate" ) ,
665
664
plugin . Name ) ) ;
666
- Log . Exception ( "Flow.Launcher.Plugin.PluginsManager" , e . Message , e ) ;
665
+ Context . API . LogException ( ClassName , e . Message , e ) ;
667
666
}
668
667
catch ( ArgumentException e )
669
668
{
670
669
Context . API . ShowMsgError ( Context . API . GetTranslation ( "plugin_pluginsmanager_install_error_title" ) ,
671
670
string . Format ( Context . API . GetTranslation ( "plugin_pluginsmanager_plugin_modified_error" ) ,
672
671
plugin . Name ) ) ;
673
- Log . Exception ( "Flow.Launcher.Plugin.PluginsManager" , e . Message , e ) ;
672
+ Context . API . LogException ( ClassName , e . Message , e ) ;
674
673
}
675
674
}
676
675
@@ -744,7 +743,7 @@ private async Task UninstallAsync(PluginMetadata plugin)
744
743
}
745
744
catch ( ArgumentException e )
746
745
{
747
- Log . Exception ( "Flow.Launcher.Plugin.PluginsManager" , e . Message , e ) ;
746
+ Context . API . LogException ( ClassName , e . Message , e ) ;
748
747
Context . API . ShowMsgError ( Context . API . GetTranslation ( "plugin_pluginsmanager_uninstall_error_title" ) ,
749
748
Context . API . GetTranslation ( "plugin_pluginsmanager_plugin_modified_error" ) ) ;
750
749
}
0 commit comments