Skip to content

Commit

Permalink
fix keyboard shortcuts on macOS 13. Close #10
Browse files Browse the repository at this point in the history
  • Loading branch information
zhiayang committed Mar 24, 2023
1 parent 5537042 commit cf528c6
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 9 deletions.
4 changes: 2 additions & 2 deletions MoeStreamer.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "";
Expand Down Expand Up @@ -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 = "";
Expand Down
13 changes: 11 additions & 2 deletions MoeStreamer/src/ui/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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()
Expand Down
15 changes: 10 additions & 5 deletions MoeStreamer/src/ui/wrappers/KeyboardShortcut.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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: [])
}
}
}

Expand All @@ -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)
Expand Down

0 comments on commit cf528c6

Please sign in to comment.