Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow parameter to be used with HotKey action #9

Merged
merged 4 commits into from
Oct 30, 2018
Merged

Conversation

kphrx
Copy link
Contributor

@kphrx kphrx commented Mar 4, 2018

This change allows you to take advantage of the arguments passed to the callback.

 func applicationDidFinishLaunching(_ aNotification: Notification) {
     // ⌘ + Control + B
     guard let keyCombo: KeyCombo = KeyCombo(keyCode: 11, carbonModifiers: 4352) else { return }
     let hotKey: HotKey = HotKey(identifier: "CommandControlB",
                                 keyCombo: keyCombo,
                                 target: self,
-                                action: #selector(AppDelegate.handleHotKeyEvent))
+                                action: #selector(AppDelegate.handleHotKeyEvent(_:)))
     hotKey.register()
 }

-@objc func handleHotKeyEvent() {
+@objc func handleHotKeyEvent(_ hotKey: HotKey) {
-    print("CommandControlB") // CommandControlB
+    let identifier = hotKey.identifier
+    print(identifier) // CommandControlB
 }

@kphrx
Copy link
Contributor Author

kphrx commented Oct 29, 2018

This function is possible by using the closure supported by this PR (#20).

 func applicationDidFinishLaunching(_ aNotification: Notification) {
     // ⌘ + Control + B
     guard let keyCombo: KeyCombo = KeyCombo(keyCode: 11, carbonModifiers: 4352) else { return }
     let hotKey: HotKey = HotKey(identifier: "CommandControlB",
                                 keyCombo: keyCombo,
-                                target: self,
-                                action: #selector(AppDelegate.handleHotKeyEvent(_:)))
+                                handler: handleHotKeyEvent)
     hotKey.register()
 }

-@objc func handleHotKeyEvent(_ hotKey: HotKey) {
+func handleHotKeyEvent(_ hotKey: HotKey) {
     let identifier = hotKey.identifier
     print(identifier) // CommandControlB
 }

Copy link
Member

@Econa77 Econa77 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kpherox Sorry for late reply. I made some reviews so can you fix it?

Lib/Magnet/HotKey.swift Outdated Show resolved Hide resolved
Lib/Magnet/HotKey.swift Show resolved Hide resolved
Lib/Magnet/HotKey.swift Outdated Show resolved Hide resolved
Copy link
Member

@Econa77 Econa77 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍 Thanks :)

@Econa77 Econa77 merged commit bea0c82 into Clipy:master Oct 30, 2018
@Econa77
Copy link
Member

Econa77 commented Oct 30, 2018

Released v2.3.1 🎉

@kphrx kphrx changed the title Add @objc annotation Allow parameter to be used with HotKey action Oct 30, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants