插件市场安装优化
This commit is contained in:
lincube
2026-03-11 06:38:11 +08:00
parent 5003ff1be2
commit 2781d7e0d9
17 changed files with 907 additions and 89 deletions

View File

@@ -13,6 +13,7 @@ namespace LanMountainDesktop.Views.SettingsPages;
internal sealed class AirAppMarketInstallService : IDisposable
{
private readonly PluginRuntimeService _runtime;
private readonly PluginsInstallHelperClient _helperClient = new();
private readonly HttpClient _httpClient;
private readonly ResumableDownloadService _downloadService;
private readonly AirAppMarketReleaseResolverService _releaseResolverService;
@@ -89,7 +90,28 @@ internal sealed class AirAppMarketInstallService : IDisposable
$"SHA-256 mismatch. Expected {plugin.Sha256}, actual {actualHash}.");
}
var manifest = _runtime.InstallPluginPackage(downloadPath);
PluginManifest manifest;
if (OperatingSystem.IsWindows())
{
var helperResult = await _helperClient.InstallPackageAsync(
downloadPath,
_runtime.PluginsDirectory,
cancellationToken);
if (!helperResult.Success || string.IsNullOrWhiteSpace(helperResult.InstalledPackagePath))
{
return new AirAppMarketInstallResult(
false,
null,
helperResult.ErrorMessage ?? "Plugins install helper failed.");
}
manifest = _runtime.RegisterInstalledPluginPackage(helperResult.InstalledPackagePath);
}
else
{
manifest = _runtime.InstallPluginPackage(downloadPath);
}
AppLogger.Info(
"PluginMarket",
$"Install staged successfully. PluginId='{manifest.Id}'; InstalledName='{manifest.Name}'; PackagePath='{downloadPath}'.");

View File

@@ -196,6 +196,14 @@ public sealed class PluginRuntimeService : IDisposable
}
}
public PluginManifest RegisterInstalledPluginPackage(string packagePath)
{
lock (_packageMutationGate)
{
return RegisterInstalledPluginPackageCore(packagePath);
}
}
public bool DeleteInstalledPlugin(string pluginId)
{
lock (_packageMutationGate)
@@ -288,6 +296,25 @@ public sealed class PluginRuntimeService : IDisposable
return new PluginPackageInstallResult(manifest, replacedExisting, RestartRequired: true);
}
private PluginManifest RegisterInstalledPluginPackageCore(string packagePath)
{
ArgumentException.ThrowIfNullOrWhiteSpace(packagePath);
var fullPackagePath = Path.GetFullPath(packagePath);
if (!File.Exists(fullPackagePath))
{
throw new FileNotFoundException($"Plugin package '{fullPackagePath}' was not found.", fullPackagePath);
}
var manifest = ReadManifestFromPackage(fullPackagePath);
AppLogger.Info(
"PluginRuntime",
$"Registering externally installed package. PluginId='{manifest.Id}'; Source='{fullPackagePath}'.");
UpdateCatalogAfterPackageInstall(manifest, fullPackagePath);
PendingRestartStateService.SetPending(PendingRestartStateService.PluginCatalogReason, true);
return manifest;
}
public void Dispose()
{
UnloadInstalledPlugins();