From 7c5a7cde26e40f5a02403f395d17a98a589eabf8 Mon Sep 17 00:00:00 2001 From: Daisuke Murase Date: Thu, 7 May 2026 10:35:20 -0700 Subject: [PATCH] fix: guard against nil CFUUIDCreateString result in detectFullscreenDisplays CFUUIDCreateString returns CFString! (implicitly unwrapped optional) and can return nil when CGDisplayCreateUUIDFromDisplayID produces an invalid UUID during display state transitions (space switches, fullscreen app entry/exit). The activeSpaceDidChange notification fires exactly at these transient moments, making it the trigger for the crash. Replace the implicit 'as CFString' force- unwrap with guard let so invalid displays are skipped instead of crashing. --- Cargo.lock | 6 +++--- app/Sources/BarViewModel.swift | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 31d65df..95898c0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -452,7 +452,7 @@ checksum = "69cdb34c158ceb288df11e18b4bd39de994f6657d83847bdffdbd7f346754b0f" [[package]] name = "ranma-cli" -version = "0.1.10" +version = "0.1.11" dependencies = [ "argh", "libc", @@ -462,7 +462,7 @@ dependencies = [ [[package]] name = "ranma-core" -version = "0.1.10" +version = "0.1.11" dependencies = [ "parking_lot", "serde", @@ -737,7 +737,7 @@ dependencies = [ [[package]] name = "uniffi-bindgen" -version = "0.1.10" +version = "0.1.11" dependencies = [ "uniffi", ] diff --git a/app/Sources/BarViewModel.swift b/app/Sources/BarViewModel.swift index 0932b4f..717ba68 100644 --- a/app/Sources/BarViewModel.swift +++ b/app/Sources/BarViewModel.swift @@ -207,7 +207,7 @@ final class BarViewModel: StateChangeHandler, @unchecked Sendable { for screen in NSScreen.screens { let displayID = screen.displayID let uuid = CGDisplayCreateUUIDFromDisplayID(displayID).takeRetainedValue() - let uuidString = CFUUIDCreateString(nil, uuid) as CFString + guard let uuidString = CFUUIDCreateString(nil, uuid) else { continue } let spaceID = SLSManagedDisplayGetCurrentSpace(cid, uuidString) if spaceID != 0 && SLSSpaceGetType(cid, spaceID) == 4 {