Skip to content

Commit

Permalink
WIP - Switch to DocC
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed Mar 30, 2022
1 parent 0dcedd5 commit 83af2c0
Show file tree
Hide file tree
Showing 12 changed files with 61 additions and 48 deletions.
25 changes: 25 additions & 0 deletions .github/workflows/documentation.yml
Original file line number Diff line number Diff line change
@@ -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
14 changes: 0 additions & 14 deletions .github/workflows/jazzy.yml

This file was deleted.

2 changes: 1 addition & 1 deletion .github/workflows/swiftlint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: SwiftLint
uses: norio-nomura/[email protected]
12 changes: 0 additions & 12 deletions .jazzy.yml

This file was deleted.

14 changes: 14 additions & 0 deletions Package.resolved
Original file line number Diff line number Diff line change
@@ -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
}
5 changes: 4 additions & 1 deletion Package.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version:5.5
// swift-tools-version:5.6
import PackageDescription

let package = Package(
Expand All @@ -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"
Expand Down
25 changes: 11 additions & 14 deletions Sources/KeyboardShortcuts/KeyboardShortcuts.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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<Shortcut>()

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<Shortcut> {
let shortcuts = [legacyKeyDownHandlers.keys, legacyKeyUpHandlers.keys]
Expand Down Expand Up @@ -145,7 +142,7 @@ public enum KeyboardShortcuts {
If the `Name` has a default shortcut, it will reset to that.
```
```swift
import SwiftUI
import KeyboardShortcuts
Expand Down Expand Up @@ -175,7 +172,7 @@ public enum KeyboardShortcuts {
- Note: This overload exists as Swift doesn't support splatting.
```
```swift
import SwiftUI
import KeyboardShortcuts
Expand Down Expand Up @@ -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
Expand All @@ -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)
}
Expand All @@ -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
Expand All @@ -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)
}
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Sources/KeyboardShortcuts/NSMenuItem++.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ extension NSMenuItem {
This method overrides `.keyEquivalent` and `.keyEquivalentModifierMask`.
```
```swift
import Cocoa
import KeyboardShortcuts
Expand Down
2 changes: 1 addition & 1 deletion Sources/KeyboardShortcuts/Name.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion Sources/KeyboardShortcuts/Recorder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ extension KeyboardShortcuts {
It takes care of storing the keyboard shortcut in `UserDefaults` for you.
```
```swift
import SwiftUI
import KeyboardShortcuts
Expand Down
2 changes: 1 addition & 1 deletion Sources/KeyboardShortcuts/RecorderCocoa.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ extension KeyboardShortcuts {
It takes care of storing the keyboard shortcut in `UserDefaults` for you.
```
```swift
import Cocoa
import KeyboardShortcuts
Expand Down
4 changes: 2 additions & 2 deletions Sources/KeyboardShortcuts/Shortcut.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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"
```
*/
Expand Down

0 comments on commit 83af2c0

Please sign in to comment.