Skip to content

PR: Sub Issue 11+12 - GracefulExit utility#332

Merged
JusterZhu merged 3 commits into
masterfrom
feature/aot-resource
May 24, 2026
Merged

PR: Sub Issue 11+12 - GracefulExit utility#332
JusterZhu merged 3 commits into
masterfrom
feature/aot-resource

Conversation

@JusterZhu
Copy link
Copy Markdown
Collaborator

Summary

Closes #331

Changes

  • \GracefulExit.ShutdownAsync()\ — graceful shutdown (CloseMainWindow + timeout + Kill fallback)
  • \GracefulExit.CurrentProcessAsync()\ — shutdown current process

Replaces raw \Process.Kill()\ calls throughout the codebase.

Build

✅ 0 errors

JusterZhu added 3 commits May 24, 2026 08:10
- StorageManager.Restore() — restore from backup to install path
- StorageManager.CleanBackup() — keep only N most recent backups
- StorageManager.ListBackups() — query backup metadata
- BackupConfig — version retention, skip dirs, enable/disable
- BackupInfo record — version, path, timestamp, size

Closes #327
…ooks

- IUpdateHooks interface with 5 lifecycle callbacks
- UpdateContext / DownloadContext records
- NoOpUpdateHooks (default pass-through)
- UnixPermissionHooks: chmod +x for Linux/macOS
- CustomPermissionHooks: user-supplied permission script

Closes #329
- CloseMainWindow() + timeout fallback to Kill()
- Current process shutdown helper
- Replaces raw Process.Kill() calls across the codebase

Closes #331
Copilot AI review requested due to automatic review settings May 24, 2026 00:11
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Introduces new lifecycle-hook abstractions and a GracefulExit helper intended to replace raw Process.Kill() usage, and extends StorageManager with backup-related utilities.

Changes:

  • Add GracefulExit utility for graceful process shutdown with timeout + kill fallback.
  • Add IUpdateHooks plus default/no-op and permission-related hook implementations.
  • Add backup restore/list/cleanup helpers plus backup metadata/config types in StorageManager.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 9 comments.

File Description
src/c#/GeneralUpdate.Core/Hooks/IUpdateHooks.cs Adds hook interface + contexts and default/permission hook implementations.
src/c#/GeneralUpdate.Core/GracefulExit.cs Adds process shutdown helper intended to replace direct Process.Kill().
src/c#/GeneralUpdate.Core/FileSystem/StorageManager.cs Adds backup restore/retention/listing helpers and backup metadata/config types.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +14 to +18
if (process == null || process.HasExited) return;
if (!process.CloseMainWindow())
await Task.Delay(timeoutMs).ConfigureAwait(false);
if (!process.HasExited)
process.Kill(); // Last resort
/// <summary>Shutdown the current process gracefully.</summary>
public static async Task CurrentProcessAsync(int timeoutMs = 3000)
{
var p = Process.GetCurrentProcess();
using System.Diagnostics;
using System.IO;
using System.Threading.Tasks;
using GeneralUpdate.Core.Configuration;
Comment on lines +49 to +54
public async Task OnBeforeStartAppAsync(UpdateContext ctx)
{
var mainApp = Path.Combine(ctx.InstallPath, ctx.AppName);
if (File.Exists(mainApp))
await Process.Start("chmod", $"+x \"{mainApp}\"").WaitForExitAsync();
}
Comment on lines +74 to +78
using var proc = Process.Start(psi)!;
await proc.WaitForExitAsync();
if (proc.ExitCode != 0)
throw new InvalidOperationException(
$"Permission script '{_scriptPath}' failed (exit {proc.ExitCode})");
private void ResetId() => Interlocked.Exchange(ref _fileCount, 0);

/// <summary>Restore files from backup directory to install path.</summary>
public static void Restore(string backupDir, string installPath)
Comment on lines +292 to +295
foreach (var file in Directory.GetFiles(backupDir, "*", SearchOption.AllDirectories))
{
var relativePath = file.Substring(backupDir.Length).TrimStart(Path.DirectorySeparatorChar);
var dest = Path.Combine(installPath, relativePath);
Comment on lines +301 to +310
/// <summary>Clean old backups, keeping only the N most recent versions.</summary>
public static void CleanBackup(string installPath, int keepVersions = 3)
{
var backupRoot = Path.Combine(installPath, "__backups");
if (!Directory.Exists(backupRoot)) return;

var dirs = Directory.GetDirectories(backupRoot)
.Select(d => new DirectoryInfo(d))
.OrderByDescending(d => d.CreationTime)
.Skip(keepVersions);
Comment on lines +307 to +310
var dirs = Directory.GetDirectories(backupRoot)
.Select(d => new DirectoryInfo(d))
.OrderByDescending(d => d.CreationTime)
.Skip(keepVersions);
@JusterZhu JusterZhu merged commit 4a8fe99 into master May 24, 2026
1 check passed
@JusterZhu JusterZhu deleted the feature/aot-resource branch May 24, 2026 00:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Sub Issue 11+12: AOT compatibility markers + GracefulExit + Dispose cleanup

2 participants