mierau / hotline

A modern Hotline client for Mac, iOS, and iPadOS
MIT License
157 stars 8 forks source link

Keyboard shortcut for connecting to a server #32

Open jverkoey opened 1 month ago

jverkoey commented 1 month ago

When browsing servers, my natural inclination was to press Cmd+Down to try to connect to the server. Return works just as well, but I figured it might be a nice additional macOS-ism to support Cmd+Down.

jverkoey commented 1 month ago

I took at stab at this, first by attempting to add a button to the context menu with a keyboard shortcut here:

https://github.com/mierau/hotline/blob/93841e378308f959566e1411a7cba6a2602db2e8/Hotline/macOS/TrackerView.swift#L70-L89

like so:

Button {
  connect(to: item)
} label: {
  Label("Connect", systemImage: "phone.connection.fill")
}
.buttonStyle(.borderless)
.keyboardShortcut(.downArrow, modifiers: .command)

But this didn't work. I just realized that this might be because the keyboard shortcut doesn't get a chance to be registered anywhere until the context menu itself appears. Sure enough, once the context menu appears, the shortcut works as expected.

Going to try registering the command in the app menu instead.

jverkoey commented 1 month ago

Also I found https://steipete.com/posts/fixing-keyboardshortcut-in-swiftui/ which seemed relevant at first but likely isn't :)

jverkoey commented 1 month ago

Adding

Button("Connect") {
  print("Foo")
}
.keyboardShortcut(.downArrow, modifiers: .command)

to the server command menu group works as expected, but now I'm not sure how to wire this up to the connection logic from TrackerView 🤔.

jverkoey commented 1 month ago

Got it working. PR inbound!