From 5b73ed69df69735061b2e80b58695ad744ab1d79 Mon Sep 17 00:00:00 2001 From: Vansh Gandhi Date: Mon, 15 May 2017 14:08:01 -0700 Subject: [PATCH] Added command double tap option to activate assistant --- MacAssistant/AppDelegate.swift | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/MacAssistant/AppDelegate.swift b/MacAssistant/AppDelegate.swift index 76da7bc..1666a63 100644 --- a/MacAssistant/AppDelegate.swift +++ b/MacAssistant/AppDelegate.swift @@ -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) { @@ -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)) @@ -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?) { @@ -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?) {