@@ -29,7 +29,7 @@ public static class PluginManager
2929 public static readonly HashSet < PluginPair > GlobalPlugins = new ( ) ;
3030 public static readonly Dictionary < string , PluginPair > NonGlobalPlugins = new ( ) ;
3131
32- public static IPublicAPI API { get ; private set ; } = Ioc . Default . GetRequiredService < IPublicAPI > ( ) ;
32+ private static readonly IPublicAPI _api = Ioc . Default . GetRequiredService < IPublicAPI > ( ) ;
3333
3434 private static PluginsSettings Settings ;
3535 private static List < PluginMetadata > _metadatas ;
@@ -63,7 +63,7 @@ public static void Save()
6363 savable ? . Save ( ) ;
6464 }
6565
66- API . SavePluginSettings ( ) ;
66+ _api . SavePluginSettings ( ) ;
6767 }
6868
6969 public static async ValueTask DisposePluginsAsync ( )
@@ -168,7 +168,7 @@ public static async Task InitializePluginsAsync()
168168 try
169169 {
170170 var milliseconds = await Stopwatch . DebugAsync ( $ "|PluginManager.InitializePlugins|Init method time cost for <{ pair . Metadata . Name } >",
171- ( ) => pair . Plugin . InitAsync ( new PluginInitContext ( pair . Metadata , API ) ) ) ;
171+ ( ) => pair . Plugin . InitAsync ( new PluginInitContext ( pair . Metadata , _api ) ) ) ;
172172
173173 pair . Metadata . InitTime += milliseconds ;
174174 Log . Info (
@@ -209,10 +209,10 @@ public static async Task InitializePluginsAsync()
209209 if ( failedPlugins . Any ( ) )
210210 {
211211 var failed = string . Join ( "," , failedPlugins . Select ( x => x . Metadata . Name ) ) ;
212- API . ShowMsg (
213- API . GetTranslation ( "failedToInitializePluginsTitle" ) ,
212+ _api . ShowMsg (
213+ _api . GetTranslation ( "failedToInitializePluginsTitle" ) ,
214214 string . Format (
215- API . GetTranslation ( "failedToInitializePluginsMessage" ) ,
215+ _api . GetTranslation ( "failedToInitializePluginsMessage" ) ,
216216 failed
217217 ) ,
218218 "" ,
@@ -519,7 +519,7 @@ internal static void InstallPlugin(UserPlugin plugin, string zipFilePath, bool c
519519
520520 var newPluginPath = Path . Combine ( installDirectory , folderName ) ;
521521
522- FilesFolders . CopyAll ( pluginFolderPath , newPluginPath , ( s ) => API . ShowMsgBox ( s ) ) ;
522+ FilesFolders . CopyAll ( pluginFolderPath , newPluginPath , ( s ) => _api . ShowMsgBox ( s ) ) ;
523523
524524 try
525525 {
@@ -554,8 +554,8 @@ internal static void UninstallPlugin(PluginMetadata plugin, bool removePluginFro
554554
555555 // if user want to remove the plugin settings, we cannot call save method for the plugin json storage instance of this plugin
556556 // so we need to remove it from the api instance
557- var method = API . GetType ( ) . GetMethod ( "RemovePluginSettings" ) ;
558- var pluginJsonStorage = method ? . Invoke ( API , new object [ ] { assemblyName } ) ;
557+ var method = _api . GetType ( ) . GetMethod ( "RemovePluginSettings" ) ;
558+ var pluginJsonStorage = method ? . Invoke ( _api , new object [ ] { assemblyName } ) ;
559559
560560 // if there exists a json storage for current plugin, we need to delete the directory path
561561 if ( pluginJsonStorage != null )
@@ -568,8 +568,8 @@ internal static void UninstallPlugin(PluginMetadata plugin, bool removePluginFro
568568 catch ( Exception e )
569569 {
570570 Log . Exception ( $ "|PluginManager.UninstallPlugin|Failed to delete plugin json folder for { plugin . Name } ", e ) ;
571- API . ShowMsg ( API . GetTranslation ( "failedToRemovePluginSettingsTitle" ) ,
572- string . Format ( API . GetTranslation ( "failedToRemovePluginSettingsMessage" ) , plugin . Name ) ) ;
571+ _api . ShowMsg ( _api . GetTranslation ( "failedToRemovePluginSettingsTitle" ) ,
572+ string . Format ( _api . GetTranslation ( "failedToRemovePluginSettingsMessage" ) , plugin . Name ) ) ;
573573 }
574574 }
575575 }
@@ -585,8 +585,8 @@ internal static void UninstallPlugin(PluginMetadata plugin, bool removePluginFro
585585 catch ( Exception e )
586586 {
587587 Log . Exception ( $ "|PluginManager.UninstallPlugin|Failed to delete plugin json folder for { plugin . Name } ", e ) ;
588- API . ShowMsg ( API . GetTranslation ( "failedToRemovePluginSettingsTitle" ) ,
589- string . Format ( API . GetTranslation ( "failedToRemovePluginSettingsMessage" ) , plugin . Name ) ) ;
588+ _api . ShowMsg ( _api . GetTranslation ( "failedToRemovePluginSettingsTitle" ) ,
589+ string . Format ( _api . GetTranslation ( "failedToRemovePluginSettingsMessage" ) , plugin . Name ) ) ;
590590 }
591591 }
592592 }
0 commit comments