Feat macos (#2)
Android / build-android (release) Successful in 2m18s
Build / build-amd64 (release) Successful in 34s
Build / build-arm64 (release) Canceled after 0s

---------

Co-authored-by: intelligence <intelligence@debian.local>
Co-authored-by: jourintown <jourintown@proton.me>
Reviewed-on: #2
This commit was merged in pull request #2.
This commit is contained in:
jourintownandintelligence committed 2026-08-29 20:30:30 +02:00
1 parent 136bf7cfa3
commit 32e7f32e0a
22 files changed
+1360 -7

No files matched your search

@@ -0,0 +1,59 @@
import AppKit
import SwiftUI
struct HotkeyRecorder: NSViewRepresentable {
@Binding var shortcut: HotkeyShortcut
func makeNSView(context: Context) -> HotkeyCaptureView {
let view = HotkeyCaptureView()
view.onShortcut = { shortcut = $0 }
view.stringValue = shortcut.displayName
return view
}
func updateNSView(_ view: HotkeyCaptureView, context: Context) {
view.onShortcut = { shortcut = $0 }
if view.window?.firstResponder !== view {
view.stringValue = shortcut.displayName
}
}
}
final class HotkeyCaptureView: NSTextField {
var onShortcut: ((HotkeyShortcut) -> Void)?
override init(frame frameRect: NSRect) {
super.init(frame: frameRect)
isEditable = false
isSelectable = false
isBezeled = true
bezelStyle = .roundedBezel
alignment = .center
font = .monospacedSystemFont(ofSize: NSFont.systemFontSize, weight: .medium)
toolTip = "Click, then press a shortcut"
}
required init?(coder: NSCoder) { nil }
override var acceptsFirstResponder: Bool { true }
override func mouseDown(with event: NSEvent) {
window?.makeFirstResponder(self)
stringValue = "Type shortcut"
}
override func keyDown(with event: NSEvent) {
guard let shortcut = HotkeyShortcut(event: event) else {
NSSound.beep()
return
}
stringValue = shortcut.displayName
onShortcut?(shortcut)
window?.makeFirstResponder(nil)
}
override func resignFirstResponder() -> Bool {
needsDisplay = true
return super.resignFirstResponder()
}
}