v0.24.9 — Deploy _api/, fix WebView2 Program Files, DL robustness

Deploy auto de l'API PHP de stats (parallèle Report/Doc) :
- ApiToolDeployer : copy _api/ → C:\xampp\htdocs\proserve\ avec atomic
  rename + backups horodatés + revert + pruning. Strict clone du pattern
  DocToolDeployer.
- ApiToolConfig dans LocalConfig (default folder "proserve" en minuscule
  pour matcher l'install standard PROSERVE côté client).
- Settings → Avancés : section dédiée (HtdocsRoot, FolderName, AutoDeploy,
  MaxBackups, Re-déployer, liste backups + revert) + ApiBackupViewModel.
- DI registration dans App.xaml.cs, injection MainViewModel, appel
  post-install après le bloc Doc.
- 8 nouvelles strings i18n (5 langues).

Fix WebView2 vide en Program Files :
- Set WEBVIEW2_USER_DATA_FOLDER vers %LocalAppData%\PSLauncher\WebView2\
  dans App.OnStartup. Sans ça, WebView2 essaie d'écrire son cache à côté
  du .exe (read-only en Program Files) → init silencieusement KO →
  onglets Report/Doc vides.

Refresh auto WebView2 sur navigation d'onglet :
- Hook IsVisibleChanged sur ReportWebView et DocsWebView. À chaque
  ré-affichage, CoreWebView2.Reload() pour voir les données serveur à
  jour. Le binding Source garde la nav initiale au cold start.

Fix UI : Cancel décalant le footer pendant Check updates :
- Nouveau flag IsDownloadActive distinct de IsBusy. Visibility du bouton
  Cancel passe de IsBusy → IsDownloadActive : couvre uniquement les DL,
  plus aucune apparition pendant Check updates / Install / Uninstall /
  Self-update qui décalait tout le layout 1 s.

DL robustness (multi-PC) :
- SafeInstallAsync : error boundary sur l'install handler. Plus aucune
  exception silencieuse — log + popup d'erreur visible (résout les cas
  "le 2e PC ne démarre pas, sans message").
- DownloadManager : vérif explicite que CHAQUE segment a Completed=true
  && DownloadedBytes >= Length AVANT le SHA-256. Le check actualSize
  était inutile (fichier sparse-préalloué).
- MaxRetryAttempts Polly 6 → 10 pour absorber les outages PHP-FPM
  request_terminate_timeout sous charge multi-PC.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-05-04 13:53:13 +02:00
parent 9de8e95910
commit 7de0c01b97
13 changed files with 693 additions and 8 deletions

View File

@@ -17,6 +17,7 @@ using PSLauncher.Core.Installations;
using PSLauncher.Core.Licensing;
using PSLauncher.Core.Localization;
using PSLauncher.Core.Manifests;
using PSLauncher.Core.ApiTool;
using PSLauncher.Core.DocTool;
using PSLauncher.Core.Health;
using PSLauncher.Core.Migrations;
@@ -49,6 +50,7 @@ public sealed partial class MainViewModel : ObservableObject
private readonly IDatabaseMigrationService _migrationService;
private readonly IReportToolDeployer _reportDeployer;
private readonly IDocToolDeployer _docDeployer;
private readonly IApiToolDeployer _apiDeployer;
private readonly ISystemHealthService _healthService;
private readonly IServiceProvider _serviceProvider;
private readonly ILogger<MainViewModel> _logger;
@@ -112,6 +114,15 @@ public sealed partial class MainViewModel : ObservableObject
[NotifyCanExecuteChangedFor(nameof(CheckForUpdatesCommand))]
private bool _isBusy;
/// <summary>
/// Flag dédié au téléchargement en cours, distinct de <see cref="IsBusy"/> qui
/// couvre AUSSI Check updates / Install / Uninstall / Self-update. Sert à scoper
/// la visibilité du bouton "Annuler" du footer aux seuls DL — sinon il apparaît
/// 1 s pendant un Check updates et décale tout le layout.
/// </summary>
[ObservableProperty]
private bool _isDownloadActive;
[ObservableProperty] private double _progressPercent;
/// <summary>
@@ -311,6 +322,7 @@ public sealed partial class MainViewModel : ObservableObject
IDatabaseMigrationService migrationService,
IReportToolDeployer reportDeployer,
IDocToolDeployer docDeployer,
IApiToolDeployer apiDeployer,
ISystemHealthService healthService,
IServiceProvider serviceProvider,
ILogger<MainViewModel> logger)
@@ -329,6 +341,7 @@ public sealed partial class MainViewModel : ObservableObject
_migrationService = migrationService;
_reportDeployer = reportDeployer;
_docDeployer = docDeployer;
_apiDeployer = apiDeployer;
_healthService = healthService;
_serviceProvider = serviceProvider;
_logger = logger;
@@ -516,13 +529,43 @@ public sealed partial class MainViewModel : ObservableObject
private void WireRowHandlers(VersionRowViewModel row)
{
row.LaunchHandler = LaunchVersion;
row.InstallHandler = r => _activeInstallTask = InstallVersionAsync(r);
// Wrap InstallVersionAsync via SafeInstallAsync : sans ça, une exception
// levée AVANT le premier await (ex. ThemedMessageBox.Show dans le check
// "IsBusy") tomberait dans le vide (handler sync void) et la UI resterait
// figée sans message — exactement le symptôme "le 2e PC ne démarre pas".
row.InstallHandler = r => _activeInstallTask = SafeInstallAsync(r);
row.UninstallHandler = r => _ = UninstallVersionAsync(r);
row.ShowReleaseNotesHandler = r => _ = ShowReleaseNotesAsync(r);
row.OpenFolderHandler = OpenVersionFolder;
row.RestartFromZeroHandler = r => _ = RestartFromZeroAsync(r);
}
/// <summary>
/// Error boundary autour de <see cref="InstallVersionAsync"/>. Garantit qu'aucune
/// exception ne disparaît silencieusement (cas du fire-and-forget pré-0.24.6 où
/// le launcher pouvait rester figé sur un click sans aucun feedback).
/// </summary>
private async Task SafeInstallAsync(VersionRowViewModel row)
{
try
{
await InstallVersionAsync(row);
}
catch (Exception ex)
{
_logger.LogError(ex, "InstallVersionAsync unhandled exception (row={Version})", row.Version);
StatusMessage = Strings.StatusError(ex.Message);
try
{
ThemedMessageBox.Show(
Strings.MsgInstallFailed(ex.Message),
Strings.MsgBoxError,
MessageBoxButton.OK, MessageBoxImage.Error);
}
catch { /* dialog peut échouer si on est en train de quitter */ }
}
}
[RelayCommand(CanExecute = nameof(CanCheckUpdates))]
private async Task CheckForUpdatesAsync()
{
@@ -826,6 +869,7 @@ public sealed partial class MainViewModel : ObservableObject
if (IsBusy) { ThemedMessageBox.Show(Strings.MsgBusy, Strings.MsgBoxPatience, MessageBoxButton.OK, MessageBoxImage.Information); return; }
IsBusy = true;
IsDownloadActive = true;
_activeRow = row;
_activeDownloadCts = new CancellationTokenSource();
var ct = _activeDownloadCts.Token;
@@ -1059,6 +1103,49 @@ public sealed partial class MainViewModel : ObservableObject
}
}
// 8) Déploiement de l'API PHP de stats (parallèle à Report/Doc).
// Cherche _api/ dans le ZIP extrait et copie vers htdocs en
// atomic rename. Skip silencieux si _api/ absent du ZIP.
if (_config.ApiTool.AutoDeploy)
{
StatusMessage = Strings.StatusDeployingApi(row.Version);
ProgressDetail = null;
ProgressPercent = 0;
var apProgress = new Progress<DeployProgress>(dp =>
{
if (dp.FilesTotal > 0)
{
var pct = (double)dp.FilesDone / dp.FilesTotal * 100.0;
ProgressPercent = pct;
row.ProgressPercent = pct;
}
var label = Strings.ProgressApiDeploy(dp.FilesDone, dp.FilesTotal, dp.CurrentFilename);
ProgressDetail = label;
row.ProgressDetail = label;
});
var apResult = await _apiDeployer.DeployAsync(target, apProgress, ct);
switch (apResult.Status)
{
case DeployStatus.Deployed:
_logger.LogInformation("Api tool deployed ({N} files) for v{Version}", apResult.FilesDeployed, row.Version);
break;
case DeployStatus.SkippedNoSourceFolder:
_logger.LogInformation("No _api/ in v{Version} ZIP, api tool unchanged", row.Version);
break;
case DeployStatus.XamppNotFound:
// Idem Doc : warning XAMPP déjà éventuellement affiché par Report,
// on log silencieusement pour ne pas multiplier les popups identiques.
_logger.LogWarning("Api tool deploy : XAMPP htdocs not found at {Root}", _config.ApiTool.HtdocsRoot);
break;
case DeployStatus.Failed:
ThemedMessageBox.Show(
Strings.MsgApiDeployFailed(apResult.ErrorMessage ?? "?"),
Strings.MsgBoxApiDeployFailed,
MessageBoxButton.OK, MessageBoxImage.Warning);
break;
}
}
StatusMessage = Strings.StatusInstalledSuccess(row.Version);
ProgressDetail = null;
ProgressPercent = 0;
@@ -1100,6 +1187,7 @@ public sealed partial class MainViewModel : ObservableObject
_activeRow = null;
_activeInstallTask = null;
IsBusy = false;
IsDownloadActive = false;
}
}