Skip to content

Commit 10d3f4a

Browse files
committed
Make PluginManager.API private
1 parent 022cad0 commit 10d3f4a

File tree

6 files changed

+22
-24
lines changed

6 files changed

+22
-24
lines changed

Flow.Launcher.Core/Plugin/PluginManager.cs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}

Flow.Launcher/MainWindow.xaml.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,7 @@ private void CheckFirstLaunch()
438438
if (_settings.FirstLaunch)
439439
{
440440
_settings.FirstLaunch = false;
441-
PluginManager.API.SaveAppAllSettings();
441+
App.API.SaveAppAllSettings();
442442
OpenWelcomeWindow();
443443
}
444444
}

Flow.Launcher/SettingPages/ViewModels/SettingsPaneAboutViewModel.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
using System.Windows;
77
using CommunityToolkit.Mvvm.Input;
88
using Flow.Launcher.Core;
9-
using Flow.Launcher.Core.Plugin;
109
using Flow.Launcher.Core.Resource;
1110
using Flow.Launcher.Infrastructure;
1211
using Flow.Launcher.Infrastructure.UserSettings;
@@ -77,15 +76,15 @@ private void AskClearLogFolderConfirmation()
7776
[RelayCommand]
7877
private void OpenSettingsFolder()
7978
{
80-
PluginManager.API.OpenDirectory(Path.Combine(DataLocation.DataDirectory(), Constant.Settings));
79+
App.API.OpenDirectory(Path.Combine(DataLocation.DataDirectory(), Constant.Settings));
8180
}
8281

8382
[RelayCommand]
8483
private void OpenParentOfSettingsFolder(object parameter)
8584
{
8685
string settingsFolderPath = Path.Combine(DataLocation.DataDirectory(), Constant.Settings);
8786
string parentFolderPath = Path.GetDirectoryName(settingsFolderPath);
88-
PluginManager.API.OpenDirectory(parentFolderPath);
87+
App.API.OpenDirectory(parentFolderPath);
8988
}
9089

9190

Flow.Launcher/SettingPages/Views/SettingsPanePluginStore.xaml.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
using System.Windows.Data;
44
using System.Windows.Input;
55
using System.Windows.Navigation;
6-
using Flow.Launcher.Core.Plugin;
76
using Flow.Launcher.SettingPages.ViewModels;
87
using Flow.Launcher.ViewModel;
98

@@ -49,7 +48,7 @@ private void SettingsPanePlugins_OnKeyDown(object sender, KeyEventArgs e)
4948

5049
private void Hyperlink_OnRequestNavigate(object sender, RequestNavigateEventArgs e)
5150
{
52-
PluginManager.API.OpenUrl(e.Uri.AbsoluteUri);
51+
App.API.OpenUrl(e.Uri.AbsoluteUri);
5352
e.Handled = true;
5453
}
5554

Flow.Launcher/ViewModel/MainViewModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,7 @@ private void OpenSetting()
442442
[RelayCommand]
443443
private void SelectHelp()
444444
{
445-
PluginManager.API.OpenUrl("https://www.flowlauncher.com/docs/#/usage-tips");
445+
App.API.OpenUrl("https://www.flowlauncher.com/docs/#/usage-tips");
446446
}
447447

448448
[RelayCommand]

Flow.Launcher/ViewModel/PluginViewModel.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -134,20 +134,20 @@ private void OpenPluginDirectory()
134134
{
135135
var directory = PluginPair.Metadata.PluginDirectory;
136136
if (!string.IsNullOrEmpty(directory))
137-
PluginManager.API.OpenDirectory(directory);
137+
App.API.OpenDirectory(directory);
138138
}
139139

140140
[RelayCommand]
141141
private void OpenSourceCodeLink()
142142
{
143-
PluginManager.API.OpenUrl(PluginPair.Metadata.Website);
143+
App.API.OpenUrl(PluginPair.Metadata.Website);
144144
}
145145

146146
[RelayCommand]
147147
private void OpenDeletePluginWindow()
148148
{
149-
PluginManager.API.ChangeQuery($"{PluginManagerActionKeyword} uninstall {PluginPair.Metadata.Name}".Trim(), true);
150-
PluginManager.API.ShowMainWindow();
149+
App.API.ChangeQuery($"{PluginManagerActionKeyword} uninstall {PluginPair.Metadata.Name}".Trim(), true);
150+
App.API.ShowMainWindow();
151151
}
152152

153153
public static bool IsActionKeywordRegistered(string newActionKeyword) => PluginManager.ActionKeywordRegistered(newActionKeyword);

0 commit comments

Comments
 (0)