Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Allow to customize popup hotkey
- Loading branch information
Showing
5 changed files
with
67 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,17 @@ | ||
import Cocoa | ||
import HotKey | ||
|
||
@NSApplicationMain | ||
class AppDelegate: NSObject, NSApplicationDelegate { | ||
let clipboard = Clipboard() | ||
let history = History() | ||
let hotKey = HotKey(key: .c, modifiers: [.command, .shift]) | ||
|
||
let hotKey = GlobalHotKey() | ||
var maccy: Maccy { | ||
return Maccy(history: history, clipboard: clipboard) | ||
} | ||
|
||
func applicationDidFinishLaunching(_ aNotification: Notification) { | ||
maccy.start() | ||
hotKey.keyDownHandler = { self.maccy.popUp() } | ||
hotKey.handler = { self.maccy.popUp() } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import HotKey | ||
|
||
class GlobalHotKey { | ||
var handler: HotKey.Handler? { | ||
get { return hotKey?.keyDownHandler } | ||
set(newHandler) { hotKey?.keyDownHandler = newHandler } | ||
} | ||
|
||
private let hotKeyStore = "hotKey" | ||
private let defaultKeyBinding = "command+shift+c" | ||
private var hotKey: HotKey? = nil | ||
|
||
init() { | ||
UserDefaults.standard.register(defaults: [hotKeyStore: defaultKeyBinding]) | ||
registerHotKey() | ||
} | ||
|
||
private func registerHotKey() { | ||
guard let keybindingString = UserDefaults.standard.string(forKey: hotKeyStore) else { | ||
return | ||
} | ||
var keysList = keybindingString.split(separator: "+") | ||
|
||
guard let keyString = keysList.popLast() else { | ||
return | ||
} | ||
guard let key = Key(string: String(keyString)) else { | ||
return | ||
} | ||
|
||
var modifiers: NSEvent.ModifierFlags = [] | ||
for keyString in keysList { | ||
switch (keyString) { | ||
case "command": | ||
modifiers.insert(.command) | ||
case "control": | ||
modifiers.insert(.control) | ||
case "option": | ||
modifiers.insert(.option) | ||
case "shift": | ||
modifiers.insert(.shift) | ||
default: () | ||
} | ||
} | ||
|
||
hotKey = HotKey(key: key, modifiers: modifiers) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters