From ed2b353648cdf24d09b4d87d65e2083319a448c0 Mon Sep 17 00:00:00 2001 From: Kerwin Carpede Date: Thu, 10 Sep 2026 04:20:07 +0200 Subject: [PATCH 1/3] Add right Command shortcut and beta build --- Leader Key.xcodeproj/project.pbxproj | 55 +++++ .../xcschemes/Leader Key Beta.xcscheme | 63 ++++++ Leader Key/AppDelegate.swift | 38 +++- Leader Key/Defaults.swift | 2 + Leader Key/RightCommandMonitor.swift | 200 ++++++++++++++++++ Leader Key/Settings/GeneralPane.swift | 33 ++- Leader Key/StatusItem.swift | 18 +- Leader Key/Support/Beta-Info.plist | 25 +++ Leader Key/UserConfig.swift | 10 +- .../RightCommandMonitorTests.swift | 65 ++++++ README.md | 10 +- 11 files changed, 503 insertions(+), 16 deletions(-) create mode 100644 Leader Key.xcodeproj/xcshareddata/xcschemes/Leader Key Beta.xcscheme create mode 100644 Leader Key/RightCommandMonitor.swift create mode 100644 Leader Key/Support/Beta-Info.plist create mode 100644 Leader KeyTests/RightCommandMonitorTests.swift diff --git a/Leader Key.xcodeproj/project.pbxproj b/Leader Key.xcodeproj/project.pbxproj index 141cebf6..ddf64dc7 100644 --- a/Leader Key.xcodeproj/project.pbxproj +++ b/Leader Key.xcodeproj/project.pbxproj @@ -41,6 +41,8 @@ 427C18502BD6652500955B98 /* Util.swift in Sources */ = {isa = PBXBuildFile; fileRef = 427C184F2BD6652500955B98 /* Util.swift */; }; 427C18542BD6E59300955B98 /* NSWindow+Animations.swift in Sources */ = {isa = PBXBuildFile; fileRef = 427C18532BD6E59300955B98 /* NSWindow+Animations.swift */; }; 4284834C2E813212009D7EEF /* KeyboardLayoutTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4284834B2E813212009D7EEF /* KeyboardLayoutTests.swift */; }; + 6A9D3E8101A24B6300D4C101 /* RightCommandMonitor.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6A9D3E8001A24B6300D4C101 /* RightCommandMonitor.swift */; }; + 6A9D3E8301A24B6300D4C101 /* RightCommandMonitorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6A9D3E8201A24B6300D4C101 /* RightCommandMonitorTests.swift */; }; 42B21FBC2D67566100F4A2C7 /* Alerts.swift in Sources */ = {isa = PBXBuildFile; fileRef = 42B21FBB2D67566100F4A2C7 /* Alerts.swift */; }; 42CCB5A32DAD257700356FC0 /* Kingfisher in Frameworks */ = {isa = PBXBuildFile; productRef = FBCA04D82D9F02F700271163 /* Kingfisher */; }; 42DFCD722D5B7D48002EA111 /* Events.swift in Sources */ = {isa = PBXBuildFile; fileRef = 42DFCD712D5B7D46002EA111 /* Events.swift */; }; @@ -102,6 +104,8 @@ 427C184F2BD6652500955B98 /* Util.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Util.swift; sourceTree = ""; }; 427C18532BD6E59300955B98 /* NSWindow+Animations.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "NSWindow+Animations.swift"; sourceTree = ""; }; 4284834B2E813212009D7EEF /* KeyboardLayoutTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KeyboardLayoutTests.swift; sourceTree = ""; }; + 6A9D3E8001A24B6300D4C101 /* RightCommandMonitor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RightCommandMonitor.swift; sourceTree = ""; }; + 6A9D3E8201A24B6300D4C101 /* RightCommandMonitorTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RightCommandMonitorTests.swift; sourceTree = ""; }; 42B21FBB2D67566100F4A2C7 /* Alerts.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Alerts.swift; sourceTree = ""; }; 42DFCD712D5B7D46002EA111 /* Events.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Events.swift; sourceTree = ""; }; 42F4CDC82D458FF700D0DD76 /* MainMenu.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MainMenu.swift; sourceTree = ""; }; @@ -193,6 +197,7 @@ 427C181B2BD314B500955B98 /* Constants.swift */, 427C18272BD31E2E00955B98 /* Controller.swift */, 427C184C2BD65C5C00955B98 /* Defaults.swift */, + 6A9D3E8001A24B6300D4C101 /* RightCommandMonitor.swift */, 42DFCD712D5B7D46002EA111 /* Events.swift */, 42F4CDD02D48C51F00D0DD76 /* Extensions.swift */, 42F4CDC82D458FF700D0DD76 /* MainMenu.swift */, @@ -228,6 +233,7 @@ 42454DDC2D71CBAB004E1374 /* ConfigValidatorTests.swift */, EC5CEBC4C47B4C5DB2258814 /* URLSchemeTests.swift */, 427C17FC2BD311B500955B98 /* UserConfigTests.swift */, + 6A9D3E8201A24B6300D4C101 /* RightCommandMonitorTests.swift */, ); path = "Leader KeyTests"; sourceTree = ""; @@ -415,6 +421,7 @@ 42F4CDC92D458FF700D0DD76 /* MainMenu.swift in Sources */, 42454DDB2D71CB39004E1374 /* ConfigValidator.swift in Sources */, 427C184D2BD65C5C00955B98 /* Defaults.swift in Sources */, + 6A9D3E8101A24B6300D4C101 /* RightCommandMonitor.swift in Sources */, 427C18292BD31E2E00955B98 /* MainWindow.swift in Sources */, 42FDC31A2D51687B004F5C5C /* AdvancedPane.swift in Sources */, 115AA5BF2DA521C600C17E18 /* ActionIcon.swift in Sources */, @@ -454,6 +461,7 @@ EC5CEBC4C47B4C5DB2258813 /* URLSchemeTests.swift in Sources */, 427C17FD2BD311B500955B98 /* UserConfigTests.swift in Sources */, 4284834C2E813212009D7EEF /* KeyboardLayoutTests.swift in Sources */, + 6A9D3E8301A24B6300D4C101 /* RightCommandMonitorTests.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -596,6 +604,15 @@ }; name = Release; }; + A1B2C3D42C3D4E5F00112233 /* Beta */ = { + isa = XCBuildConfiguration; + buildSettings = { + MACOSX_DEPLOYMENT_TARGET = 14.4; + SDKROOT = macosx; + SWIFT_ACTIVE_COMPILATION_CONDITIONS = "BETA $(inherited)"; + }; + name = Beta; + }; 427C180D2BD311B500955B98 /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { @@ -668,6 +685,42 @@ }; name = Release; }; + A1B2C3D52C3D4E5F00112233 /* Beta */ = { + isa = XCBuildConfiguration; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; + ASSETCATALOG_COMPILER_INCLUDE_ALL_APPICON_ASSETS = YES; + CODE_SIGN_ENTITLEMENTS = "Leader Key/Leader_Key.entitlements"; + "CODE_SIGN_IDENTITY[sdk=macosx*]" = "Apple Development"; + CODE_SIGN_STYLE = Automatic; + COMBINE_HIDPI_IMAGES = YES; + CURRENT_PROJECT_VERSION = 155; + DEAD_CODE_STRIPPING = YES; + DEVELOPMENT_ASSET_PATHS = "\"Leader Key/Support/Preview Content\""; + ENABLE_HARDENED_RUNTIME = YES; + ENABLE_PREVIEWS = YES; + GENERATE_INFOPLIST_FILE = YES; + INFOPLIST_FILE = "Leader Key/Support/Beta-Info.plist"; + INFOPLIST_KEY_CFBundleDisplayName = "Leader Key Beta"; + INFOPLIST_KEY_LSApplicationCategoryType = "public.app-category.utilities"; + INFOPLIST_KEY_LSUIElement = YES; + INFOPLIST_KEY_NSHumanReadableCopyright = ""; + INFOPLIST_KEY_NSMainStoryboardFile = Main; + INFOPLIST_KEY_NSPrincipalClass = NSApplication; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/../Frameworks", + ); + MACOSX_DEPLOYMENT_TARGET = 13.0; + MARKETING_VERSION = 1.17.3; + PRODUCT_BUNDLE_IDENTIFIER = "com.brnbw.Leader-Key.beta"; + PRODUCT_NAME = "Leader Key Beta"; + SWIFT_EMIT_LOC_STRINGS = YES; + SWIFT_VERSION = 5.0; + }; + name = Beta; + }; 427C18102BD311B500955B98 /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { @@ -712,6 +765,7 @@ buildConfigurations = ( 427C180A2BD311B500955B98 /* Debug */, 427C180B2BD311B500955B98 /* Release */, + A1B2C3D42C3D4E5F00112233 /* Beta */, ); defaultConfigurationIsVisible = 0; defaultConfigurationName = Release; @@ -721,6 +775,7 @@ buildConfigurations = ( 427C180D2BD311B500955B98 /* Debug */, 427C180E2BD311B500955B98 /* Release */, + A1B2C3D52C3D4E5F00112233 /* Beta */, ); defaultConfigurationIsVisible = 0; defaultConfigurationName = Release; diff --git a/Leader Key.xcodeproj/xcshareddata/xcschemes/Leader Key Beta.xcscheme b/Leader Key.xcodeproj/xcshareddata/xcschemes/Leader Key Beta.xcscheme new file mode 100644 index 00000000..fa574e78 --- /dev/null +++ b/Leader Key.xcodeproj/xcshareddata/xcschemes/Leader Key Beta.xcscheme @@ -0,0 +1,63 @@ + + + + + + + + + + + + + + + + + + + + + diff --git a/Leader Key/AppDelegate.swift b/Leader Key/AppDelegate.swift index 36411839..b2ff6a45 100644 --- a/Leader Key/AppDelegate.swift +++ b/Leader Key/AppDelegate.swift @@ -18,6 +18,9 @@ class AppDelegate: NSObject, NSApplicationDelegate, let statusItem = StatusItem() let config = UserConfig() + lazy var rightCommandMonitor = RightCommandMonitor { [weak self] in + self?.activate() + } var state: UserState! @IBOutlet var updaterController: SPUStandardUpdaterController! @@ -66,9 +69,11 @@ class AppDelegate: NSObject, NSApplicationDelegate, statusItem.handleRevealConfig = { NSWorkspace.shared.activateFileViewerSelecting([self.config.url]) } - statusItem.handleCheckForUpdates = { - self.updaterController.checkForUpdates(nil) - } + #if !BETA + statusItem.handleCheckForUpdates = { + self.updaterController.checkForUpdates(nil) + } + #endif Task { for await value in Defaults.updates(.showMenuBarIcon) { @@ -90,6 +95,13 @@ class AppDelegate: NSObject, NSApplicationDelegate, // Activation policy is managed solely by the Settings window registerGlobalShortcuts() + updateRightCommandMonitor(enabled: Defaults[.useRightCommandAsLeader]) + + Task { @MainActor in + for await enabled in Defaults.updates(.useRightCommandAsLeader) { + self.updateRightCommandMonitor(enabled: enabled) + } + } } func activate() { @@ -126,13 +138,29 @@ class AppDelegate: NSObject, NSApplicationDelegate, self.processKeys([groupKey]) } } - if Defaults[.groupShortcuts].isEmpty && !KeyboardShortcuts.isEnabled(for: .activate) { + let hasRightCommandShortcut = + Defaults[.useRightCommandAsLeader] && rightCommandMonitor.hasInputMonitoringPermission + if Defaults[.groupShortcuts].isEmpty && !KeyboardShortcuts.isEnabled(for: .activate) + && !hasRightCommandShortcut + { showSettings() } } + private func updateRightCommandMonitor(enabled: Bool) { + if enabled && rightCommandMonitor.hasInputMonitoringPermission { + rightCommandMonitor.start() + } else { + rightCommandMonitor.stop() + } + } + + func refreshRightCommandMonitor() { + updateRightCommandMonitor(enabled: Defaults[.useRightCommandAsLeader]) + } + func applicationWillTerminate(_ notification: Notification) { - // Config saves automatically on changes + rightCommandMonitor.stop() } @IBAction diff --git a/Leader Key/Defaults.swift b/Leader Key/Defaults.swift index 66703047..628b4de0 100644 --- a/Leader Key/Defaults.swift +++ b/Leader Key/Defaults.swift @@ -39,6 +39,8 @@ extension Defaults.Keys { static let groupShortcuts = Key>( "groupShortcuts", default: Set(), suite: defaultsSuite) + static let useRightCommandAsLeader = Key( + "useRightCommandAsLeader", default: false, suite: defaultsSuite) } enum AutoOpenCheatsheetSetting: String, Defaults.Serializable { diff --git a/Leader Key/RightCommandMonitor.swift b/Leader Key/RightCommandMonitor.swift new file mode 100644 index 00000000..c3e09d68 --- /dev/null +++ b/Leader Key/RightCommandMonitor.swift @@ -0,0 +1,200 @@ +import Carbon.HIToolbox +import CoreGraphics + +enum RightCommandTapEvent { + case flagsChanged(keyCode: CGKeyCode, flags: CGEventFlags) + case keyDown + case mouseDown +} + +struct RightCommandTapState { + private var isRightCommandDown = false + private var shouldActivate = false + private var heldOtherModifiers = Set() + + mutating func handle(_ event: RightCommandTapEvent) -> Bool { + switch event { + case .flagsChanged(let keyCode, let flags): + return handleModifierChange(keyCode: keyCode, flags: flags) + case .keyDown, .mouseDown: + if isRightCommandDown { + shouldActivate = false + } + return false + } + } + + mutating func reset() { + isRightCommandDown = false + shouldActivate = false + heldOtherModifiers.removeAll() + } + + private mutating func handleModifierChange(keyCode: CGKeyCode, flags: CGEventFlags) -> Bool { + if keyCode == CGKeyCode(kVK_RightCommand) { + if isRightCommandDown { + isRightCommandDown = false + defer { shouldActivate = false } + return shouldActivate + } + + isRightCommandDown = true + shouldActivate = heldOtherModifiers.isEmpty + return false + } + + updateHeldModifiers(keyCode: keyCode, flags: flags) + + if isRightCommandDown { + shouldActivate = false + } + + return false + } + + private mutating func updateHeldModifiers(keyCode: CGKeyCode, flags: CGEventFlags) { + guard let modifierFlag = modifierFlag(for: keyCode) else { + return + } + + if flags.contains(modifierFlag) { + heldOtherModifiers.insert(keyCode) + } else { + heldOtherModifiers.remove(keyCode) + } + } + + private func modifierFlag(for keyCode: CGKeyCode) -> CGEventFlags? { + switch keyCode { + case CGKeyCode(kVK_Command): + return .maskCommand + case CGKeyCode(kVK_Shift), CGKeyCode(kVK_RightShift): + return .maskShift + case CGKeyCode(kVK_Option), CGKeyCode(kVK_RightOption): + return .maskAlternate + case CGKeyCode(kVK_Control), CGKeyCode(kVK_RightControl): + return .maskControl + case CGKeyCode(kVK_Function): + return .maskSecondaryFn + default: + return nil + } + } +} + +final class RightCommandMonitor { + private var eventTap: CFMachPort? + private var runLoopSource: CFRunLoopSource? + private var state = RightCommandTapState() + private let onTap: () -> Void + + init(onTap: @escaping () -> Void) { + self.onTap = onTap + } + + deinit { + stop() + } + + var hasInputMonitoringPermission: Bool { + CGPreflightListenEventAccess() + } + + @discardableResult + func start() -> Bool { + guard eventTap == nil, hasInputMonitoringPermission else { + return eventTap != nil + } + + let eventMask = eventMask( + for: [ + .flagsChanged, + .keyDown, + .leftMouseDown, + .rightMouseDown, + .otherMouseDown, + ] + ) + let userInfo = Unmanaged.passUnretained(self).toOpaque() + guard + let eventTap = CGEvent.tapCreate( + tap: .cgSessionEventTap, + place: .headInsertEventTap, + options: .listenOnly, + eventsOfInterest: eventMask, + callback: Self.eventTapCallback, + userInfo: userInfo + ) + else { + return false + } + + guard let runLoopSource = CFMachPortCreateRunLoopSource(kCFAllocatorDefault, eventTap, 0) + else { + CFMachPortInvalidate(eventTap) + return false + } + + self.eventTap = eventTap + self.runLoopSource = runLoopSource + CFRunLoopAddSource(CFRunLoopGetMain(), runLoopSource, .commonModes) + CGEvent.tapEnable(tap: eventTap, enable: true) + return true + } + + func stop() { + if let runLoopSource { + CFRunLoopRemoveSource(CFRunLoopGetMain(), runLoopSource, .commonModes) + } + if let eventTap { + CFMachPortInvalidate(eventTap) + } + + runLoopSource = nil + eventTap = nil + state.reset() + } + + private func receive(type: CGEventType, event: CGEvent) { + switch type { + case .tapDisabledByTimeout, .tapDisabledByUserInput: + if let eventTap { + CGEvent.tapEnable(tap: eventTap, enable: true) + } + return + case .flagsChanged: + let keyCode = CGKeyCode(event.getIntegerValueField(.keyboardEventKeycode)) + activateIfNeeded(for: .flagsChanged(keyCode: keyCode, flags: event.flags)) + case .keyDown: + activateIfNeeded(for: .keyDown) + case .leftMouseDown, .rightMouseDown, .otherMouseDown: + activateIfNeeded(for: .mouseDown) + default: + return + } + } + + private func activateIfNeeded(for event: RightCommandTapEvent) { + guard state.handle(event) else { + return + } + + DispatchQueue.main.async { [weak self] in + self?.onTap() + } + } + + private static let eventTapCallback: CGEventTapCallBack = { _, type, event, userInfo in + if let userInfo { + let monitor = Unmanaged.fromOpaque(userInfo).takeUnretainedValue() + monitor.receive(type: type, event: event) + } + return Unmanaged.passUnretained(event) + } + + private func eventMask(for eventTypes: [CGEventType]) -> CGEventMask { + eventTypes.reduce(CGEventMask(0)) { mask, eventType in + mask | (CGEventMask(1) << eventType.rawValue) + } + } +} diff --git a/Leader Key/Settings/GeneralPane.swift b/Leader Key/Settings/GeneralPane.swift index 4ebc9174..f7095b6e 100644 --- a/Leader Key/Settings/GeneralPane.swift +++ b/Leader Key/Settings/GeneralPane.swift @@ -1,3 +1,4 @@ +import AppKit import Defaults import KeyboardShortcuts import LaunchAtLogin @@ -9,6 +10,8 @@ struct GeneralPane: View { @EnvironmentObject private var config: UserConfig @Default(.configDir) var configDir @Default(.theme) var theme + @Default(.useRightCommandAsLeader) var useRightCommandAsLeader + @State private var hasInputMonitoringPermission = CGPreflightListenEventAccess() var body: some View { Settings.Container(contentWidth: contentWidth) { @@ -86,7 +89,35 @@ struct GeneralPane: View { } Settings.Section(title: "Shortcut") { - KeyboardShortcuts.Recorder(for: .activate) + VStack(alignment: .leading, spacing: 8) { + KeyboardShortcuts.Recorder(for: .activate) + + Toggle("Use right ⌘ as Leader Key", isOn: $useRightCommandAsLeader) + .onChange(of: useRightCommandAsLeader) { enabled in + if enabled && !CGPreflightListenEventAccess() { + CGRequestListenEventAccess() + } + + hasInputMonitoringPermission = CGPreflightListenEventAccess() + (NSApplication.shared.delegate as? AppDelegate)?.refreshRightCommandMonitor() + } + + if useRightCommandAsLeader && !hasInputMonitoringPermission { + Text( + "Input Monitoring permission is required. Enable Leader Key in System Settings to use this shortcut." + ) + .font(.caption) + .foregroundStyle(.secondary) + } else if useRightCommandAsLeader { + Text("Leader Key opens when you tap and release the right Command key.") + .font(.caption) + .foregroundStyle(.secondary) + } + } + .onAppear { + hasInputMonitoringPermission = CGPreflightListenEventAccess() + (NSApplication.shared.delegate as? AppDelegate)?.refreshRightCommandMonitor() + } } Settings.Section(title: "Theme") { diff --git a/Leader Key/StatusItem.swift b/Leader Key/StatusItem.swift index 28386b6d..f4feb96c 100644 --- a/Leader Key/StatusItem.swift +++ b/Leader Key/StatusItem.swift @@ -56,14 +56,16 @@ class StatusItem { menu.addItem(NSMenuItem.separator()) - let checkForUpdatesItem = NSMenuItem( - title: "Check for Updates...", action: #selector(checkForUpdates), - keyEquivalent: "" - ) - checkForUpdatesItem.target = self - menu.addItem(checkForUpdatesItem) - - menu.addItem(NSMenuItem.separator()) + #if !BETA + let checkForUpdatesItem = NSMenuItem( + title: "Check for Updates...", action: #selector(checkForUpdates), + keyEquivalent: "" + ) + checkForUpdatesItem.target = self + menu.addItem(checkForUpdatesItem) + + menu.addItem(NSMenuItem.separator()) + #endif let revealConfigItem = NSMenuItem( title: "Show config in Finder", action: #selector(revealConfigFile), diff --git a/Leader Key/Support/Beta-Info.plist b/Leader Key/Support/Beta-Info.plist new file mode 100644 index 00000000..2919b3d5 --- /dev/null +++ b/Leader Key/Support/Beta-Info.plist @@ -0,0 +1,25 @@ + + + + + CFBundleDevelopmentRegion + en + CFBundleLocalizations + + en + + CFBundleURLTypes + + + CFBundleTypeRole + Viewer + CFBundleURLName + com.brnbw.LeaderKey.beta + CFBundleURLSchemes + + leaderkey-beta + + + + + diff --git a/Leader Key/UserConfig.swift b/Leader Key/UserConfig.swift index c339d028..02a9e3b7 100644 --- a/Leader Key/UserConfig.swift +++ b/Leader Key/UserConfig.swift @@ -182,7 +182,7 @@ class UserConfig: ObservableObject { let appSupportDir = FileManager.default.urls( for: .applicationSupportDirectory, in: .userDomainMask)[0] let path = (appSupportDir.path as NSString).appendingPathComponent( - "Leader Key") + defaultDirectoryName) do { try FileManager.default.createDirectory( atPath: path, withIntermediateDirectories: true) @@ -192,6 +192,14 @@ class UserConfig: ObservableObject { return path } + private static var defaultDirectoryName: String { + #if BETA + "Leader Key Beta" + #else + "Leader Key" + #endif + } + private func ensureValidConfigDirectory() { let dir = Defaults[.configDir] let defaultDir = Self.defaultDirectory() diff --git a/Leader KeyTests/RightCommandMonitorTests.swift b/Leader KeyTests/RightCommandMonitorTests.swift new file mode 100644 index 00000000..d6c46d6f --- /dev/null +++ b/Leader KeyTests/RightCommandMonitorTests.swift @@ -0,0 +1,65 @@ +import Carbon.HIToolbox +import CoreGraphics +import XCTest + +@testable import Leader_Key + +final class RightCommandMonitorTests: XCTestCase { + func testTapRightCommandActivatesOnRelease() { + var state = RightCommandTapState() + + XCTAssertFalse(rightCommandDown(&state)) + XCTAssertTrue(rightCommandUp(&state)) + } + + func testLeftCommandDoesNotActivate() { + var state = RightCommandTapState() + + XCTAssertFalse( + state.handle(.flagsChanged(keyCode: CGKeyCode(kVK_Command), flags: [.maskCommand]))) + XCTAssertFalse( + state.handle(.flagsChanged(keyCode: CGKeyCode(kVK_Command), flags: []))) + } + + func testKeyPressedWhileRightCommandIsHeldCancelsActivation() { + var state = RightCommandTapState() + + XCTAssertFalse(rightCommandDown(&state)) + XCTAssertFalse(state.handle(.keyDown)) + XCTAssertFalse(rightCommandUp(&state)) + } + + func testAdditionalModifierCancelsActivation() { + var state = RightCommandTapState() + + XCTAssertFalse(rightCommandDown(&state)) + XCTAssertFalse( + state.handle(.flagsChanged(keyCode: CGKeyCode(kVK_Shift), flags: [.maskCommand, .maskShift]))) + XCTAssertFalse(rightCommandUp(&state)) + } + + func testRightCommandDoesNotActivateWhenLeftCommandIsHeldFirst() { + var state = RightCommandTapState() + + XCTAssertFalse( + state.handle(.flagsChanged(keyCode: CGKeyCode(kVK_Command), flags: [.maskCommand]))) + XCTAssertFalse(rightCommandDown(&state)) + XCTAssertFalse(rightCommandUp(&state)) + } + + func testMouseClickWhileRightCommandIsHeldCancelsActivation() { + var state = RightCommandTapState() + + XCTAssertFalse(rightCommandDown(&state)) + XCTAssertFalse(state.handle(.mouseDown)) + XCTAssertFalse(rightCommandUp(&state)) + } + + private func rightCommandDown(_ state: inout RightCommandTapState) -> Bool { + state.handle(.flagsChanged(keyCode: CGKeyCode(kVK_RightCommand), flags: [.maskCommand])) + } + + private func rightCommandUp(_ state: inout RightCommandTapState) -> Bool { + state.handle(.flagsChanged(keyCode: CGKeyCode(kVK_RightCommand), flags: [])) + } +} diff --git a/README.md b/README.md index 985631fb..2f901319 100644 --- a/README.md +++ b/README.md @@ -36,6 +36,13 @@ or $ brew install leader-key ``` +### Beta build + +The Xcode scheme **Leader Key Beta** builds a separately installable beta app. It +uses the `Leader Key Beta.app` name, a distinct bundle identifier, independent +preferences, and `~/Library/Application Support/Leader Key Beta` for its config. +It does not use the release update feed. + ### Post-Install setup - Open the settings menu with the menu bar icon Screenshot 2025-05-21 at 1 58 46 PM - Choose your [`leader`](#what-do-i-set-as-my-leader-key) (`Shortcut` that will open the app) @@ -113,7 +120,8 @@ open "leaderkey://navigate?keys=a,b,c&execute=false" #### What do I set as my Leader Key? -Any key can be your leader key, but **only modifiers will not work**. +Any non-modifier key can be your leader key. You can also enable **right ⌘** in Settings; +it opens Leader Key when tapped and released, and requires macOS Input Monitoring permission. **Examples:** From 8efd16e0b5eaea47db0f499ae93216b5916faf23 Mon Sep 17 00:00:00 2001 From: Kerwin Carpede Date: Thu, 10 Sep 2026 04:55:27 +0200 Subject: [PATCH 2/3] Publish beta builds from GitHub Actions --- .github/workflows/appcast.yml | 1 + .github/workflows/release-beta.yml | 45 ++++++++++++++++++++++++++++++ README.md | 3 ++ 3 files changed, 49 insertions(+) create mode 100644 .github/workflows/release-beta.yml diff --git a/.github/workflows/appcast.yml b/.github/workflows/appcast.yml index 58e569d7..be6a6a3b 100644 --- a/.github/workflows/appcast.yml +++ b/.github/workflows/appcast.yml @@ -10,6 +10,7 @@ on: jobs: call-workflow: + if: github.event_name != 'release' || !github.event.release.prerelease uses: mikker/appcast-workflow/.github/workflows/appcast.yml@main secrets: inherit permissions: diff --git a/.github/workflows/release-beta.yml b/.github/workflows/release-beta.yml new file mode 100644 index 00000000..c12dac25 --- /dev/null +++ b/.github/workflows/release-beta.yml @@ -0,0 +1,45 @@ +name: Publish Beta Release + +on: + push: + tags: + - "beta-v*" + +permissions: + contents: write + +jobs: + publish: + runs-on: macos-15 + + steps: + - uses: actions/checkout@v4 + + - name: Build unsigned beta app + run: | + xcodebuild \ + -project "Leader Key.xcodeproj" \ + -scheme "Leader Key Beta" \ + -configuration Beta \ + -destination "platform=macOS" \ + -skipPackagePluginValidation \ + CODE_SIGNING_ALLOWED=NO \ + CONFIGURATION_BUILD_DIR="$RUNNER_TEMP/build" \ + build + + - name: Package beta app + id: package + run: | + archive_path="$RUNNER_TEMP/Leader-Key-Beta-${GITHUB_REF_NAME}.zip" + ditto -c -k --sequesterRsrc --keepParent \ + "$RUNNER_TEMP/build/Leader Key Beta.app" \ + "$archive_path" + echo "archive_path=$archive_path" >> "$GITHUB_OUTPUT" + + - name: Publish GitHub prerelease + env: + GH_TOKEN: ${{ github.token }} + run: | + gh release create "$GITHUB_REF_NAME" "${{ steps.package.outputs.archive_path }}" \ + --prerelease \ + --generate-notes diff --git a/README.md b/README.md index 2f901319..016719f6 100644 --- a/README.md +++ b/README.md @@ -43,6 +43,9 @@ uses the `Leader Key Beta.app` name, a distinct bundle identifier, independent preferences, and `~/Library/Application Support/Leader Key Beta` for its config. It does not use the release update feed. +Push a `beta-v*` tag to publish an unsigned Beta zip as a GitHub prerelease. +For example: `git tag beta-v1.17.4.0 && git push origin beta-v1.17.4.0`. + ### Post-Install setup - Open the settings menu with the menu bar icon Screenshot 2025-05-21 at 1 58 46 PM - Choose your [`leader`](#what-do-i-set-as-my-leader-key) (`Shortcut` that will open the app) From 0c2c93239eb90ba33bb1a7fccb7482b95a5bba92 Mon Sep 17 00:00:00 2001 From: Kerwin Carpede Date: Thu, 10 Sep 2026 05:03:28 +0200 Subject: [PATCH 3/3] Remove appcast and beta release workflows --- .github/workflows/appcast.yml | 18 ------------ .github/workflows/release-beta.yml | 45 ------------------------------ README.md | 3 -- 3 files changed, 66 deletions(-) delete mode 100644 .github/workflows/appcast.yml delete mode 100644 .github/workflows/release-beta.yml diff --git a/.github/workflows/appcast.yml b/.github/workflows/appcast.yml deleted file mode 100644 index be6a6a3b..00000000 --- a/.github/workflows/appcast.yml +++ /dev/null @@ -1,18 +0,0 @@ -# Trigger build 1 -name: Appcast - -on: - push: - branches: [main] - release: - types: [published] - workflow_dispatch: - -jobs: - call-workflow: - if: github.event_name != 'release' || !github.event.release.prerelease - uses: mikker/appcast-workflow/.github/workflows/appcast.yml@main - secrets: inherit - permissions: - pages: write - id-token: write diff --git a/.github/workflows/release-beta.yml b/.github/workflows/release-beta.yml deleted file mode 100644 index c12dac25..00000000 --- a/.github/workflows/release-beta.yml +++ /dev/null @@ -1,45 +0,0 @@ -name: Publish Beta Release - -on: - push: - tags: - - "beta-v*" - -permissions: - contents: write - -jobs: - publish: - runs-on: macos-15 - - steps: - - uses: actions/checkout@v4 - - - name: Build unsigned beta app - run: | - xcodebuild \ - -project "Leader Key.xcodeproj" \ - -scheme "Leader Key Beta" \ - -configuration Beta \ - -destination "platform=macOS" \ - -skipPackagePluginValidation \ - CODE_SIGNING_ALLOWED=NO \ - CONFIGURATION_BUILD_DIR="$RUNNER_TEMP/build" \ - build - - - name: Package beta app - id: package - run: | - archive_path="$RUNNER_TEMP/Leader-Key-Beta-${GITHUB_REF_NAME}.zip" - ditto -c -k --sequesterRsrc --keepParent \ - "$RUNNER_TEMP/build/Leader Key Beta.app" \ - "$archive_path" - echo "archive_path=$archive_path" >> "$GITHUB_OUTPUT" - - - name: Publish GitHub prerelease - env: - GH_TOKEN: ${{ github.token }} - run: | - gh release create "$GITHUB_REF_NAME" "${{ steps.package.outputs.archive_path }}" \ - --prerelease \ - --generate-notes diff --git a/README.md b/README.md index 016719f6..2f901319 100644 --- a/README.md +++ b/README.md @@ -43,9 +43,6 @@ uses the `Leader Key Beta.app` name, a distinct bundle identifier, independent preferences, and `~/Library/Application Support/Leader Key Beta` for its config. It does not use the release update feed. -Push a `beta-v*` tag to publish an unsigned Beta zip as a GitHub prerelease. -For example: `git tag beta-v1.17.4.0 && git push origin beta-v1.17.4.0`. - ### Post-Install setup - Open the settings menu with the menu bar icon Screenshot 2025-05-21 at 1 58 46 PM - Choose your [`leader`](#what-do-i-set-as-my-leader-key) (`Shortcut` that will open the app)