Commit 31fd9db0 authored by Kourser's avatar Kourser
Browse files

fix(macos): keep the key event out of the main-actor closure

The macOS 27.1 SDK flags returning the NSEvent, which is not Sendable,
from MainActor.assumeIsolated. The closure now answers whether it
consumed the space bar, and the monitor returns the event itself.

Co-Authored-By: default avatarClaude Opus 5.5 <noreply@anthropic.com>
parent 000d6fcd
Loading
Loading
Loading
Loading
+8 −5
Changes for Skingomz/MacAppDelegate.swift: 8 added lines, 5 removed lines.
Original line number Diff line number Diff line
@@ -23,15 +23,18 @@ final class MacAppDelegate: NSObject, NSApplicationDelegate {

    func applicationDidFinishLaunching(_ notification: Notification) {
        spaceKeyMonitor = NSEvent.addLocalMonitorForEvents(matching: .keyDown) { event in
            MainActor.assumeIsolated {
            guard event.charactersIgnoringModifiers == " ",
                      event.modifierFlags.intersection([.command, .option, .control, .shift]).isEmpty,
                      !(NSApp.keyWindow?.firstResponder is NSTextView), // typing a space
                      let playback = Self.playback, playback.currentEpisode != nil
                  event.modifierFlags.intersection([.command, .option, .control, .shift]).isEmpty
            else { return event }
            // The event (not Sendable) stays out of the isolated closure.
            let consumed = MainActor.assumeIsolated { () -> Bool in
                guard !(NSApp.keyWindow?.firstResponder is NSTextView), // typing a space
                      let playback = Self.playback, playback.currentEpisode != nil
                else { return false }
                playback.togglePlayPause()
                return nil // consumed
                return true
            }
            return consumed ? nil : event
        }
    }