Add a synchronous signal handler for graceful shutdown

This commit is contained in:
Pierre Tachoire
2025-12-29 12:43:52 +01:00
parent f4961ee8b2
commit 4684b8611d
4 changed files with 163 additions and 51 deletions

View File

@@ -40,6 +40,7 @@ telemetry: Telemetry,
allocator: Allocator,
app_dir_path: ?[]const u8,
notification: *Notification,
shutdown: bool = false,
pub const RunMode = enum {
help,
@@ -99,9 +100,14 @@ pub fn init(allocator: Allocator, config: Config) !*App {
}
pub fn deinit(self: *App) void {
if (@atomicRmw(bool, &self.shutdown, .Xchg, true, .monotonic)) {
return;
}
const allocator = self.allocator;
if (self.app_dir_path) |app_dir_path| {
allocator.free(app_dir_path);
self.app_dir_path = null;
}
self.telemetry.deinit();
self.notification.deinit();