From cf528c687f6c901dd24bf53f6451d4f9cf5b4b6c Mon Sep 17 00:00:00 2001 From: zhiayang Date: Fri, 24 Mar 2023 23:19:29 +0800 Subject: [PATCH] fix keyboard shortcuts on macOS 13. Close #10 --- MoeStreamer.xcodeproj/project.pbxproj | 4 ++-- MoeStreamer/src/ui/ViewController.swift | 13 +++++++++++-- .../src/ui/wrappers/KeyboardShortcut.swift | 15 ++++++++++----- 3 files changed, 23 insertions(+), 9 deletions(-) diff --git a/MoeStreamer.xcodeproj/project.pbxproj b/MoeStreamer.xcodeproj/project.pbxproj index d57c746..bcecbe7 100644 --- a/MoeStreamer.xcodeproj/project.pbxproj +++ b/MoeStreamer.xcodeproj/project.pbxproj @@ -673,7 +673,7 @@ "@executable_path/../Frameworks", ); MACOSX_DEPLOYMENT_TARGET = 10.15; - MARKETING_VERSION = 0.17.11; + MARKETING_VERSION = 0.17.12; PRODUCT_BUNDLE_IDENTIFIER = com.zhiayang.MoeStreamer; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_OBJC_BRIDGING_HEADER = ""; @@ -708,7 +708,7 @@ "@executable_path/../Frameworks", ); MACOSX_DEPLOYMENT_TARGET = 10.15; - MARKETING_VERSION = 0.17.11; + MARKETING_VERSION = 0.17.12; PRODUCT_BUNDLE_IDENTIFIER = com.zhiayang.MoeStreamer; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_OBJC_BRIDGING_HEADER = ""; diff --git a/MoeStreamer/src/ui/ViewController.swift b/MoeStreamer/src/ui/ViewController.swift index 57a8523..ac6f942 100644 --- a/MoeStreamer/src/ui/ViewController.swift +++ b/MoeStreamer/src/ui/ViewController.swift @@ -127,8 +127,7 @@ class ViewController : NSObject, NSPopoverDelegate popover.behavior = .transient popover.delegate = self - if #unavailable(macOS 11.0) - { + let setupShortcuts = { [self] in popover.keydownHandler = { (event) in switch event.characters?.first?.asciiValue { @@ -172,6 +171,16 @@ class ViewController : NSObject, NSPopoverDelegate } } } + + // for some obscure reason, this method works on 10.15, not 11, and not 13. + if #unavailable(macOS 11.0) + { + setupShortcuts() + } + else if #available(macOS 13.0, *) + { + setupShortcuts() + } } func shutdown() diff --git a/MoeStreamer/src/ui/wrappers/KeyboardShortcut.swift b/MoeStreamer/src/ui/wrappers/KeyboardShortcut.swift index f58fd75..f43eaf7 100644 --- a/MoeStreamer/src/ui/wrappers/KeyboardShortcut.swift +++ b/MoeStreamer/src/ui/wrappers/KeyboardShortcut.swift @@ -9,14 +9,19 @@ extension Backport { @ViewBuilder func keyboardShortcut(key: Character) -> some View { - if #available(macOS 11.0, *) + // this shit is broken on ventura (13), and doesn't exist on catalina (10.15) + if #available(macOS 13.0, *) { - content.keyboardShortcut(KeyEquivalent(key), modifiers: []) + self.content } - else + else if #unavailable(macOS 11.0) { self.content } + else + { + content.keyboardShortcut(KeyEquivalent(key), modifiers: []) + } } } @@ -28,12 +33,12 @@ struct ShortcutMaker: View var body: some View { ZStack { ForEach(self.shortcuts, id: \.self) { key in - Button(action: self.action) { + Button(action: { print("AAAAA"); self.action() }) { EmptyView() } .montereyCompat .keyboardShortcut(key: key) - .buttonStyle(.borderless) +// .buttonStyle(.plain) .fixedSize() .frame(width: 0.0, height: 0.0) .padding(0)