Skip to content

Commit

Permalink
Added command double tap option to activate assistant
Browse files Browse the repository at this point in the history
  • Loading branch information
vanshg committed May 15, 2017
1 parent 6708a50 commit 5b73ed6
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions MacAssistant/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ class AppDelegate: NSObject, NSApplicationDelegate {
public override init() {
super.init()
popover.contentViewController = NSViewController(nibName: "LoadingView", bundle: nil)
registerHotkey() // TODO: Proper interaction between hotkey and window
// popover.appearance = NSAppearance(named: NSAppearanceNameVibrantDark)
// registerHotkey() // TODO: Proper interaction between hotkey and window
}

func applicationWillFinishLaunching(_ notification: Notification) {
Expand Down Expand Up @@ -60,8 +60,8 @@ class AppDelegate: NSObject, NSApplicationDelegate {
}

func registerHotkey() {
guard let keyCombo = KeyCombo(doubledCocoaModifiers: .control) else { return }
let hotKey = HotKey(identifier: "ControlDoubleTap",
guard let keyCombo = KeyCombo(doubledCocoaModifiers: .command) else { return }
let hotKey = HotKey(identifier: "CommandDoubleTapped",
keyCombo: keyCombo,
target: self,
action: #selector(AppDelegate.hotkeyPressed))
Expand All @@ -71,14 +71,16 @@ class AppDelegate: NSObject, NSApplicationDelegate {
func hotkeyPressed(sender: AnyObject?) {
if !popover.isShown {
showPopover(sender: sender)
if (isLoggedIn) {
(popover.contentViewController as? AssistantViewController)?.startListening()
}
} else if let controller = popover.contentViewController as? AssistantViewController {
if controller.isListening {
controller.stopListening()
} else {
controller.startListening()
}
}
if (isLoggedIn) {
(popover.contentViewController as? AssistantViewController)?.startListening()
}
}

func statusIconClicked(sender: AnyObject?) {
Expand All @@ -92,10 +94,10 @@ class AppDelegate: NSObject, NSApplicationDelegate {
}

func closePopover(sender: AnyObject?) {
popover.performClose(sender)
if let controller = popover.contentViewController as? AssistantViewController {
controller.stopListening()
}
popover.performClose(sender)
}

func togglePopover(sender: AnyObject?) {
Expand Down

0 comments on commit 5b73ed6

Please sign in to comment.