diff --git a/.github/workflows/documentation.yml b/.github/workflows/documentation.yml new file mode 100644 index 00000000..954ead91 --- /dev/null +++ b/.github/workflows/documentation.yml @@ -0,0 +1,25 @@ +name: Generate documentation +on: + push: + branches: + - main + # tags: + # - '*' +jobs: + deploy: + runs-on: macos-12 + steps: + - uses: actions/checkout@v3 + - name: DocC + run: > + swift package --allow-writing-to-directory docs + generate-documentation --target KeyboardShortcuts + --disable-indexing + --transform-for-static-hosting + --hosting-base-path KeyboardShortcuts + --output-path docs + - name: Deploy + uses: peaceiris/actions-gh-pages@v3 + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + publish_dir: ./docs diff --git a/.github/workflows/jazzy.yml b/.github/workflows/jazzy.yml deleted file mode 100644 index 29cd3fde..00000000 --- a/.github/workflows/jazzy.yml +++ /dev/null @@ -1,14 +0,0 @@ -name: Publish docs -on: - release: - types: [published] -jobs: - deploy: - runs-on: macos-latest - steps: - - uses: actions/checkout@v2 - - name: Publish docs - uses: steven0351/publish-jazzy-docs@v1 - with: - personal_access_token: ${{ secrets.ACCESS_TOKEN }} - config: .jazzy.yml diff --git a/.github/workflows/swiftlint.yml b/.github/workflows/swiftlint.yml index 27653452..00cebf20 100644 --- a/.github/workflows/swiftlint.yml +++ b/.github/workflows/swiftlint.yml @@ -9,6 +9,6 @@ jobs: lint: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: SwiftLint uses: norio-nomura/action-swiftlint@3.2.1 diff --git a/.jazzy.yml b/.jazzy.yml deleted file mode 100644 index 4a6f4647..00000000 --- a/.jazzy.yml +++ /dev/null @@ -1,12 +0,0 @@ -module: KeyboardShortcuts -github_url: https://github.com/sindresorhus/KeyboardShortcuts -root_url: https://sindresorhus.com/KeyboardShortcuts -copyright: MIT License © [Sindre Sorhus](https://sindresorhus.com) -swift_build_tool: spm -build_tool_arguments: - - '-Xswiftc' - - '-swift-version' - - '-Xswiftc' - - '5' -theme: fullwidth -hide_documentation_coverage: true diff --git a/Package.resolved b/Package.resolved new file mode 100644 index 00000000..528fbc10 --- /dev/null +++ b/Package.resolved @@ -0,0 +1,14 @@ +{ + "pins" : [ + { + "identity" : "swift-docc-plugin", + "kind" : "remoteSourceControl", + "location" : "https://github.com/apple/swift-docc-plugin", + "state" : { + "revision" : "3303b164430d9a7055ba484c8ead67a52f7b74f6", + "version" : "1.0.0" + } + } + ], + "version" : 2 +} diff --git a/Package.swift b/Package.swift index 333739a2..59e89b3e 100644 --- a/Package.swift +++ b/Package.swift @@ -1,4 +1,4 @@ -// swift-tools-version:5.5 +// swift-tools-version:5.6 import PackageDescription let package = Package( @@ -15,6 +15,9 @@ let package = Package( ] ) ], + dependencies: [ + .package(url: "https://github.com/apple/swift-docc-plugin", from: "1.0.0"), + ], targets: [ .target( name: "KeyboardShortcuts" diff --git a/Sources/KeyboardShortcuts/KeyboardShortcuts.swift b/Sources/KeyboardShortcuts/KeyboardShortcuts.swift index cdfcbdaf..e9c418b5 100644 --- a/Sources/KeyboardShortcuts/KeyboardShortcuts.swift +++ b/Sources/KeyboardShortcuts/KeyboardShortcuts.swift @@ -4,16 +4,13 @@ import Cocoa Global keyboard shortcuts for your macOS app. */ public enum KeyboardShortcuts { - /// :nodoc: - public typealias KeyAction = () -> Void - private static var registeredShortcuts = Set() - private static var legacyKeyDownHandlers = [Name: [KeyAction]]() - private static var legacyKeyUpHandlers = [Name: [KeyAction]]() + private static var legacyKeyDownHandlers = [Name: [() -> Void]]() + private static var legacyKeyUpHandlers = [Name: [() -> Void]]() - private static var streamKeyDownHandlers = [Name: [UUID: KeyAction]]() - private static var streamKeyUpHandlers = [Name: [UUID: KeyAction]]() + private static var streamKeyDownHandlers = [Name: [UUID: () -> Void]]() + private static var streamKeyUpHandlers = [Name: [UUID: () -> Void]]() private static var shortcutsForLegacyHandlers: Set { let shortcuts = [legacyKeyDownHandlers.keys, legacyKeyUpHandlers.keys] @@ -145,7 +142,7 @@ public enum KeyboardShortcuts { If the `Name` has a default shortcut, it will reset to that. - ``` + ```swift import SwiftUI import KeyboardShortcuts @@ -175,7 +172,7 @@ public enum KeyboardShortcuts { - Note: This overload exists as Swift doesn't support splatting. - ``` + ```swift import SwiftUI import KeyboardShortcuts @@ -289,7 +286,7 @@ public enum KeyboardShortcuts { You can safely call this even if the user has not yet set a keyboard shortcut. It will just be inactive until they do. - ``` + ```swift import Cocoa import KeyboardShortcuts @@ -303,7 +300,7 @@ public enum KeyboardShortcuts { } ``` */ - public static func onKeyDown(for name: Name, action: @escaping KeyAction) { + public static func onKeyDown(for name: Name, action: @escaping () -> Void) { legacyKeyDownHandlers[name, default: []].append(action) registerShortcutIfNeeded(for: name) } @@ -315,7 +312,7 @@ public enum KeyboardShortcuts { You can safely call this even if the user has not yet set a keyboard shortcut. It will just be inactive until they do. - ``` + ```swift import Cocoa import KeyboardShortcuts @@ -329,7 +326,7 @@ public enum KeyboardShortcuts { } ``` */ - public static func onKeyUp(for name: Name, action: @escaping KeyAction) { + public static func onKeyUp(for name: Name, action: @escaping () -> Void) { legacyKeyUpHandlers[name, default: []].append(action) registerShortcutIfNeeded(for: name) } @@ -389,7 +386,7 @@ extension KeyboardShortcuts { Ending the async sequence will stop the listener. For example, in the below example, the listener will stop when the view disappears. - ``` + ```swift import SwiftUI import KeyboardShortcuts diff --git a/Sources/KeyboardShortcuts/NSMenuItem++.swift b/Sources/KeyboardShortcuts/NSMenuItem++.swift index caa36a8a..f75bfee7 100644 --- a/Sources/KeyboardShortcuts/NSMenuItem++.swift +++ b/Sources/KeyboardShortcuts/NSMenuItem++.swift @@ -20,7 +20,7 @@ extension NSMenuItem { This method overrides `.keyEquivalent` and `.keyEquivalentModifierMask`. - ``` + ```swift import Cocoa import KeyboardShortcuts diff --git a/Sources/KeyboardShortcuts/Name.swift b/Sources/KeyboardShortcuts/Name.swift index 3ac9052c..4bacd7fd 100644 --- a/Sources/KeyboardShortcuts/Name.swift +++ b/Sources/KeyboardShortcuts/Name.swift @@ -4,7 +4,7 @@ extension KeyboardShortcuts { After registering it, you can use it in, for example, `KeyboardShortcut.Recorder` and `KeyboardShortcut.onKeyUp()`. - ``` + ```swift import KeyboardShortcuts extension KeyboardShortcuts.Name { diff --git a/Sources/KeyboardShortcuts/Recorder.swift b/Sources/KeyboardShortcuts/Recorder.swift index 42f1fee9..c219bc01 100644 --- a/Sources/KeyboardShortcuts/Recorder.swift +++ b/Sources/KeyboardShortcuts/Recorder.swift @@ -26,7 +26,7 @@ extension KeyboardShortcuts { It takes care of storing the keyboard shortcut in `UserDefaults` for you. - ``` + ```swift import SwiftUI import KeyboardShortcuts diff --git a/Sources/KeyboardShortcuts/RecorderCocoa.swift b/Sources/KeyboardShortcuts/RecorderCocoa.swift index 2220eb4e..c2e6753a 100644 --- a/Sources/KeyboardShortcuts/RecorderCocoa.swift +++ b/Sources/KeyboardShortcuts/RecorderCocoa.swift @@ -11,7 +11,7 @@ extension KeyboardShortcuts { It takes care of storing the keyboard shortcut in `UserDefaults` for you. - ``` + ```swift import Cocoa import KeyboardShortcuts diff --git a/Sources/KeyboardShortcuts/Shortcut.swift b/Sources/KeyboardShortcuts/Shortcut.swift index 9de50528..0e2564e2 100644 --- a/Sources/KeyboardShortcuts/Shortcut.swift +++ b/Sources/KeyboardShortcuts/Shortcut.swift @@ -283,8 +283,8 @@ extension KeyboardShortcuts.Shortcut: CustomStringConvertible { /** The string representation of the keyboard shortcut. - ``` - print(Shortcut(.a, modifiers: [.command])) + ```swift + print(KeyboardShortcuts.Shortcut(.a, modifiers: [.command])) //=> "⌘A" ``` */