Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: sindresorhus/KeyboardShortcuts
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 1.17.0
Choose a base ref
...
head repository: sindresorhus/KeyboardShortcuts
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: main
Choose a head ref
  • 20 commits
  • 35 files changed
  • 7 contributors

Commits on Feb 20, 2024

  1. Copy the full SHA
    3b11952 View commit details
  2. Target macOS 10.15

    sindresorhus committed Feb 20, 2024
    Copy the full SHA
    04b8db6 View commit details
  3. Copy the full SHA
    09e4a10 View commit details

Commits on May 23, 2024

  1. Copy the full SHA
    2e5f155 View commit details

Commits on Jul 25, 2024

  1. Minor tweaks

    sindresorhus committed Jul 25, 2024
    Copy the full SHA
    99cfb0b View commit details

Commits on Sep 1, 2024

  1. Copy the full SHA
    b4211a1 View commit details
  2. Copy the full SHA
    e6b6011 View commit details

Commits on Sep 22, 2024

  1. Tweaks

    sindresorhus committed Sep 22, 2024
    Copy the full SHA
    e1f4dbf View commit details
  2. Copy the full SHA
    68d5d2d View commit details
  3. Copy the full SHA
    425ddf7 View commit details

Commits on Sep 23, 2024

  1. Code style tweaks

    sindresorhus committed Sep 23, 2024
    Copy the full SHA
    9369a04 View commit details

Commits on Oct 8, 2024

  1. Tweaks

    sindresorhus committed Oct 8, 2024
    Copy the full SHA
    16e7f8b View commit details

Commits on Oct 9, 2024

  1. Add .resetAll() method

    sindresorhus committed Oct 9, 2024
    Copy the full SHA
    528cd5c View commit details

Commits on Oct 21, 2024

  1. Improve localizations and fix recorder not allowing multiple modifier…

    …s when option is present (#187)
    francisfeng authored Oct 21, 2024
    Copy the full SHA
    9203a8d View commit details

Commits on Nov 4, 2024

  1. Fix using Control+C keyboard shortcut

    It was incorrectly triggering the dialog for it being taken by the system. This is because we were not storing the `.function` modifier in the shortcut. The system shortcut is Fn+Control+C.
    sindresorhus committed Nov 4, 2024
    Copy the full SHA
    c3c361f View commit details

Commits on Nov 30, 2024

  1. Copy the full SHA
    db50681 View commit details

Commits on Dec 7, 2024

  1. Fix logic for .globalKeyboardShortcut() (#193)

    Co-authored-by: Sindre Sorhus <sindresorhus@gmail.com>
    cweider and sindresorhus authored Dec 7, 2024
    Copy the full SHA
    323d9f8 View commit details

Commits on Dec 13, 2024

  1. Copy the full SHA
    7ecc38b View commit details

Commits on Mar 7, 2025

  1. Copy the full SHA
    2d6b49e View commit details
  2. Copy the full SHA
    045cf17 View commit details
Showing with 1,006 additions and 345 deletions.
  1. +35 −8 .swiftlint.yml
  2. +1 −1 .swiftpm/xcode/xcshareddata/xcschemes/KeyboardShortcuts.xcscheme
  3. +13 −7 Example/KeyboardShortcutsExample.xcodeproj/project.pbxproj
  4. +1 −3 Example/KeyboardShortcutsExample/App.swift
  5. +9 −5 Example/KeyboardShortcutsExample/AppState.swift
  6. +0 −24 Example/KeyboardShortcutsExample/Info.plist
  7. +33 −31 Example/KeyboardShortcutsExample/MainScreen.swift
  8. +2 −3 Example/KeyboardShortcutsExample/Utilities.swift
  9. +2 −2 Package.swift
  10. +2 −0 Sources/KeyboardShortcuts/CarbonKeyboardShortcuts.swift
  11. +1 −1 Sources/KeyboardShortcuts/Key.swift
  12. +43 −46 Sources/KeyboardShortcuts/KeyboardShortcuts.swift
  13. +2 −0 Sources/KeyboardShortcuts/Localization/ar.lproj/Localizable.strings
  14. +2 −0 Sources/KeyboardShortcuts/Localization/cs.lproj/Localizable.strings
  15. +2 −0 Sources/KeyboardShortcuts/Localization/de.lproj/Localizable.strings
  16. +2 −0 Sources/KeyboardShortcuts/Localization/en.lproj/Localizable.strings
  17. +2 −0 Sources/KeyboardShortcuts/Localization/es.lproj/Localizable.strings
  18. +2 −0 Sources/KeyboardShortcuts/Localization/fr.lproj/Localizable.strings
  19. +2 −0 Sources/KeyboardShortcuts/Localization/hu.lproj/Localizable.strings
  20. +3 −0 Sources/KeyboardShortcuts/Localization/ja.lproj/Localizable.strings
  21. +2 −0 Sources/KeyboardShortcuts/Localization/ko.lproj/Localizable.strings
  22. +2 −0 Sources/KeyboardShortcuts/Localization/nl.lproj/Localizable.strings
  23. +2 −0 Sources/KeyboardShortcuts/Localization/pt-BR.lproj/Localizable.strings
  24. +2 −0 Sources/KeyboardShortcuts/Localization/ru.lproj/Localizable.strings
  25. +7 −5 Sources/KeyboardShortcuts/Localization/sk.lproj/Localizable.strings
  26. +5 −2 Sources/KeyboardShortcuts/Localization/zh-Hans.lproj/Localizable.strings
  27. +3 −0 Sources/KeyboardShortcuts/Localization/zh-TW.lproj/Localizable.strings
  28. +17 −22 Sources/KeyboardShortcuts/NSMenuItem++.swift
  29. +2 −2 Sources/KeyboardShortcuts/Name.swift
  30. +3 −8 Sources/KeyboardShortcuts/Recorder.swift
  31. +39 −20 Sources/KeyboardShortcuts/RecorderCocoa.swift
  32. +557 −116 Sources/KeyboardShortcuts/Shortcut.swift
  33. +119 −32 Sources/KeyboardShortcuts/Utilities.swift
  34. +83 −4 Sources/KeyboardShortcuts/ViewModifiers.swift
  35. +4 −3 readme.md
43 changes: 35 additions & 8 deletions .swiftlint.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
only_rules:
- anyobject_protocol
- accessibility_trait_for_button
- array_init
- blanket_disable_command
- block_based_kvo
- class_delegate_protocol
- closing_brace
@@ -10,6 +11,7 @@ only_rules:
- collection_alignment
- colon
- comma
- comma_inheritance
- compiler_protocol_init
- computed_accessors_order
- conditional_returns_on_newline
@@ -20,13 +22,15 @@ only_rules:
- control_statement
- custom_rules
- deployment_target
- direct_return
- discarded_notification_center_observer
- discouraged_assert
- discouraged_direct_init
- discouraged_none_name
- discouraged_object_literal
- discouraged_optional_boolean
- discouraged_optional_collection
- duplicate_conditions
- duplicate_enum_cases
- duplicate_imports
- duplicated_key_in_dictionary_literal
@@ -42,6 +46,7 @@ only_rules:
- explicit_init
- fallthrough
- fatal_error_message
- final_test_case
- first_where
- flatmap_over_map_reduce
- for_where
@@ -52,7 +57,7 @@ only_rules:
- implicit_getter
- implicit_return
- inclusive_language
- inert_defer
- invalid_swiftlint_command
- is_disjoint
- joined_default_parameter
- last_where
@@ -69,6 +74,7 @@ only_rules:
- mark
- modifier_order
- multiline_arguments
- multiline_arguments_brackets
- multiline_function_chains
- multiline_literal_brackets
- multiline_parameters
@@ -77,19 +83,22 @@ only_rules:
- no_extension_access_modifier
- no_fallthrough_only
- no_space_in_method_call
- non_optional_string_data_conversion
- non_overridable_class_declaration
- notification_center_detachment
- ns_number_init_as_function_reference
- nsobject_prefer_isequal
- number_separator
- opening_brace
- operator_usage_whitespace
- operator_whitespace
- orphaned_doc_comment
- overridden_super_call
- prefer_self_in_static_references
- prefer_self_type_over_type_of_self
- prefer_zero_over_explicit_init
- private_action
- private_outlet
- private_subject
- private_swiftui_state
- private_unit_test
- prohibited_super_call
- protocol_property_accessors_order
@@ -105,12 +114,18 @@ only_rules:
- redundant_void_return
- required_enum_case
- return_arrow_whitespace
- return_value_from_void_function
- self_binding
- self_in_property_initialization
- shorthand_operator
- shorthand_optional_binding
- sorted_first_last
- statement_position
- static_operator
- static_over_final_class
- strong_iboutlet
- superfluous_disable_command
- superfluous_else
- switch_case_alignment
- switch_case_on_newline
- syntactic_sugar
@@ -121,12 +136,13 @@ only_rules:
- trailing_newline
- trailing_semicolon
- trailing_whitespace
- unavailable_condition
- unavailable_function
- unneeded_break_in_switch
- unneeded_override
- unneeded_parentheses_in_closure_argument
- unowned_variable_capture
- untyped_error_in_catch
- unused_capture_list
- unused_closure_parameter
- unused_control_flow_label
- unused_enumerated
@@ -137,14 +153,19 @@ only_rules:
- vertical_parameter_alignment_on_call
- vertical_whitespace_closing_braces
- vertical_whitespace_opening_braces
- void_function_in_ternary
- void_return
- xct_specific_matcher
- xctfail_message
- yoda_condition
analyzer_rules:
- capture_variable
- typesafe_array_init
- unneeded_synthesized_initializer
- unused_declaration
- unused_import
for_where:
allow_for_as_filter: true
number_separator:
minimum_length: 5
identifier_name:
@@ -154,7 +175,6 @@ identifier_name:
min_length:
warning: 2
error: 2
validates_start_with_lowercase: false
allowed_symbols:
- '_'
excluded:
@@ -168,6 +188,10 @@ identifier_name:
- 'y1'
- 'y2'
- 'z2'
redundant_type_annotation:
consider_default_literal_types_redundant: true
unneeded_override:
affect_initializers: true
deployment_target:
macOS_deployment_target: '10.11'
custom_rules:
@@ -191,11 +215,14 @@ custom_rules:
regex: '\bCGFloat\('
message: 'Use Double instead of CGFloat'
swiftui_state_private:
regex: '@(State|StateObject|ObservedObject|EnvironmentObject)\s+var'
message: 'SwiftUI @State/@StateObject/@ObservedObject/@EnvironmentObject properties should be private'
regex: '@(ObservedObject|EnvironmentObject)\s+var'
message: 'SwiftUI @ObservedObject and @EnvironmentObject properties should be private'
swiftui_environment_private:
regex: '@Environment\(\\\.\w+\)\s+var'
message: 'SwiftUI @Environment properties should be private'
final_class:
regex: '^class [a-zA-Z\d]+[^{]+\{'
message: 'Classes should be marked as final whenever possible. If you actually need it to be subclassable, just add `// swiftlint:disable:next final_class`.'
no_alignment_center:
regex: '\b\(alignment: .center\b'
message: 'This alignment is the default.'
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1430"
LastUpgradeVersion = "1530"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
20 changes: 13 additions & 7 deletions Example/KeyboardShortcutsExample.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
@@ -23,7 +23,6 @@
E36FB94B2609BA43004272D9 /* MainScreen.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MainScreen.swift; sourceTree = "<group>"; };
E36FB94D2609BA45004272D9 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
E36FB9502609BA45004272D9 /* Preview Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = "Preview Assets.xcassets"; sourceTree = "<group>"; };
E36FB9522609BA45004272D9 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
E36FB9532609BA45004272D9 /* KeyboardShortcutsExample.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = KeyboardShortcutsExample.entitlements; sourceTree = "<group>"; };
E36FB9622609BB83004272D9 /* AppState.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppState.swift; sourceTree = "<group>"; };
E36FB9652609BF3D004272D9 /* Utilities.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Utilities.swift; sourceTree = "<group>"; };
@@ -75,7 +74,6 @@
E36FB94B2609BA43004272D9 /* MainScreen.swift */,
E36FB9652609BF3D004272D9 /* Utilities.swift */,
E36FB94D2609BA45004272D9 /* Assets.xcassets */,
E36FB9522609BA45004272D9 /* Info.plist */,
E36FB9532609BA45004272D9 /* KeyboardShortcutsExample.entitlements */,
E36FB94F2609BA45004272D9 /* Preview Content */,
);
@@ -128,7 +126,7 @@
attributes = {
BuildIndependentTargetsInParallel = YES;
LastSwiftUpdateCheck = 1240;
LastUpgradeCheck = 1430;
LastUpgradeCheck = 1530;
TargetAttributes = {
E36FB9452609BA43004272D9 = {
CreatedOnToolsVersion = 12.4;
@@ -184,6 +182,7 @@
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS = YES;
CLANG_ANALYZER_NONNULL = YES;
CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++14";
@@ -218,6 +217,7 @@
DEBUG_INFORMATION_FORMAT = dwarf;
ENABLE_STRICT_OBJC_MSGSEND = YES;
ENABLE_TESTABILITY = YES;
ENABLE_USER_SCRIPT_SANDBOXING = YES;
GCC_C_LANGUAGE_STANDARD = gnu11;
GCC_DYNAMIC_NO_PIC = NO;
GCC_NO_COMMON_BLOCKS = YES;
@@ -232,7 +232,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
MACOSX_DEPLOYMENT_TARGET = 12.3;
MACOSX_DEPLOYMENT_TARGET = 14.4;
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
MTL_FAST_MATH = YES;
ONLY_ACTIVE_ARCH = YES;
@@ -246,6 +246,7 @@
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS = YES;
CLANG_ANALYZER_NONNULL = YES;
CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++14";
@@ -280,6 +281,7 @@
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
ENABLE_NS_ASSERTIONS = NO;
ENABLE_STRICT_OBJC_MSGSEND = YES;
ENABLE_USER_SCRIPT_SANDBOXING = YES;
GCC_C_LANGUAGE_STANDARD = gnu11;
GCC_NO_COMMON_BLOCKS = YES;
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
@@ -288,7 +290,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
MACOSX_DEPLOYMENT_TARGET = 12.3;
MACOSX_DEPLOYMENT_TARGET = 14.4;
MTL_ENABLE_DEBUG_INFO = NO;
MTL_FAST_MATH = YES;
SDKROOT = macosx;
@@ -312,14 +314,16 @@
DEVELOPMENT_TEAM = "";
ENABLE_HARDENED_RUNTIME = YES;
ENABLE_PREVIEWS = YES;
INFOPLIST_FILE = KeyboardShortcutsExample/Info.plist;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_KEY_LSApplicationCategoryType = "public.app-category.utilities";
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/../Frameworks",
);
MARKETING_VERSION = 1.0.0;
PRODUCT_BUNDLE_IDENTIFIER = com.sindresorhus.KeyboardShortcutsExample;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_STRICT_CONCURRENCY = complete;
SWIFT_VERSION = 5.0;
};
name = Debug;
@@ -339,14 +343,16 @@
DEVELOPMENT_TEAM = "";
ENABLE_HARDENED_RUNTIME = YES;
ENABLE_PREVIEWS = YES;
INFOPLIST_FILE = KeyboardShortcutsExample/Info.plist;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_KEY_LSApplicationCategoryType = "public.app-category.utilities";
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/../Frameworks",
);
MARKETING_VERSION = 1.0.0;
PRODUCT_BUNDLE_IDENTIFIER = com.sindresorhus.KeyboardShortcutsExample;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_STRICT_CONCURRENCY = complete;
SWIFT_VERSION = 5.0;
};
name = Release;
4 changes: 1 addition & 3 deletions Example/KeyboardShortcutsExample/App.swift
Original file line number Diff line number Diff line change
@@ -2,13 +2,11 @@ import SwiftUI

@main
struct AppMain: App {
@StateObject private var state = AppState()

var body: some Scene {
WindowGroup {
MainScreen()
.task {
state.createMenus()
AppState.shared.createMenus()
}
}
}
14 changes: 9 additions & 5 deletions Example/KeyboardShortcutsExample/AppState.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import SwiftUI

@MainActor
final class AppState: ObservableObject {
final class AppState {
static let shared = AppState()

private init() {}

func createMenus() {
let testMenuItem = NSMenuItem()
NSApp.mainMenu?.addItem(testMenuItem)
@@ -13,22 +17,22 @@ final class AppState: ObservableObject {
testMenu.addCallbackItem("Shortcut 1") { [weak self] in
self?.alert(1)
}
.setShortcut(for: .testShortcut1)
.setShortcut(for: .testShortcut1)

testMenu.addCallbackItem("Shortcut 2") { [weak self] in
self?.alert(2)
}
.setShortcut(for: .testShortcut2)
.setShortcut(for: .testShortcut2)

testMenu.addCallbackItem("Shortcut 3") { [weak self] in
self?.alert(3)
}
.setShortcut(for: .testShortcut3)
.setShortcut(for: .testShortcut3)

testMenu.addCallbackItem("Shortcut 4") { [weak self] in
self?.alert(4)
}
.setShortcut(for: .testShortcut4)
.setShortcut(for: .testShortcut4)
}

private func alert(_ number: Int) {
24 changes: 0 additions & 24 deletions Example/KeyboardShortcutsExample/Info.plist

This file was deleted.

Loading