mirror of
https://github.com/Flow-Launcher/Flow.Launcher.git
synced 2026-03-11 08:54:32 +00:00
Use PublicApi.Instance instead of private one
This commit is contained in:
parent
7350c1d4d5
commit
0e366a6269
13 changed files with 140 additions and 208 deletions
|
|
@ -3,10 +3,8 @@ using System.IO;
|
|||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Windows;
|
||||
using CommunityToolkit.Mvvm.DependencyInjection;
|
||||
using Flow.Launcher.Infrastructure;
|
||||
using Flow.Launcher.Infrastructure.UserSettings;
|
||||
using Flow.Launcher.Plugin;
|
||||
using Flow.Launcher.Plugin.SharedCommands;
|
||||
using Microsoft.Win32;
|
||||
using Squirrel;
|
||||
|
|
@ -17,8 +15,6 @@ namespace Flow.Launcher.Core.Configuration
|
|||
{
|
||||
private static readonly string ClassName = nameof(Portable);
|
||||
|
||||
private readonly IPublicAPI API = Ioc.Default.GetRequiredService<IPublicAPI>();
|
||||
|
||||
/// <summary>
|
||||
/// As at Squirrel.Windows version 1.5.2, UpdateManager needs to be disposed after finish
|
||||
/// </summary>
|
||||
|
|
@ -45,13 +41,13 @@ namespace Flow.Launcher.Core.Configuration
|
|||
#endif
|
||||
IndicateDeletion(DataLocation.PortableDataPath);
|
||||
|
||||
API.ShowMsgBox(Localize.restartToDisablePortableMode());
|
||||
PublicApi.Instance.ShowMsgBox(Localize.restartToDisablePortableMode());
|
||||
|
||||
UpdateManager.RestartApp(Constant.ApplicationFileName);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
API.LogException(ClassName, "Error occurred while disabling portable mode", e);
|
||||
PublicApi.Instance.LogException(ClassName, "Error occurred while disabling portable mode", e);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -68,13 +64,13 @@ namespace Flow.Launcher.Core.Configuration
|
|||
#endif
|
||||
IndicateDeletion(DataLocation.RoamingDataPath);
|
||||
|
||||
API.ShowMsgBox(Localize.restartToEnablePortableMode());
|
||||
PublicApi.Instance.ShowMsgBox(Localize.restartToEnablePortableMode());
|
||||
|
||||
UpdateManager.RestartApp(Constant.ApplicationFileName);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
API.LogException(ClassName, "Error occurred while enabling portable mode", e);
|
||||
PublicApi.Instance.LogException(ClassName, "Error occurred while enabling portable mode", e);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -94,13 +90,13 @@ namespace Flow.Launcher.Core.Configuration
|
|||
|
||||
public void MoveUserDataFolder(string fromLocation, string toLocation)
|
||||
{
|
||||
FilesFolders.CopyAll(fromLocation, toLocation, (s) => API.ShowMsgBox(s));
|
||||
FilesFolders.CopyAll(fromLocation, toLocation, (s) => PublicApi.Instance.ShowMsgBox(s));
|
||||
VerifyUserDataAfterMove(fromLocation, toLocation);
|
||||
}
|
||||
|
||||
public void VerifyUserDataAfterMove(string fromLocation, string toLocation)
|
||||
{
|
||||
FilesFolders.VerifyBothFolderFilesEqual(fromLocation, toLocation, (s) => API.ShowMsgBox(s));
|
||||
FilesFolders.VerifyBothFolderFilesEqual(fromLocation, toLocation, (s) => PublicApi.Instance.ShowMsgBox(s));
|
||||
}
|
||||
|
||||
public void CreateShortcuts()
|
||||
|
|
@ -150,12 +146,12 @@ namespace Flow.Launcher.Core.Configuration
|
|||
// delete it and prompt the user to pick the portable data location
|
||||
if (File.Exists(roamingDataDeleteFilePath))
|
||||
{
|
||||
FilesFolders.RemoveFolderIfExists(roamingDataDir, (s) => API.ShowMsgBox(s));
|
||||
FilesFolders.RemoveFolderIfExists(roamingDataDir, (s) => PublicApi.Instance.ShowMsgBox(s));
|
||||
|
||||
if (API.ShowMsgBox(Localize.moveToDifferentLocation(),
|
||||
if (PublicApi.Instance.ShowMsgBox(Localize.moveToDifferentLocation(),
|
||||
string.Empty, MessageBoxButton.YesNo) == MessageBoxResult.Yes)
|
||||
{
|
||||
FilesFolders.OpenPath(Constant.RootDirectory, (s) => API.ShowMsgBox(s));
|
||||
FilesFolders.OpenPath(Constant.RootDirectory, (s) => PublicApi.Instance.ShowMsgBox(s));
|
||||
|
||||
Environment.Exit(0);
|
||||
}
|
||||
|
|
@ -164,9 +160,9 @@ namespace Flow.Launcher.Core.Configuration
|
|||
// delete it and notify the user about it.
|
||||
else if (File.Exists(portableDataDeleteFilePath))
|
||||
{
|
||||
FilesFolders.RemoveFolderIfExists(portableDataDir, (s) => API.ShowMsgBox(s));
|
||||
FilesFolders.RemoveFolderIfExists(portableDataDir, (s) => PublicApi.Instance.ShowMsgBox(s));
|
||||
|
||||
API.ShowMsgBox(Localize.shortcutsUninstallerCreated());
|
||||
PublicApi.Instance.ShowMsgBox(Localize.shortcutsUninstallerCreated());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -177,7 +173,7 @@ namespace Flow.Launcher.Core.Configuration
|
|||
|
||||
if (roamingLocationExists && portableLocationExists)
|
||||
{
|
||||
API.ShowMsgBox(Localize.userDataDuplicated(DataLocation.PortableDataPath, DataLocation.RoamingDataPath, Environment.NewLine));
|
||||
PublicApi.Instance.ShowMsgBox(Localize.userDataDuplicated(DataLocation.PortableDataPath, DataLocation.RoamingDataPath, Environment.NewLine));
|
||||
|
||||
return false;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,7 +8,6 @@ using System.Text.Json;
|
|||
using System.Text.Json.Serialization;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using CommunityToolkit.Mvvm.DependencyInjection;
|
||||
using Flow.Launcher.Infrastructure.Http;
|
||||
using Flow.Launcher.Plugin;
|
||||
|
||||
|
|
@ -18,13 +17,9 @@ namespace Flow.Launcher.Core.ExternalPlugins
|
|||
{
|
||||
private static readonly string ClassName = nameof(CommunityPluginSource);
|
||||
|
||||
// We should not initialize API in static constructor because it will create another API instance
|
||||
private static IPublicAPI api = null;
|
||||
private static IPublicAPI API => api ??= Ioc.Default.GetRequiredService<IPublicAPI>();
|
||||
|
||||
private string latestEtag = "";
|
||||
|
||||
private List<UserPlugin> plugins = new();
|
||||
private List<UserPlugin> plugins = [];
|
||||
|
||||
private static readonly JsonSerializerOptions PluginStoreItemSerializationOption = new()
|
||||
{
|
||||
|
|
@ -41,7 +36,7 @@ namespace Flow.Launcher.Core.ExternalPlugins
|
|||
/// </remarks>
|
||||
public async Task<List<UserPlugin>> FetchAsync(CancellationToken token)
|
||||
{
|
||||
API.LogInfo(ClassName, $"Loading plugins from {ManifestFileUrl}");
|
||||
PublicApi.Instance.LogInfo(ClassName, $"Loading plugins from {ManifestFileUrl}");
|
||||
|
||||
var request = new HttpRequestMessage(HttpMethod.Get, ManifestFileUrl);
|
||||
|
||||
|
|
@ -59,40 +54,40 @@ namespace Flow.Launcher.Core.ExternalPlugins
|
|||
.ConfigureAwait(false);
|
||||
latestEtag = response.Headers.ETag?.Tag;
|
||||
|
||||
API.LogInfo(ClassName, $"Loaded {plugins.Count} plugins from {ManifestFileUrl}");
|
||||
PublicApi.Instance.LogInfo(ClassName, $"Loaded {plugins.Count} plugins from {ManifestFileUrl}");
|
||||
return plugins;
|
||||
}
|
||||
else if (response.StatusCode == HttpStatusCode.NotModified)
|
||||
{
|
||||
API.LogInfo(ClassName, $"Resource {ManifestFileUrl} has not been modified.");
|
||||
PublicApi.Instance.LogInfo(ClassName, $"Resource {ManifestFileUrl} has not been modified.");
|
||||
return plugins;
|
||||
}
|
||||
else
|
||||
{
|
||||
API.LogWarn(ClassName, $"Failed to load resource {ManifestFileUrl} with response {response.StatusCode}");
|
||||
PublicApi.Instance.LogWarn(ClassName, $"Failed to load resource {ManifestFileUrl} with response {response.StatusCode}");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
catch (OperationCanceledException) when (token.IsCancellationRequested)
|
||||
{
|
||||
API.LogDebug(ClassName, $"Fetching from {ManifestFileUrl} was cancelled by caller.");
|
||||
PublicApi.Instance.LogDebug(ClassName, $"Fetching from {ManifestFileUrl} was cancelled by caller.");
|
||||
return null;
|
||||
}
|
||||
catch (TaskCanceledException)
|
||||
{
|
||||
// Likely an HttpClient timeout or external cancellation not requested by our token
|
||||
API.LogWarn(ClassName, $"Fetching from {ManifestFileUrl} timed out.");
|
||||
PublicApi.Instance.LogWarn(ClassName, $"Fetching from {ManifestFileUrl} timed out.");
|
||||
return null;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
if (e is HttpRequestException or WebException or SocketException || e.InnerException is TimeoutException)
|
||||
{
|
||||
API.LogException(ClassName, $"Check your connection and proxy settings to {ManifestFileUrl}.", e);
|
||||
PublicApi.Instance.LogException(ClassName, $"Check your connection and proxy settings to {ManifestFileUrl}.", e);
|
||||
}
|
||||
else
|
||||
{
|
||||
API.LogException(ClassName, "Error Occurred", e);
|
||||
PublicApi.Instance.LogException(ClassName, "Error Occurred", e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@ using System.IO;
|
|||
using System.Linq;
|
||||
using System.Windows;
|
||||
using System.Windows.Forms;
|
||||
using CommunityToolkit.Mvvm.DependencyInjection;
|
||||
using Flow.Launcher.Infrastructure.UserSettings;
|
||||
using Flow.Launcher.Plugin;
|
||||
using Flow.Launcher.Plugin.SharedCommands;
|
||||
|
|
@ -15,8 +14,6 @@ namespace Flow.Launcher.Core.ExternalPlugins.Environments
|
|||
{
|
||||
private static readonly string ClassName = nameof(AbstractPluginEnvironment);
|
||||
|
||||
protected readonly IPublicAPI API = Ioc.Default.GetRequiredService<IPublicAPI>();
|
||||
|
||||
internal abstract string Language { get; }
|
||||
|
||||
internal abstract string EnvName { get; }
|
||||
|
|
@ -59,7 +56,7 @@ namespace Flow.Launcher.Core.ExternalPlugins.Environments
|
|||
}
|
||||
|
||||
var noRuntimeMessage = Localize.runtimePluginInstalledChooseRuntimePrompt(Language, EnvName, Environment.NewLine);
|
||||
if (API.ShowMsgBox(noRuntimeMessage, string.Empty, MessageBoxButton.YesNo) == MessageBoxResult.No)
|
||||
if (PublicApi.Instance.ShowMsgBox(noRuntimeMessage, string.Empty, MessageBoxButton.YesNo) == MessageBoxResult.No)
|
||||
{
|
||||
var msg = Localize.runtimePluginChooseRuntimeExecutable(EnvName);
|
||||
|
||||
|
|
@ -77,7 +74,7 @@ namespace Flow.Launcher.Core.ExternalPlugins.Environments
|
|||
// Let users select valid path or choose to download
|
||||
while (string.IsNullOrEmpty(selectedFile))
|
||||
{
|
||||
if (API.ShowMsgBox(forceDownloadMessage, string.Empty, MessageBoxButton.YesNo) == MessageBoxResult.Yes)
|
||||
if (PublicApi.Instance.ShowMsgBox(forceDownloadMessage, string.Empty, MessageBoxButton.YesNo) == MessageBoxResult.Yes)
|
||||
{
|
||||
// Continue select file
|
||||
selectedFile = GetFileFromDialog(msg, FileDialogFilter);
|
||||
|
|
@ -110,8 +107,8 @@ namespace Flow.Launcher.Core.ExternalPlugins.Environments
|
|||
}
|
||||
else
|
||||
{
|
||||
API.ShowMsgBox(Localize.runtimePluginUnableToSetExecutablePath(Language));
|
||||
API.LogError(ClassName,
|
||||
PublicApi.Instance.ShowMsgBox(Localize.runtimePluginUnableToSetExecutablePath(Language));
|
||||
PublicApi.Instance.LogError(ClassName,
|
||||
$"Not able to successfully set {EnvName} path, setting's plugin executable path variable is still an empty string.",
|
||||
$"{Language}Environment");
|
||||
|
||||
|
|
@ -125,7 +122,7 @@ namespace Flow.Launcher.Core.ExternalPlugins.Environments
|
|||
{
|
||||
if (expectedPath == currentPath) return;
|
||||
|
||||
FilesFolders.RemoveFolderIfExists(installedDirPath, (s) => API.ShowMsgBox(s));
|
||||
FilesFolders.RemoveFolderIfExists(installedDirPath, (s) => PublicApi.Instance.ShowMsgBox(s));
|
||||
|
||||
InstallEnvironment();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using CommunityToolkit.Mvvm.DependencyInjection;
|
||||
using Flow.Launcher.Plugin;
|
||||
using Flow.Launcher.Infrastructure;
|
||||
|
||||
|
|
@ -23,10 +22,6 @@ namespace Flow.Launcher.Core.ExternalPlugins
|
|||
private static DateTime lastFetchedAt = DateTime.MinValue;
|
||||
private static readonly TimeSpan fetchTimeout = TimeSpan.FromMinutes(2);
|
||||
|
||||
// We should not initialize API in static constructor because it will create another API instance
|
||||
private static IPublicAPI api = null;
|
||||
private static IPublicAPI API => api ??= Ioc.Default.GetRequiredService<IPublicAPI>();
|
||||
|
||||
public static List<UserPlugin> UserPlugins { get; private set; }
|
||||
|
||||
public static async Task<bool> UpdateManifestAsync(bool usePrimaryUrlOnly = false, CancellationToken token = default)
|
||||
|
|
@ -61,7 +56,7 @@ namespace Flow.Launcher.Core.ExternalPlugins
|
|||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
API.LogException(ClassName, "Http request failed", e);
|
||||
PublicApi.Instance.LogException(ClassName, "Http request failed", e);
|
||||
}
|
||||
finally
|
||||
{
|
||||
|
|
@ -83,12 +78,12 @@ namespace Flow.Launcher.Core.ExternalPlugins
|
|||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
API.LogException(ClassName, $"Failed to parse the minimum app version {plugin.MinimumAppVersion} for plugin {plugin.Name}. "
|
||||
PublicApi.Instance.LogException(ClassName, $"Failed to parse the minimum app version {plugin.MinimumAppVersion} for plugin {plugin.Name}. "
|
||||
+ "Plugin excluded from manifest", e);
|
||||
return false;
|
||||
}
|
||||
|
||||
API.LogInfo(ClassName, $"Plugin {plugin.Name} requires minimum Flow Launcher version {plugin.MinimumAppVersion}, "
|
||||
PublicApi.Instance.LogInfo(ClassName, $"Plugin {plugin.Name} requires minimum Flow Launcher version {plugin.MinimumAppVersion}, "
|
||||
+ $"but current version is {Constant.Version}. Plugin excluded from manifest.");
|
||||
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@ using System.IO;
|
|||
using Flow.Launcher.Infrastructure;
|
||||
using Flow.Launcher.Plugin;
|
||||
using System.Text.Json;
|
||||
using CommunityToolkit.Mvvm.DependencyInjection;
|
||||
|
||||
namespace Flow.Launcher.Core.Plugin
|
||||
{
|
||||
|
|
@ -13,10 +12,6 @@ namespace Flow.Launcher.Core.Plugin
|
|||
{
|
||||
private static readonly string ClassName = nameof(PluginConfig);
|
||||
|
||||
// We should not initialize API in static constructor because it will create another API instance
|
||||
private static IPublicAPI api = null;
|
||||
private static IPublicAPI API => api ??= Ioc.Default.GetRequiredService<IPublicAPI>();
|
||||
|
||||
/// <summary>
|
||||
/// Parse plugin metadata in the given directories
|
||||
/// </summary>
|
||||
|
|
@ -38,7 +33,7 @@ namespace Flow.Launcher.Core.Plugin
|
|||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
API.LogException(ClassName, $"Can't delete <{directory}>", e);
|
||||
PublicApi.Instance.LogException(ClassName, $"Can't delete <{directory}>", e);
|
||||
}
|
||||
}
|
||||
else
|
||||
|
|
@ -55,7 +50,7 @@ namespace Flow.Launcher.Core.Plugin
|
|||
|
||||
duplicateList
|
||||
.ForEach(
|
||||
x => API.LogWarn(ClassName,
|
||||
x => PublicApi.Instance.LogWarn(ClassName,
|
||||
string.Format("Duplicate plugin name: {0}, id: {1}, version: {2} " +
|
||||
"not loaded due to version not the highest of the duplicates",
|
||||
x.Name, x.ID, x.Version),
|
||||
|
|
@ -107,7 +102,7 @@ namespace Flow.Launcher.Core.Plugin
|
|||
string configPath = Path.Combine(pluginDirectory, Constant.PluginMetadataFileName);
|
||||
if (!File.Exists(configPath))
|
||||
{
|
||||
API.LogError(ClassName, $"Didn't find config file <{configPath}>");
|
||||
PublicApi.Instance.LogError(ClassName, $"Didn't find config file <{configPath}>");
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
@ -123,19 +118,19 @@ namespace Flow.Launcher.Core.Plugin
|
|||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
API.LogException(ClassName, $"Invalid json for config <{configPath}>", e);
|
||||
PublicApi.Instance.LogException(ClassName, $"Invalid json for config <{configPath}>", e);
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!AllowedLanguage.IsAllowed(metadata.Language))
|
||||
{
|
||||
API.LogError(ClassName, $"Invalid language <{metadata.Language}> for config <{configPath}>");
|
||||
PublicApi.Instance.LogError(ClassName, $"Invalid language <{metadata.Language}> for config <{configPath}>");
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!File.Exists(metadata.ExecuteFilePath))
|
||||
{
|
||||
API.LogError(ClassName, $"Execute file path didn't exist <{metadata.ExecuteFilePath}> for conifg <{configPath}");
|
||||
PublicApi.Instance.LogError(ClassName, $"Execute file path didn't exist <{metadata.ExecuteFilePath}> for conifg <{configPath}");
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -22,10 +22,6 @@ public static class PluginInstaller
|
|||
|
||||
private static readonly Settings Settings = Ioc.Default.GetRequiredService<Settings>();
|
||||
|
||||
// We should not initialize API in static constructor because it will create another API instance
|
||||
private static IPublicAPI api = null;
|
||||
private static IPublicAPI API => api ??= Ioc.Default.GetRequiredService<IPublicAPI>();
|
||||
|
||||
/// <summary>
|
||||
/// Installs a plugin and restarts the application if required by settings. Prompts user for confirmation and handles download if needed.
|
||||
/// </summary>
|
||||
|
|
@ -33,14 +29,14 @@ public static class PluginInstaller
|
|||
/// <returns>A Task representing the asynchronous install operation.</returns>
|
||||
public static async Task InstallPluginAndCheckRestartAsync(UserPlugin newPlugin)
|
||||
{
|
||||
if (API.PluginModified(newPlugin.ID))
|
||||
if (PublicApi.Instance.PluginModified(newPlugin.ID))
|
||||
{
|
||||
API.ShowMsgError(Localize.pluginModifiedAlreadyTitle(newPlugin.Name),
|
||||
PublicApi.Instance.ShowMsgError(Localize.pluginModifiedAlreadyTitle(newPlugin.Name),
|
||||
Localize.pluginModifiedAlreadyMessage());
|
||||
return;
|
||||
}
|
||||
|
||||
if (API.ShowMsgBox(
|
||||
if (PublicApi.Instance.ShowMsgBox(
|
||||
Localize.InstallPromptSubtitle(newPlugin.Name, newPlugin.Author, Environment.NewLine),
|
||||
Localize.InstallPromptTitle(),
|
||||
button: MessageBoxButton.YesNo) != MessageBoxResult.Yes) return;
|
||||
|
|
@ -78,7 +74,7 @@ public static class PluginInstaller
|
|||
throw new FileNotFoundException($"Plugin {newPlugin.ID} zip file not found at {filePath}", filePath);
|
||||
}
|
||||
|
||||
if (!API.InstallPlugin(newPlugin, filePath))
|
||||
if (!PublicApi.Instance.InstallPlugin(newPlugin, filePath))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
|
@ -90,18 +86,18 @@ public static class PluginInstaller
|
|||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
API.LogException(ClassName, "Failed to install plugin", e);
|
||||
API.ShowMsgError(Localize.ErrorInstallingPlugin());
|
||||
PublicApi.Instance.LogException(ClassName, "Failed to install plugin", e);
|
||||
PublicApi.Instance.ShowMsgError(Localize.ErrorInstallingPlugin());
|
||||
return; // do not restart on failure
|
||||
}
|
||||
|
||||
if (Settings.AutoRestartAfterChanging)
|
||||
{
|
||||
API.RestartApp();
|
||||
PublicApi.Instance.RestartApp();
|
||||
}
|
||||
else
|
||||
{
|
||||
API.ShowMsg(
|
||||
PublicApi.Instance.ShowMsg(
|
||||
Localize.installbtn(),
|
||||
Localize.InstallSuccessNoRestart(newPlugin.Name));
|
||||
}
|
||||
|
|
@ -128,14 +124,14 @@ public static class PluginInstaller
|
|||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
API.LogException(ClassName, "Failed to validate zip file", e);
|
||||
API.ShowMsgError(Localize.ZipFileNotHavePluginJson());
|
||||
PublicApi.Instance.LogException(ClassName, "Failed to validate zip file", e);
|
||||
PublicApi.Instance.ShowMsgError(Localize.ZipFileNotHavePluginJson());
|
||||
return;
|
||||
}
|
||||
|
||||
if (API.PluginModified(plugin.ID))
|
||||
if (PublicApi.Instance.PluginModified(plugin.ID))
|
||||
{
|
||||
API.ShowMsgError(Localize.pluginModifiedAlreadyTitle(plugin.Name),
|
||||
PublicApi.Instance.ShowMsgError(Localize.pluginModifiedAlreadyTitle(plugin.Name),
|
||||
Localize.pluginModifiedAlreadyMessage());
|
||||
return;
|
||||
}
|
||||
|
|
@ -143,7 +139,7 @@ public static class PluginInstaller
|
|||
if (Settings.ShowUnknownSourceWarning)
|
||||
{
|
||||
if (!InstallSourceKnown(plugin.Website)
|
||||
&& API.ShowMsgBox(Localize.InstallFromUnknownSourceSubtitle(Environment.NewLine),
|
||||
&& PublicApi.Instance.ShowMsgBox(Localize.InstallFromUnknownSourceSubtitle(Environment.NewLine),
|
||||
Localize.InstallFromUnknownSourceTitle(),
|
||||
MessageBoxButton.YesNo) == MessageBoxResult.No)
|
||||
return;
|
||||
|
|
@ -159,44 +155,44 @@ public static class PluginInstaller
|
|||
/// <returns>A Task representing the asynchronous uninstall operation.</returns>
|
||||
public static async Task UninstallPluginAndCheckRestartAsync(PluginMetadata oldPlugin)
|
||||
{
|
||||
if (API.PluginModified(oldPlugin.ID))
|
||||
if (PublicApi.Instance.PluginModified(oldPlugin.ID))
|
||||
{
|
||||
API.ShowMsgError(Localize.pluginModifiedAlreadyTitle(oldPlugin.Name),
|
||||
PublicApi.Instance.ShowMsgError(Localize.pluginModifiedAlreadyTitle(oldPlugin.Name),
|
||||
Localize.pluginModifiedAlreadyMessage());
|
||||
return;
|
||||
}
|
||||
|
||||
if (API.ShowMsgBox(
|
||||
if (PublicApi.Instance.ShowMsgBox(
|
||||
Localize.UninstallPromptSubtitle(oldPlugin.Name, oldPlugin.Author, Environment.NewLine),
|
||||
Localize.UninstallPromptTitle(),
|
||||
button: MessageBoxButton.YesNo) != MessageBoxResult.Yes) return;
|
||||
|
||||
var removePluginSettings = API.ShowMsgBox(
|
||||
var removePluginSettings = PublicApi.Instance.ShowMsgBox(
|
||||
Localize.KeepPluginSettingsSubtitle(),
|
||||
Localize.KeepPluginSettingsTitle(),
|
||||
button: MessageBoxButton.YesNo) == MessageBoxResult.No;
|
||||
|
||||
try
|
||||
{
|
||||
if (!await API.UninstallPluginAsync(oldPlugin, removePluginSettings))
|
||||
if (!await PublicApi.Instance.UninstallPluginAsync(oldPlugin, removePluginSettings))
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
API.LogException(ClassName, "Failed to uninstall plugin", e);
|
||||
API.ShowMsgError(Localize.ErrorUninstallingPlugin());
|
||||
PublicApi.Instance.LogException(ClassName, "Failed to uninstall plugin", e);
|
||||
PublicApi.Instance.ShowMsgError(Localize.ErrorUninstallingPlugin());
|
||||
return; // don not restart on failure
|
||||
}
|
||||
|
||||
if (Settings.AutoRestartAfterChanging)
|
||||
{
|
||||
API.RestartApp();
|
||||
PublicApi.Instance.RestartApp();
|
||||
}
|
||||
else
|
||||
{
|
||||
API.ShowMsg(
|
||||
PublicApi.Instance.ShowMsg(
|
||||
Localize.uninstallbtn(),
|
||||
Localize.UninstallSuccessNoRestart(oldPlugin.Name));
|
||||
}
|
||||
|
|
@ -210,7 +206,7 @@ public static class PluginInstaller
|
|||
/// <returns>A Task representing the asynchronous update operation.</returns>
|
||||
public static async Task UpdatePluginAndCheckRestartAsync(UserPlugin newPlugin, PluginMetadata oldPlugin)
|
||||
{
|
||||
if (API.ShowMsgBox(
|
||||
if (PublicApi.Instance.ShowMsgBox(
|
||||
Localize.UpdatePromptSubtitle(oldPlugin.Name, oldPlugin.Author, Environment.NewLine),
|
||||
Localize.UpdatePromptTitle(),
|
||||
button: MessageBoxButton.YesNo) != MessageBoxResult.Yes) return;
|
||||
|
|
@ -238,25 +234,25 @@ public static class PluginInstaller
|
|||
return;
|
||||
}
|
||||
|
||||
if (!await API.UpdatePluginAsync(oldPlugin, newPlugin, filePath))
|
||||
if (!await PublicApi.Instance.UpdatePluginAsync(oldPlugin, newPlugin, filePath))
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
API.LogException(ClassName, "Failed to update plugin", e);
|
||||
API.ShowMsgError(Localize.ErrorUpdatingPlugin());
|
||||
PublicApi.Instance.LogException(ClassName, "Failed to update plugin", e);
|
||||
PublicApi.Instance.ShowMsgError(Localize.ErrorUpdatingPlugin());
|
||||
return; // do not restart on failure
|
||||
}
|
||||
|
||||
if (Settings.AutoRestartAfterChanging)
|
||||
{
|
||||
API.RestartApp();
|
||||
PublicApi.Instance.RestartApp();
|
||||
}
|
||||
else
|
||||
{
|
||||
API.ShowMsg(
|
||||
PublicApi.Instance.ShowMsg(
|
||||
Localize.updatebtn(),
|
||||
Localize.UpdateSuccessNoRestart(newPlugin.Name));
|
||||
}
|
||||
|
|
@ -273,17 +269,17 @@ public static class PluginInstaller
|
|||
public static async Task CheckForPluginUpdatesAsync(Action<List<PluginUpdateInfo>> updateAllPlugins, bool silentUpdate = true, bool usePrimaryUrlOnly = false, CancellationToken token = default)
|
||||
{
|
||||
// Update the plugin manifest
|
||||
await API.UpdatePluginManifestAsync(usePrimaryUrlOnly, token);
|
||||
await PublicApi.Instance.UpdatePluginManifestAsync(usePrimaryUrlOnly, token);
|
||||
|
||||
// Get all plugins that can be updated
|
||||
var resultsForUpdate = (
|
||||
from existingPlugin in API.GetAllPlugins()
|
||||
join pluginUpdateSource in API.GetPluginManifest()
|
||||
from existingPlugin in PublicApi.Instance.GetAllPlugins()
|
||||
join pluginUpdateSource in PublicApi.Instance.GetPluginManifest()
|
||||
on existingPlugin.Metadata.ID equals pluginUpdateSource.ID
|
||||
where string.Compare(existingPlugin.Metadata.Version, pluginUpdateSource.Version,
|
||||
StringComparison.InvariantCulture) <
|
||||
0 // if current version precedes version of the plugin from update source (e.g. PluginsManifest)
|
||||
&& !API.PluginModified(existingPlugin.Metadata.ID)
|
||||
&& !PublicApi.Instance.PluginModified(existingPlugin.Metadata.ID)
|
||||
select
|
||||
new PluginUpdateInfo()
|
||||
{
|
||||
|
|
@ -302,19 +298,19 @@ public static class PluginInstaller
|
|||
{
|
||||
if (!silentUpdate)
|
||||
{
|
||||
API.ShowMsg(Localize.updateNoResultTitle(), Localize.updateNoResultSubtitle());
|
||||
PublicApi.Instance.ShowMsg(Localize.updateNoResultTitle(), Localize.updateNoResultSubtitle());
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// If all plugins are modified, just return
|
||||
if (resultsForUpdate.All(x => API.PluginModified(x.ID)))
|
||||
if (resultsForUpdate.All(x => PublicApi.Instance.PluginModified(x.ID)))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Show message box with button to update all plugins
|
||||
API.ShowMsgWithButton(
|
||||
PublicApi.Instance.ShowMsgWithButton(
|
||||
Localize.updateAllPluginsTitle(),
|
||||
Localize.updateAllPluginsButtonContent(),
|
||||
() =>
|
||||
|
|
@ -350,7 +346,7 @@ public static class PluginInstaller
|
|||
return;
|
||||
}
|
||||
|
||||
if (!await API.UpdatePluginAsync(plugin.PluginExistingMetadata, plugin.PluginNewUserPlugin, downloadToFilePath))
|
||||
if (!await PublicApi.Instance.UpdatePluginAsync(plugin.PluginExistingMetadata, plugin.PluginNewUserPlugin, downloadToFilePath))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
|
@ -359,8 +355,8 @@ public static class PluginInstaller
|
|||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
API.LogException(ClassName, "Failed to update plugin", e);
|
||||
API.ShowMsgError(Localize.ErrorUpdatingPlugin());
|
||||
PublicApi.Instance.LogException(ClassName, "Failed to update plugin", e);
|
||||
PublicApi.Instance.ShowMsgError(Localize.ErrorUpdatingPlugin());
|
||||
}
|
||||
}));
|
||||
|
||||
|
|
@ -368,11 +364,11 @@ public static class PluginInstaller
|
|||
|
||||
if (restart)
|
||||
{
|
||||
API.RestartApp();
|
||||
PublicApi.Instance.RestartApp();
|
||||
}
|
||||
else
|
||||
{
|
||||
API.ShowMsg(
|
||||
PublicApi.Instance.ShowMsg(
|
||||
Localize.updatebtn(),
|
||||
Localize.PluginsUpdateSuccessNoRestart());
|
||||
}
|
||||
|
|
@ -396,7 +392,7 @@ public static class PluginInstaller
|
|||
if (showProgress)
|
||||
{
|
||||
var exceptionHappened = false;
|
||||
await API.ShowProgressBoxAsync(progressBoxTitle,
|
||||
await PublicApi.Instance.ShowProgressBoxAsync(progressBoxTitle,
|
||||
async (reportProgress) =>
|
||||
{
|
||||
if (reportProgress == null)
|
||||
|
|
@ -408,18 +404,18 @@ public static class PluginInstaller
|
|||
}
|
||||
else
|
||||
{
|
||||
await API.HttpDownloadAsync(downloadUrl, filePath, reportProgress, cts.Token).ConfigureAwait(false);
|
||||
await PublicApi.Instance.HttpDownloadAsync(downloadUrl, filePath, reportProgress, cts.Token).ConfigureAwait(false);
|
||||
}
|
||||
}, cts.Cancel);
|
||||
|
||||
// if exception happened while downloading and user does not cancel downloading,
|
||||
// we need to redownload the plugin
|
||||
if (exceptionHappened && (!cts.IsCancellationRequested))
|
||||
await API.HttpDownloadAsync(downloadUrl, filePath, token: cts.Token).ConfigureAwait(false);
|
||||
await PublicApi.Instance.HttpDownloadAsync(downloadUrl, filePath, token: cts.Token).ConfigureAwait(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
await API.HttpDownloadAsync(downloadUrl, filePath, token: cts.Token).ConfigureAwait(false);
|
||||
await PublicApi.Instance.HttpDownloadAsync(downloadUrl, filePath, token: cts.Token).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -446,7 +442,7 @@ public static class PluginInstaller
|
|||
if (!Uri.TryCreate(url, UriKind.Absolute, out var uri) || uri.Host != acceptedHost)
|
||||
return false;
|
||||
|
||||
return API.GetAllPlugins().Any(x =>
|
||||
return PublicApi.Instance.GetAllPlugins().Any(x =>
|
||||
!string.IsNullOrEmpty(x.Metadata.Website) &&
|
||||
x.Metadata.Website.StartsWith(constructedUrlPart)
|
||||
);
|
||||
|
|
|
|||
|
|
@ -6,7 +6,6 @@ using System.Linq;
|
|||
using System.Text.Json;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using CommunityToolkit.Mvvm.DependencyInjection;
|
||||
using Flow.Launcher.Core.ExternalPlugins;
|
||||
using Flow.Launcher.Infrastructure;
|
||||
using Flow.Launcher.Infrastructure.DialogJump;
|
||||
|
|
@ -29,10 +28,6 @@ namespace Flow.Launcher.Core.Plugin
|
|||
public static readonly HashSet<PluginPair> GlobalPlugins = new();
|
||||
public static readonly Dictionary<string, PluginPair> NonGlobalPlugins = new();
|
||||
|
||||
// We should not initialize API in static constructor because it will create another API instance
|
||||
private static IPublicAPI api = null;
|
||||
private static IPublicAPI API => api ??= Ioc.Default.GetRequiredService<IPublicAPI>();
|
||||
|
||||
private static PluginsSettings Settings;
|
||||
private static readonly ConcurrentBag<string> ModifiedPlugins = new();
|
||||
|
||||
|
|
@ -75,12 +70,12 @@ namespace Flow.Launcher.Core.Plugin
|
|||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
API.LogException(ClassName, $"Failed to save plugin {pluginPair.Metadata.Name}", e);
|
||||
PublicApi.Instance.LogException(ClassName, $"Failed to save plugin {pluginPair.Metadata.Name}", e);
|
||||
}
|
||||
}
|
||||
|
||||
API.SavePluginSettings();
|
||||
API.SavePluginCaches();
|
||||
PublicApi.Instance.SavePluginSettings();
|
||||
PublicApi.Instance.SavePluginCaches();
|
||||
}
|
||||
|
||||
public static async ValueTask DisposePluginsAsync()
|
||||
|
|
@ -107,7 +102,7 @@ namespace Flow.Launcher.Core.Plugin
|
|||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
API.LogException(ClassName, $"Failed to dispose plugin {pluginPair.Metadata.Name}", e);
|
||||
PublicApi.Instance.LogException(ClassName, $"Failed to dispose plugin {pluginPair.Metadata.Name}", e);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -218,7 +213,7 @@ namespace Flow.Launcher.Core.Plugin
|
|||
{
|
||||
if (string.IsNullOrEmpty(metadata.AssemblyName))
|
||||
{
|
||||
API.LogWarn(ClassName, $"AssemblyName is empty for plugin with metadata: {metadata.Name}");
|
||||
PublicApi.Instance.LogWarn(ClassName, $"AssemblyName is empty for plugin with metadata: {metadata.Name}");
|
||||
continue; // Skip if AssemblyName is not set, which can happen for erroneous plugins
|
||||
}
|
||||
metadata.PluginSettingsDirectoryPath = Path.Combine(DataLocation.PluginSettingsDirectory, metadata.AssemblyName);
|
||||
|
|
@ -228,7 +223,7 @@ namespace Flow.Launcher.Core.Plugin
|
|||
{
|
||||
if (string.IsNullOrEmpty(metadata.Name))
|
||||
{
|
||||
API.LogWarn(ClassName, $"Name is empty for plugin with metadata: {metadata.Name}");
|
||||
PublicApi.Instance.LogWarn(ClassName, $"Name is empty for plugin with metadata: {metadata.Name}");
|
||||
continue; // Skip if Name is not set, which can happen for erroneous plugins
|
||||
}
|
||||
metadata.PluginSettingsDirectoryPath = Path.Combine(DataLocation.PluginSettingsDirectory, metadata.Name);
|
||||
|
|
@ -249,28 +244,28 @@ namespace Flow.Launcher.Core.Plugin
|
|||
{
|
||||
try
|
||||
{
|
||||
var milliseconds = await API.StopwatchLogDebugAsync(ClassName, $"Init method time cost for <{pair.Metadata.Name}>",
|
||||
() => pair.Plugin.InitAsync(new PluginInitContext(pair.Metadata, API)));
|
||||
var milliseconds = await PublicApi.Instance.StopwatchLogDebugAsync(ClassName, $"Init method time cost for <{pair.Metadata.Name}>",
|
||||
() => pair.Plugin.InitAsync(new PluginInitContext(pair.Metadata, PublicApi.Instance)));
|
||||
|
||||
pair.Metadata.InitTime += milliseconds;
|
||||
API.LogInfo(ClassName,
|
||||
PublicApi.Instance.LogInfo(ClassName,
|
||||
$"Total init cost for <{pair.Metadata.Name}> is <{pair.Metadata.InitTime}ms>");
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
API.LogException(ClassName, $"Fail to Init plugin: {pair.Metadata.Name}", e);
|
||||
PublicApi.Instance.LogException(ClassName, $"Fail to Init plugin: {pair.Metadata.Name}", e);
|
||||
if (pair.Metadata.Disabled && pair.Metadata.HomeDisabled)
|
||||
{
|
||||
// If this plugin is already disabled, do not show error message again
|
||||
// Or else it will be shown every time
|
||||
API.LogDebug(ClassName, $"Skipped init for <{pair.Metadata.Name}> due to error");
|
||||
PublicApi.Instance.LogDebug(ClassName, $"Skipped init for <{pair.Metadata.Name}> due to error");
|
||||
}
|
||||
else
|
||||
{
|
||||
pair.Metadata.Disabled = true;
|
||||
pair.Metadata.HomeDisabled = true;
|
||||
failedPlugins.Enqueue(pair);
|
||||
API.LogDebug(ClassName, $"Disable plugin <{pair.Metadata.Name}> because init failed");
|
||||
PublicApi.Instance.LogDebug(ClassName, $"Disable plugin <{pair.Metadata.Name}> because init failed");
|
||||
}
|
||||
}
|
||||
}));
|
||||
|
|
@ -298,7 +293,7 @@ namespace Flow.Launcher.Core.Plugin
|
|||
if (!failedPlugins.IsEmpty)
|
||||
{
|
||||
var failed = string.Join(",", failedPlugins.Select(x => x.Metadata.Name));
|
||||
API.ShowMsg(
|
||||
PublicApi.Instance.ShowMsg(
|
||||
Localize.failedToInitializePluginsTitle(),
|
||||
Localize.failedToInitializePluginsMessage(failed),
|
||||
"",
|
||||
|
|
@ -323,7 +318,7 @@ namespace Flow.Launcher.Core.Plugin
|
|||
if (dialogJump && plugin.Plugin is not IAsyncDialogJump)
|
||||
return Array.Empty<PluginPair>();
|
||||
|
||||
if (API.PluginModified(plugin.Metadata.ID))
|
||||
if (PublicApi.Instance.PluginModified(plugin.Metadata.ID))
|
||||
return Array.Empty<PluginPair>();
|
||||
|
||||
return new List<PluginPair>
|
||||
|
|
@ -344,7 +339,7 @@ namespace Flow.Launcher.Core.Plugin
|
|||
|
||||
try
|
||||
{
|
||||
var milliseconds = await API.StopwatchLogDebugAsync(ClassName, $"Cost for {metadata.Name}",
|
||||
var milliseconds = await PublicApi.Instance.StopwatchLogDebugAsync(ClassName, $"Cost for {metadata.Name}",
|
||||
async () => results = await pair.Plugin.QueryAsync(query, token).ConfigureAwait(false));
|
||||
|
||||
token.ThrowIfCancellationRequested();
|
||||
|
|
@ -388,7 +383,7 @@ namespace Flow.Launcher.Core.Plugin
|
|||
|
||||
try
|
||||
{
|
||||
var milliseconds = await API.StopwatchLogDebugAsync(ClassName, $"Cost for {metadata.Name}",
|
||||
var milliseconds = await PublicApi.Instance.StopwatchLogDebugAsync(ClassName, $"Cost for {metadata.Name}",
|
||||
async () => results = await ((IAsyncHomeQuery)pair.Plugin).HomeQueryAsync(token).ConfigureAwait(false));
|
||||
|
||||
token.ThrowIfCancellationRequested();
|
||||
|
|
@ -405,7 +400,7 @@ namespace Flow.Launcher.Core.Plugin
|
|||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
API.LogException(ClassName, $"Failed to query home for plugin: {metadata.Name}", e);
|
||||
PublicApi.Instance.LogException(ClassName, $"Failed to query home for plugin: {metadata.Name}", e);
|
||||
return null;
|
||||
}
|
||||
return results;
|
||||
|
|
@ -418,7 +413,7 @@ namespace Flow.Launcher.Core.Plugin
|
|||
|
||||
try
|
||||
{
|
||||
var milliseconds = await API.StopwatchLogDebugAsync(ClassName, $"Cost for {metadata.Name}",
|
||||
var milliseconds = await PublicApi.Instance.StopwatchLogDebugAsync(ClassName, $"Cost for {metadata.Name}",
|
||||
async () => results = await ((IAsyncDialogJump)pair.Plugin).QueryDialogJumpAsync(query, token).ConfigureAwait(false));
|
||||
|
||||
token.ThrowIfCancellationRequested();
|
||||
|
|
@ -435,7 +430,7 @@ namespace Flow.Launcher.Core.Plugin
|
|||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
API.LogException(ClassName, $"Failed to query Dialog Jump for plugin: {metadata.Name}", e);
|
||||
PublicApi.Instance.LogException(ClassName, $"Failed to query Dialog Jump for plugin: {metadata.Name}", e);
|
||||
return null;
|
||||
}
|
||||
return results;
|
||||
|
|
@ -502,7 +497,7 @@ namespace Flow.Launcher.Core.Plugin
|
|||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
API.LogException(ClassName,
|
||||
PublicApi.Instance.LogException(ClassName,
|
||||
$"Can't load context menus for plugin <{pluginPair.Metadata.Name}>",
|
||||
e);
|
||||
}
|
||||
|
|
@ -633,7 +628,7 @@ namespace Flow.Launcher.Core.Plugin
|
|||
{
|
||||
if (PluginModified(existingVersion.ID))
|
||||
{
|
||||
API.ShowMsgError(Localize.pluginModifiedAlreadyTitle(existingVersion.Name),
|
||||
PublicApi.Instance.ShowMsgError(Localize.pluginModifiedAlreadyTitle(existingVersion.Name),
|
||||
Localize.pluginModifiedAlreadyMessage());
|
||||
return false;
|
||||
}
|
||||
|
|
@ -666,7 +661,7 @@ namespace Flow.Launcher.Core.Plugin
|
|||
{
|
||||
if (checkModified && PluginModified(plugin.ID))
|
||||
{
|
||||
API.ShowMsgError(Localize.pluginModifiedAlreadyTitle(plugin.Name),
|
||||
PublicApi.Instance.ShowMsgError(Localize.pluginModifiedAlreadyTitle(plugin.Name),
|
||||
Localize.pluginModifiedAlreadyMessage());
|
||||
return false;
|
||||
}
|
||||
|
|
@ -686,14 +681,14 @@ namespace Flow.Launcher.Core.Plugin
|
|||
|
||||
if (string.IsNullOrEmpty(metadataJsonFilePath) || string.IsNullOrEmpty(pluginFolderPath))
|
||||
{
|
||||
API.ShowMsgError(Localize.failedToInstallPluginTitle(plugin.Name),
|
||||
PublicApi.Instance.ShowMsgError(Localize.failedToInstallPluginTitle(plugin.Name),
|
||||
Localize.fileNotFoundMessage(pluginFolderPath));
|
||||
return false;
|
||||
}
|
||||
|
||||
if (SameOrLesserPluginVersionExists(metadataJsonFilePath))
|
||||
{
|
||||
API.ShowMsgError(Localize.failedToInstallPluginTitle(plugin.Name),
|
||||
PublicApi.Instance.ShowMsgError(Localize.failedToInstallPluginTitle(plugin.Name),
|
||||
Localize.pluginExistAlreadyMessage());
|
||||
return false;
|
||||
}
|
||||
|
|
@ -723,7 +718,7 @@ namespace Flow.Launcher.Core.Plugin
|
|||
|
||||
var newPluginPath = Path.Combine(installDirectory, folderName);
|
||||
|
||||
FilesFolders.CopyAll(pluginFolderPath, newPluginPath, (s) => API.ShowMsgBox(s));
|
||||
FilesFolders.CopyAll(pluginFolderPath, newPluginPath, (s) => PublicApi.Instance.ShowMsgBox(s));
|
||||
|
||||
try
|
||||
{
|
||||
|
|
@ -732,7 +727,7 @@ namespace Flow.Launcher.Core.Plugin
|
|||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
API.LogException(ClassName, $"Failed to delete temp folder {tempFolderPluginPath}", e);
|
||||
PublicApi.Instance.LogException(ClassName, $"Failed to delete temp folder {tempFolderPluginPath}", e);
|
||||
}
|
||||
|
||||
if (checkModified)
|
||||
|
|
@ -747,7 +742,7 @@ namespace Flow.Launcher.Core.Plugin
|
|||
{
|
||||
if (checkModified && PluginModified(plugin.ID))
|
||||
{
|
||||
API.ShowMsgError(Localize.pluginModifiedAlreadyTitle(plugin.Name),
|
||||
PublicApi.Instance.ShowMsgError(Localize.pluginModifiedAlreadyTitle(plugin.Name),
|
||||
Localize.pluginModifiedAlreadyMessage());
|
||||
return false;
|
||||
}
|
||||
|
|
@ -767,7 +762,7 @@ namespace Flow.Launcher.Core.Plugin
|
|||
if (removePluginSettings)
|
||||
{
|
||||
// For dotnet plugins, we need to remove their PluginJsonStorage and PluginBinaryStorage instances
|
||||
if (AllowedLanguage.IsDotNet(plugin.Language) && API is IRemovable removable)
|
||||
if (AllowedLanguage.IsDotNet(plugin.Language) && PublicApi.Instance is IRemovable removable)
|
||||
{
|
||||
removable.RemovePluginSettings(plugin.AssemblyName);
|
||||
removable.RemovePluginCaches(plugin.PluginCacheDirectoryPath);
|
||||
|
|
@ -781,8 +776,8 @@ namespace Flow.Launcher.Core.Plugin
|
|||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
API.LogException(ClassName, $"Failed to delete plugin settings folder for {plugin.Name}", e);
|
||||
API.ShowMsgError(Localize.failedToRemovePluginSettingsTitle(),
|
||||
PublicApi.Instance.LogException(ClassName, $"Failed to delete plugin settings folder for {plugin.Name}", e);
|
||||
PublicApi.Instance.ShowMsgError(Localize.failedToRemovePluginSettingsTitle(),
|
||||
Localize.failedToRemovePluginSettingsMessage(plugin.Name));
|
||||
}
|
||||
}
|
||||
|
|
@ -797,8 +792,8 @@ namespace Flow.Launcher.Core.Plugin
|
|||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
API.LogException(ClassName, $"Failed to delete plugin cache folder for {plugin.Name}", e);
|
||||
API.ShowMsgError(Localize.failedToRemovePluginCacheTitle(),
|
||||
PublicApi.Instance.LogException(ClassName, $"Failed to delete plugin cache folder for {plugin.Name}", e);
|
||||
PublicApi.Instance.ShowMsgError(Localize.failedToRemovePluginCacheTitle(),
|
||||
Localize.failedToRemovePluginCacheMessage(plugin.Name));
|
||||
}
|
||||
Settings.RemovePluginSettings(plugin.ID);
|
||||
|
|
|
|||
|
|
@ -2,9 +2,6 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using CommunityToolkit.Mvvm.DependencyInjection;
|
||||
using Flow.Launcher.Core.ExternalPlugins.Environments;
|
||||
#pragma warning disable IDE0005
|
||||
using Flow.Launcher.Infrastructure.Logger;
|
||||
|
|
@ -18,10 +15,6 @@ namespace Flow.Launcher.Core.Plugin
|
|||
{
|
||||
private static readonly string ClassName = nameof(PluginsLoader);
|
||||
|
||||
// We should not initialize API in static constructor because it will create another API instance
|
||||
private static IPublicAPI api = null;
|
||||
private static IPublicAPI API => api ??= Ioc.Default.GetRequiredService<IPublicAPI>();
|
||||
|
||||
public static List<PluginPair> Plugins(List<PluginMetadata> metadatas, PluginsSettings settings)
|
||||
{
|
||||
var dotnetPlugins = DotNetPlugins(metadatas);
|
||||
|
|
@ -64,7 +57,7 @@ namespace Flow.Launcher.Core.Plugin
|
|||
|
||||
foreach (var metadata in metadatas)
|
||||
{
|
||||
var milliseconds = API.StopwatchLogDebug(ClassName, $"Constructor init cost for {metadata.Name}", () =>
|
||||
var milliseconds = PublicApi.Instance.StopwatchLogDebug(ClassName, $"Constructor init cost for {metadata.Name}", () =>
|
||||
{
|
||||
Assembly assembly = null;
|
||||
IAsyncPlugin plugin = null;
|
||||
|
|
@ -89,19 +82,19 @@ namespace Flow.Launcher.Core.Plugin
|
|||
#else
|
||||
catch (Exception e) when (assembly == null)
|
||||
{
|
||||
Log.Exception(ClassName, $"Couldn't load assembly for the plugin: {metadata.Name}", e);
|
||||
PublicApi.Instance.LogException(ClassName, $"Couldn't load assembly for the plugin: {metadata.Name}", e);
|
||||
}
|
||||
catch (InvalidOperationException e)
|
||||
{
|
||||
Log.Exception(ClassName, $"Can't find the required IPlugin interface for the plugin: <{metadata.Name}>", e);
|
||||
PublicApi.Instance.LogException(ClassName, $"Can't find the required IPlugin interface for the plugin: <{metadata.Name}>", e);
|
||||
}
|
||||
catch (ReflectionTypeLoadException e)
|
||||
{
|
||||
Log.Exception(ClassName, $"The GetTypes method was unable to load assembly types for the plugin: <{metadata.Name}>", e);
|
||||
PublicApi.Instance.LogException(ClassName, $"The GetTypes method was unable to load assembly types for the plugin: <{metadata.Name}>", e);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Log.Exception(ClassName, $"The following plugin has errored and can not be loaded: <{metadata.Name}>", e);
|
||||
PublicApi.Instance.LogException(ClassName, $"The following plugin has errored and can not be loaded: <{metadata.Name}>", e);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
@ -124,7 +117,7 @@ namespace Flow.Launcher.Core.Plugin
|
|||
Localize.pluginsHaveErrored():
|
||||
Localize.pluginHasErrored();
|
||||
|
||||
API.ShowMsgError($"{errorMessage}{Environment.NewLine}{Environment.NewLine}" +
|
||||
PublicApi.Instance.ShowMsgError($"{errorMessage}{Environment.NewLine}{Environment.NewLine}" +
|
||||
$"{errorPluginString}{Environment.NewLine}{Environment.NewLine}" +
|
||||
Localize.referToLogs());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,6 @@ using System.Linq;
|
|||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using CommunityToolkit.Mvvm.DependencyInjection;
|
||||
using Flow.Launcher.Core.Plugin;
|
||||
using Flow.Launcher.Infrastructure;
|
||||
using Flow.Launcher.Infrastructure.UserSettings;
|
||||
|
|
@ -18,10 +17,6 @@ namespace Flow.Launcher.Core.Resource
|
|||
{
|
||||
private static readonly string ClassName = nameof(Internationalization);
|
||||
|
||||
// We should not initialize API in static constructor because it will create another API instance
|
||||
private static IPublicAPI api = null;
|
||||
private static IPublicAPI API => api ??= Ioc.Default.GetRequiredService<IPublicAPI>();
|
||||
|
||||
private const string Folder = "Languages";
|
||||
private const string DefaultLanguageCode = "en";
|
||||
private const string DefaultFile = "en.xaml";
|
||||
|
|
@ -104,7 +99,7 @@ namespace Flow.Launcher.Core.Resource
|
|||
var directory = Path.Combine(Constant.ProgramDirectory, Folder);
|
||||
if (!Directory.Exists(directory))
|
||||
{
|
||||
API.LogError(ClassName, $"Flow Launcher language directory can't be found <{directory}>");
|
||||
PublicApi.Instance.LogError(ClassName, $"Flow Launcher language directory can't be found <{directory}>");
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -175,7 +170,7 @@ namespace Flow.Launcher.Core.Resource
|
|||
FirstOrDefault(o => o.LanguageCode.Equals(languageCode, StringComparison.OrdinalIgnoreCase));
|
||||
if (language == null)
|
||||
{
|
||||
API.LogError(ClassName, $"Language code can't be found <{languageCode}>");
|
||||
PublicApi.Instance.LogError(ClassName, $"Language code can't be found <{languageCode}>");
|
||||
return AvailableLanguages.English;
|
||||
}
|
||||
else
|
||||
|
|
@ -208,7 +203,7 @@ namespace Flow.Launcher.Core.Resource
|
|||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
API.LogException(ClassName, $"Failed to change language to <{language.LanguageCode}>", e);
|
||||
PublicApi.Instance.LogException(ClassName, $"Failed to change language to <{language.LanguageCode}>", e);
|
||||
}
|
||||
finally
|
||||
{
|
||||
|
|
@ -254,7 +249,7 @@ namespace Flow.Launcher.Core.Resource
|
|||
// "Do you want to search with pinyin?"
|
||||
string text = languageToSet == AvailableLanguages.Chinese ? "是否启用拼音搜索?" : "是否啓用拼音搜索?";
|
||||
|
||||
if (API.ShowMsgBox(text, string.Empty, MessageBoxButton.YesNo) == MessageBoxResult.No)
|
||||
if (PublicApi.Instance.ShowMsgBox(text, string.Empty, MessageBoxButton.YesNo) == MessageBoxResult.No)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
|
|
@ -311,7 +306,7 @@ namespace Flow.Launcher.Core.Resource
|
|||
}
|
||||
else
|
||||
{
|
||||
API.LogError(ClassName, $"Language path can't be found <{path}>");
|
||||
PublicApi.Instance.LogError(ClassName, $"Language path can't be found <{path}>");
|
||||
var english = Path.Combine(folder, DefaultFile);
|
||||
if (File.Exists(english))
|
||||
{
|
||||
|
|
@ -319,7 +314,7 @@ namespace Flow.Launcher.Core.Resource
|
|||
}
|
||||
else
|
||||
{
|
||||
API.LogError(ClassName, $"Default English Language path can't be found <{path}>");
|
||||
PublicApi.Instance.LogError(ClassName, $"Default English Language path can't be found <{path}>");
|
||||
return string.Empty;
|
||||
}
|
||||
}
|
||||
|
|
@ -354,7 +349,7 @@ namespace Flow.Launcher.Core.Resource
|
|||
}
|
||||
else
|
||||
{
|
||||
API.LogError(ClassName, $"No Translation for key {key}");
|
||||
PublicApi.Instance.LogError(ClassName, $"No Translation for key {key}");
|
||||
return $"No Translation for key {key}";
|
||||
}
|
||||
}
|
||||
|
|
@ -377,7 +372,7 @@ namespace Flow.Launcher.Core.Resource
|
|||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
API.LogException(ClassName, $"Failed for <{p.Metadata.Name}>", e);
|
||||
PublicApi.Instance.LogException(ClassName, $"Failed for <{p.Metadata.Name}>", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,15 +1,9 @@
|
|||
using System.ComponentModel;
|
||||
using CommunityToolkit.Mvvm.DependencyInjection;
|
||||
using Flow.Launcher.Plugin;
|
||||
|
||||
namespace Flow.Launcher.Core.Resource
|
||||
{
|
||||
public class LocalizedDescriptionAttribute : DescriptionAttribute
|
||||
{
|
||||
// We should not initialize API in static constructor because it will create another API instance
|
||||
private static IPublicAPI api = null;
|
||||
private static IPublicAPI API => api ??= Ioc.Default.GetRequiredService<IPublicAPI>();
|
||||
|
||||
private readonly string _resourceKey;
|
||||
|
||||
public LocalizedDescriptionAttribute(string resourceKey)
|
||||
|
|
@ -21,7 +15,7 @@ namespace Flow.Launcher.Core.Resource
|
|||
{
|
||||
get
|
||||
{
|
||||
string description = API.GetTranslation(_resourceKey);
|
||||
string description = PublicApi.Instance.GetTranslation(_resourceKey);
|
||||
return string.IsNullOrWhiteSpace(description) ?
|
||||
string.Format("[[{0}]]", _resourceKey) : description;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -58,21 +58,17 @@ namespace Flow.Launcher.Infrastructure.DialogJump
|
|||
|
||||
private static readonly Settings _settings = Ioc.Default.GetRequiredService<Settings>();
|
||||
|
||||
// We should not initialize API in static constructor because it will create another API instance
|
||||
private static IPublicAPI api = null;
|
||||
private static IPublicAPI API => api ??= Ioc.Default.GetRequiredService<IPublicAPI>();
|
||||
|
||||
private static HWND _mainWindowHandle = HWND.Null;
|
||||
|
||||
private static readonly Dictionary<DialogJumpExplorerPair, IDialogJumpExplorerWindow> _dialogJumpExplorers = new();
|
||||
|
||||
private static DialogJumpExplorerPair _lastExplorer = null;
|
||||
private static readonly object _lastExplorerLock = new();
|
||||
private static readonly Lock _lastExplorerLock = new();
|
||||
|
||||
private static readonly Dictionary<DialogJumpDialogPair, IDialogJumpDialogWindow> _dialogJumpDialogs = new();
|
||||
|
||||
private static IDialogJumpDialogWindow _dialogWindow = null;
|
||||
private static readonly object _dialogWindowLock = new();
|
||||
private static readonly Lock _dialogWindowLock = new();
|
||||
|
||||
private static HWINEVENTHOOK _foregroundChangeHook = HWINEVENTHOOK.Null;
|
||||
private static HWINEVENTHOOK _locationChangeHook = HWINEVENTHOOK.Null;
|
||||
|
|
@ -89,8 +85,8 @@ namespace Flow.Launcher.Infrastructure.DialogJump
|
|||
private static DispatcherTimer _dragMoveTimer = null;
|
||||
|
||||
// A list of all file dialog windows that are auto switched already
|
||||
private static readonly List<HWND> _autoSwitchedDialogs = new();
|
||||
private static readonly object _autoSwitchedDialogsLock = new();
|
||||
private static readonly List<HWND> _autoSwitchedDialogs = [];
|
||||
private static readonly Lock _autoSwitchedDialogsLock = new();
|
||||
|
||||
private static HWINEVENTHOOK _moveSizeHook = HWINEVENTHOOK.Null;
|
||||
private static readonly WINEVENTPROC _moveProc = MoveSizeCallBack;
|
||||
|
|
@ -315,7 +311,7 @@ namespace Flow.Launcher.Infrastructure.DialogJump
|
|||
{
|
||||
foreach (var explorer in _dialogJumpExplorers.Keys)
|
||||
{
|
||||
if (API.PluginModified(explorer.Metadata.ID) || // Plugin is modified
|
||||
if (PublicApi.Instance.PluginModified(explorer.Metadata.ID) || // Plugin is modified
|
||||
explorer.Metadata.Disabled) continue; // Plugin is disabled
|
||||
|
||||
var explorerWindow = explorer.Plugin.CheckExplorerWindow(hWnd);
|
||||
|
|
@ -493,7 +489,7 @@ namespace Flow.Launcher.Infrastructure.DialogJump
|
|||
var dialogWindowChanged = false;
|
||||
foreach (var dialog in _dialogJumpDialogs.Keys)
|
||||
{
|
||||
if (API.PluginModified(dialog.Metadata.ID) || // Plugin is modified
|
||||
if (PublicApi.Instance.PluginModified(dialog.Metadata.ID) || // Plugin is modified
|
||||
dialog.Metadata.Disabled) continue; // Plugin is disabled
|
||||
|
||||
IDialogJumpDialogWindow dialogWindow;
|
||||
|
|
@ -596,7 +592,7 @@ namespace Flow.Launcher.Infrastructure.DialogJump
|
|||
{
|
||||
foreach (var explorer in _dialogJumpExplorers.Keys)
|
||||
{
|
||||
if (API.PluginModified(explorer.Metadata.ID) || // Plugin is modified
|
||||
if (PublicApi.Instance.PluginModified(explorer.Metadata.ID) || // Plugin is modified
|
||||
explorer.Metadata.Disabled) continue; // Plugin is disabled
|
||||
|
||||
var explorerWindow = explorer.Plugin.CheckExplorerWindow(hwnd);
|
||||
|
|
@ -871,7 +867,7 @@ namespace Flow.Launcher.Infrastructure.DialogJump
|
|||
// Then check all dialog windows
|
||||
foreach (var dialog in _dialogJumpDialogs.Keys)
|
||||
{
|
||||
if (API.PluginModified(dialog.Metadata.ID) || // Plugin is modified
|
||||
if (PublicApi.Instance.PluginModified(dialog.Metadata.ID) || // Plugin is modified
|
||||
dialog.Metadata.Disabled) continue; // Plugin is disabled
|
||||
|
||||
var dialogWindow = _dialogJumpDialogs[dialog];
|
||||
|
|
@ -884,7 +880,7 @@ namespace Flow.Launcher.Infrastructure.DialogJump
|
|||
// Finally search for the dialog window again
|
||||
foreach (var dialog in _dialogJumpDialogs.Keys)
|
||||
{
|
||||
if (API.PluginModified(dialog.Metadata.ID) || // Plugin is modified
|
||||
if (PublicApi.Instance.PluginModified(dialog.Metadata.ID) || // Plugin is modified
|
||||
dialog.Metadata.Disabled) continue; // Plugin is disabled
|
||||
|
||||
IDialogJumpDialogWindow dialogWindow;
|
||||
|
|
@ -1067,11 +1063,8 @@ namespace Flow.Launcher.Infrastructure.DialogJump
|
|||
_navigationLock.Dispose();
|
||||
|
||||
// Stop drag move timer
|
||||
if (_dragMoveTimer != null)
|
||||
{
|
||||
_dragMoveTimer.Stop();
|
||||
_dragMoveTimer = null;
|
||||
}
|
||||
_dragMoveTimer?.Stop();
|
||||
_dragMoveTimer = null;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
|
|
|||
|
|
@ -4,10 +4,8 @@ using System.Net;
|
|||
using System.Net.Http;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using CommunityToolkit.Mvvm.DependencyInjection;
|
||||
using Flow.Launcher.Infrastructure.Logger;
|
||||
using Flow.Launcher.Infrastructure.UserSettings;
|
||||
using Flow.Launcher.Plugin;
|
||||
using JetBrains.Annotations;
|
||||
|
||||
namespace Flow.Launcher.Infrastructure.Http
|
||||
|
|
@ -20,10 +18,6 @@ namespace Flow.Launcher.Infrastructure.Http
|
|||
|
||||
private static readonly HttpClient client = new();
|
||||
|
||||
// We should not initialize API in static constructor because it will create another API instance
|
||||
private static IPublicAPI api = null;
|
||||
private static IPublicAPI API => api ??= Ioc.Default.GetRequiredService<IPublicAPI>();
|
||||
|
||||
static Http()
|
||||
{
|
||||
// need to be added so it would work on a win10 machine
|
||||
|
|
@ -82,7 +76,7 @@ namespace Flow.Launcher.Infrastructure.Http
|
|||
}
|
||||
catch (UriFormatException e)
|
||||
{
|
||||
API.ShowMsgError(Localize.pleaseTryAgain(), Localize.parseProxyFailed());
|
||||
PublicApi.Instance.ShowMsgError(Localize.pleaseTryAgain(), Localize.parseProxyFailed());
|
||||
Log.Exception(ClassName, "Unable to parse Uri", e);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,6 @@
|
|||
using System;
|
||||
using System.Text.Json.Serialization;
|
||||
using System.Threading.Tasks;
|
||||
using CommunityToolkit.Mvvm.DependencyInjection;
|
||||
using Flow.Launcher.Plugin;
|
||||
|
||||
namespace Flow.Launcher.Infrastructure.UserSettings
|
||||
{
|
||||
|
|
@ -55,11 +53,7 @@ namespace Flow.Launcher.Infrastructure.UserSettings
|
|||
{
|
||||
public string Description { get; set; }
|
||||
|
||||
public string LocalizedDescription => API.GetTranslation(Description);
|
||||
|
||||
// We should not initialize API in static constructor because it will create another API instance
|
||||
private static IPublicAPI api = null;
|
||||
private static IPublicAPI API => api ??= Ioc.Default.GetRequiredService<IPublicAPI>();
|
||||
public string LocalizedDescription => PublicApi.Instance.GetTranslation(Description);
|
||||
|
||||
public BaseBuiltinShortcutModel(string key, string description)
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in a new issue