Skip to content

Commit

Permalink
Add global shortcut recorder
Browse files Browse the repository at this point in the history
  • Loading branch information
pakerwreah committed Jan 27, 2024
1 parent 28684c7 commit 66056c6
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 3 deletions.
21 changes: 19 additions & 2 deletions Calendr.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@
34D55FE325F06669007F5C81 /* Sequence.swift in Sources */ = {isa = PBXBuildFile; fileRef = 34D55FE225F06669007F5C81 /* Sequence.swift */; };
34E004A725B61D5200241419 /* StatusItemViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 34E004A625B61D5200241419 /* StatusItemViewModel.swift */; };
34E1902325B76CFE00E9491B /* CalendarPickerViewModelTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 34E1902225B76CFE00E9491B /* CalendarPickerViewModelTests.swift */; };
34E259832B659B5600074D3A /* KeyboardShortcuts in Frameworks */ = {isa = PBXBuildFile; productRef = 34E259822B659B5600074D3A /* KeyboardShortcuts */; };
34E60D6126A0D6D6004DA082 /* NSAccessibilityProtocol+Rx.swift in Sources */ = {isa = PBXBuildFile; fileRef = 34E60D6026A0D6D6004DA082 /* NSAccessibilityProtocol+Rx.swift */; };
34E60D6326A0EA32004DA082 /* NSAccessibilityProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 34E60D6226A0EA32004DA082 /* NSAccessibilityProtocol.swift */; };
34EDE71B2AC46515007C5854 /* Error.swift in Sources */ = {isa = PBXBuildFile; fileRef = 34EDE71A2AC46515007C5854 /* Error.swift */; };
Expand Down Expand Up @@ -342,6 +343,7 @@
files = (
3418208426755CC80075B3DC /* RxCocoa in Frameworks */,
3418207E26755CC80075B3DC /* RxSwift in Frameworks */,
34E259832B659B5600074D3A /* KeyboardShortcuts in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -766,6 +768,7 @@
packageProductDependencies = (
3418207D26755CC80075B3DC /* RxSwift */,
3418208326755CC80075B3DC /* RxCocoa */,
34E259822B659B5600074D3A /* KeyboardShortcuts */,
);
productName = Calendr;
productReference = 347D0F9425952F89002451EC /* Calendr.app */;
Expand Down Expand Up @@ -833,6 +836,7 @@
mainGroup = 347D0F8B25952F89002451EC;
packageReferences = (
3418207C26755CC80075B3DC /* XCRemoteSwiftPackageReference "RxSwift" */,
34E259812B659B5600074D3A /* XCRemoteSwiftPackageReference "KeyboardShortcuts" */,
);
productRefGroup = 347D0F9525952F89002451EC /* Products */;
projectDirPath = "";
Expand Down Expand Up @@ -1263,7 +1267,7 @@
"$(inherited)",
"@executable_path/../Frameworks",
);
MARKETING_VERSION = 1.10.7;
MARKETING_VERSION = 1.10.8;
PRODUCT_BUNDLE_IDENTIFIER = br.paker.Calendr;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OBJC_BRIDGING_HEADER = "Calendr/Config/Calendr-Bridging-Header.h";
Expand All @@ -1289,7 +1293,7 @@
"$(inherited)",
"@executable_path/../Frameworks",
);
MARKETING_VERSION = 1.10.7;
MARKETING_VERSION = 1.10.8;
PRODUCT_BUNDLE_IDENTIFIER = br.paker.Calendr;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OBJC_BRIDGING_HEADER = "Calendr/Config/Calendr-Bridging-Header.h";
Expand Down Expand Up @@ -1387,6 +1391,14 @@
minimumVersion = 6.6.0;
};
};
34E259812B659B5600074D3A /* XCRemoteSwiftPackageReference "KeyboardShortcuts" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/sindresorhus/KeyboardShortcuts";
requirement = {
kind = upToNextMajorVersion;
minimumVersion = 1.17.0;
};
};
/* End XCRemoteSwiftPackageReference section */

/* Begin XCSwiftPackageProductDependency section */
Expand All @@ -1405,6 +1417,11 @@
package = 3418207C26755CC80075B3DC /* XCRemoteSwiftPackageReference "RxSwift" */;
productName = RxCocoa;
};
34E259822B659B5600074D3A /* KeyboardShortcuts */ = {
isa = XCSwiftPackageProductDependency;
package = 34E259812B659B5600074D3A /* XCRemoteSwiftPackageReference "KeyboardShortcuts" */;
productName = KeyboardShortcuts;
};
/* End XCSwiftPackageProductDependency section */
};
rootObject = 347D0F8C25952F89002451EC /* Project object */;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
{
"pins" : [
{
"identity" : "keyboardshortcuts",
"kind" : "remoteSourceControl",
"location" : "https://github.com/sindresorhus/KeyboardShortcuts",
"state" : {
"revision" : "ac12762853126cf2e7ad63a6a58e1c9f58c6a0ee",
"version" : "1.17.0"
}
},
{
"identity" : "rxswift",
"kind" : "remoteSourceControl",
Expand Down
5 changes: 5 additions & 0 deletions Calendr/Main/Keyboard.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
//

import AppKit
import KeyboardShortcuts

class Keyboard {

Expand Down Expand Up @@ -55,3 +56,7 @@ class Keyboard {
}
}
}

extension KeyboardShortcuts.Name {
static let showMainPopover = Self("showMainPopover")
}
11 changes: 11 additions & 0 deletions Calendr/Main/MainViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import Cocoa
import RxSwift
import KeyboardShortcuts

class MainViewController: NSViewController, NSPopoverDelegate {

Expand Down Expand Up @@ -658,6 +659,16 @@ class MainViewController: NSViewController, NSPopoverDelegate {

return .none
}

// Global shortcut
KeyboardShortcuts.onKeyUp(for: .showMainPopover) { [weak self] in
guard let self else { return }
if let window = self.view.window {
window.performClose(nil)
return
}
self.mainStatusItemClickHandler.leftClick.onNext(())
}
}

// MARK: - Factories
Expand Down
7 changes: 6 additions & 1 deletion Calendr/Settings/GeneralSettingsViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import Cocoa
import RxSwift
import KeyboardShortcuts

class GeneralSettingsViewController: NSViewController {

Expand All @@ -22,6 +23,7 @@ class GeneralSettingsViewController: NSViewController {
private let iconStyleDropdown = Dropdown()
private let dateFormatDropdown = Dropdown()
private let dateFormatTextField = NSTextField()
private let shortcutRecorder = KeyboardShortcuts.RecorderCocoa(for: .showMainPopover)

// Next Event
private let showNextEventCheckbox = Checkbox(title: Strings.Settings.MenuBar.showNextEvent)
Expand Down Expand Up @@ -117,11 +119,14 @@ class GeneralSettingsViewController: NSViewController {
])
.with(orientation: .vertical)

shortcutRecorder.setContentHuggingPriority(.fittingSizeCompression, for: .horizontal)

return NSStackView(views: [
autoLaunchCheckbox,
iconStyle,
dateFormat,
showMenuBarBackgroundCheckbox
showMenuBarBackgroundCheckbox,
shortcutRecorder
])
.with(spacing: Constants.contentSpacing)
.with(orientation: .vertical)
Expand Down

0 comments on commit 66056c6

Please sign in to comment.