From 0b9cbef57cec936d423fea5af3100f393435e2c3 Mon Sep 17 00:00:00 2001 From: Grishka Date: Mon, 3 Feb 2025 19:05:18 +0300 Subject: [PATCH] Fix resource leak on macOS Sonoma --- MatrixView.m | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/MatrixView.m b/MatrixView.m index 11500b0..6e19816 100644 --- a/MatrixView.m +++ b/MatrixView.m @@ -130,6 +130,21 @@ - (instancetype)initWithFrame:(NSRect)frame isPreview:(BOOL)previewmode saverParams.framesPerLivingCellChange = 3; saverParams.minDepth = CLIP_NEAR; saverParams.spawnChance = 0.2; + + // Work around the API contract breakage introduced by Apple in macOS Sonoma + // https://www.jwz.org/blog/2023/10/xscreensaver-6-08-out-now/ + if (@available(macOS 14, *)) { + if (!isPreview) { + [[NSDistributedNotificationCenter defaultCenter] + addObserverForName: @"com.apple.screensaver.willstop" + object: nil + queue: nil + usingBlock:^(NSNotification *n) { + [[NSApplication sharedApplication] terminate: self]; + }]; + } + } + return self; }