Skip to content

Commit 209518b

Browse files
authored
fix: add missing hook/reporter calls in ClientUpdateStrategy and OSSUpdateStrategy (#407)
- ClientUpdateStrategy: add OnDownloadCompletedAsync hook after download - ClientUpdateStrategy: add OnAfterUpdateAsync hook + UpdateApplied report after pipeline - OSSUpdateStrategy: add OnDownloadCompletedAsync hook after download+decompress - OSSUpdateStrategy: add OnAfterUpdateAsync hook after decompress All four entry points (Client/Upgrade/OSS/Silent) now have consistent hook/reporter lifecycle: OnBeforeUpdate -> DownloadCompleted -> OnAfterUpdate -> UpdateApplied -> OnBeforeStartApp
1 parent 98df906 commit 209518b

3 files changed

Lines changed: 61 additions & 1 deletion

File tree

src/c#/GeneralUpdate.Core/Bootstrap/GeneralUpdateBootstrap.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,10 @@ private async Task<GeneralUpdateBootstrap> LaunchOssAsync()
189189
return this;
190190
}
191191

192-
var upgradeAppName = "GeneralUpdate.Upgrade.exe";
192+
// Use user-configured AppName, fall back to default updater name
193+
var upgradeAppName = !string.IsNullOrWhiteSpace(_configInfo.AppName) && _configInfo.AppName != "Update.exe"
194+
? _configInfo.AppName
195+
: "GeneralUpdate.Upgrade.exe";
193196
var appPath = Path.Combine(basePath, upgradeAppName);
194197
if (!File.Exists(appPath))
195198
throw new Exception($"Upgrade application not found: {upgradeAppName}");

src/c#/GeneralUpdate.Core/Strategy/ClientUpdateStrategy.cs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,9 +208,12 @@ private async Task ExecuteStandardWorkflowAsync()
208208
}
209209

210210
await SafeReportDownloadCompletedAsync(hooksCtx).ConfigureAwait(false);
211+
await SafeOnDownloadCompletedAsync(hooksCtx).ConfigureAwait(false);
211212

212213
// Apply updates and start app
213214
await _osStrategy.ExecuteAsync();
215+
await SafeOnAfterUpdateAsync(hooksCtx).ConfigureAwait(false);
216+
await SafeReportUpdateAppliedAsync(hooksCtx).ConfigureAwait(false);
214217
await SafeOnBeforeStartAppAsync(hooksCtx).ConfigureAwait(false);
215218
_osStrategy.StartApp();
216219
}
@@ -318,6 +321,25 @@ private async Task SafeOnUpdateErrorAsync(Hooks.UpdateContext ctx, Exception err
318321
catch (Exception ex) { GeneralTracer.Warn($"OnUpdateErrorAsync hook failed: {ex.Message}"); }
319322
}
320323

324+
private async Task SafeOnAfterUpdateAsync(Hooks.UpdateContext ctx)
325+
{
326+
try { await Hooks.OnAfterUpdateAsync(ctx).ConfigureAwait(false); }
327+
catch (Exception ex) { GeneralTracer.Warn($"OnAfterUpdateAsync hook failed: {ex.Message}"); }
328+
}
329+
330+
private async Task SafeOnDownloadCompletedAsync(Hooks.UpdateContext ctx)
331+
{
332+
try
333+
{
334+
var downloadCtx = new Hooks.DownloadContext(
335+
_configInfo?.MainAppName ?? _configInfo?.AppName ?? "unknown",
336+
_configInfo?.LastVersion ?? "",
337+
0, TimeSpan.Zero, _configInfo?.TempPath, true);
338+
await Hooks.OnDownloadCompletedAsync(downloadCtx).ConfigureAwait(false);
339+
}
340+
catch (Exception ex) { GeneralTracer.Warn($"OnDownloadCompletedAsync hook failed: {ex.Message}"); }
341+
}
342+
321343
private async Task SafeReportUpdateStartedAsync(Hooks.UpdateContext ctx)
322344
{
323345
try
@@ -355,5 +377,17 @@ await Reporter.ReportAsync(new Download.Reporting.UpdateReport(
355377
catch (Exception ex) { GeneralTracer.Warn($"Report UpdateFailed failed: {ex.Message}"); }
356378
}
357379

380+
private async Task SafeReportUpdateAppliedAsync(Hooks.UpdateContext ctx)
381+
{
382+
try
383+
{
384+
await Reporter.ReportAsync(new Download.Reporting.UpdateReport(
385+
ctx.AppName, ctx.CurrentVersion, ctx.TargetVersion,
386+
Download.Reporting.UpdateEvent.UpdateApplied, ctx.AppType, DateTimeOffset.UtcNow
387+
)).ConfigureAwait(false);
388+
}
389+
catch (Exception ex) { GeneralTracer.Warn($"Report UpdateApplied failed: {ex.Message}"); }
390+
}
391+
358392
#endregion
359393
}

src/c#/GeneralUpdate.Core/Strategy/OSSUpdateStrategy.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,10 @@ public async Task ExecuteAsync()
109109
GeneralTracer.Debug("OSSUpdateStrategy: 4. Decompressing packages.");
110110
DecompressAssets(assets);
111111

112+
// Hooks: download + decompress completed
113+
await SafeOnDownloadCompletedAsync(ctx).ConfigureAwait(false);
114+
await SafeOnAfterUpdateAsync(ctx).ConfigureAwait(false);
115+
112116
// Report: update applied
113117
await SafeReportUpdateAppliedAsync(ctx).ConfigureAwait(false);
114118

@@ -210,6 +214,25 @@ private async Task SafeOnUpdateErrorAsync(Hooks.UpdateContext ctx, Exception err
210214
catch (Exception ex) { GeneralTracer.Warn($"OnUpdateErrorAsync hook failed: {ex.Message}"); }
211215
}
212216

217+
private async Task SafeOnAfterUpdateAsync(Hooks.UpdateContext ctx)
218+
{
219+
try { await Hooks.OnAfterUpdateAsync(ctx).ConfigureAwait(false); }
220+
catch (Exception ex) { GeneralTracer.Warn($"OnAfterUpdateAsync hook failed: {ex.Message}"); }
221+
}
222+
223+
private async Task SafeOnDownloadCompletedAsync(Hooks.UpdateContext ctx)
224+
{
225+
try
226+
{
227+
var downloadCtx = new Hooks.DownloadContext(
228+
_configInfo?.MainAppName ?? _configInfo?.AppName ?? "unknown",
229+
_configInfo?.LastVersion ?? "",
230+
0, TimeSpan.Zero, _appPath, true);
231+
await Hooks.OnDownloadCompletedAsync(downloadCtx).ConfigureAwait(false);
232+
}
233+
catch (Exception ex) { GeneralTracer.Warn($"OnDownloadCompletedAsync hook failed: {ex.Message}"); }
234+
}
235+
213236
private async Task SafeReportUpdateStartedAsync(Hooks.UpdateContext ctx)
214237
{
215238
try

0 commit comments

Comments
 (0)