Skip to content

Commit

Permalink
Add option to disable shortcuts
Browse files Browse the repository at this point in the history
  • Loading branch information
leits committed Jun 1, 2020
1 parent f1d22a4 commit ee81f69
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 8 deletions.
39 changes: 31 additions & 8 deletions MeetingBar/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ extension Defaults.Keys {
static let launchAtLogin = Key<Bool>("launchAtLogin", default: false)
static let showEventDetails = Key<Bool>("showEventDetails", default: true)
static let createMeetingService = Key<MeetingServices>("createMeetingService", default: .meet)
static let enableShortcuts = Key<Bool>("enableShortcuts", default: true)
}

@NSApplicationMain
Expand All @@ -44,12 +45,13 @@ class AppDelegate: NSObject, NSApplicationDelegate {
private let eventStore = EKEventStore()
private var calendar: EKCalendar?
// TODO: calendars instead of calendar
private let jHotKey = HotKey(key: .j, modifiers: [.command])
private let kHotKey = HotKey(key: .k, modifiers: [.command])
private var jHotKey: HotKey? = HotKey(key: .j, modifiers: [.command])
private var kHotKey: HotKey? = HotKey(key: .k, modifiers: [.command])

var calendarTitleObserver: DefaultsObservation?
var launchAtLoginObserver: DefaultsObservation?
var showEventDetailsObserver: DefaultsObservation?
var enableShortcutsObserver: DefaultsObservation?

func applicationDidFinishLaunching(_: Notification) {
eventStoreAccessCheck(eventStore: eventStore, completion: { result in
Expand Down Expand Up @@ -82,13 +84,17 @@ class AppDelegate: NSObject, NSApplicationDelegate {

self.updateStatusBarMenu()
self.updateStatusBarTitle()

self.jHotKey.keyDownHandler = {
self.joinNextMeeting()

if let hotkey = self.jHotKey {
hotkey.keyDownHandler = {
self.joinNextMeeting()
}
}

self.kHotKey.keyDownHandler = {
self.createMeeting()

if let hotkey = self.kHotKey {
hotkey.keyDownHandler = {
self.createMeeting()
}
}

self.scheduleUpdateStatusBarTitle()
Expand Down Expand Up @@ -116,6 +122,23 @@ class AppDelegate: NSObject, NSApplicationDelegate {
NSApp.disableRelaunchOnLogin()
}
}

self.enableShortcutsObserver = Defaults.observe(.enableShortcuts) { change in
NSLog("Change enableShortcuts from \(change.oldValue) to \(change.newValue)")
if change.newValue {
self.jHotKey = HotKey(key: .j, modifiers: [.command])
self.jHotKey!.keyDownHandler = {
self.joinNextMeeting()
}
self.kHotKey = HotKey(key: .k, modifiers: [.command])
self.kHotKey!.keyDownHandler = {
self.createMeeting()
}
} else {
self.jHotKey = nil
self.kHotKey = nil
}
}
}
}

Expand Down
4 changes: 4 additions & 0 deletions MeetingBar/Preferences.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ struct ContentView: View {
@Default(.launchAtLogin) var launchAtLogin
@Default(.showEventDetails) var showEventDetails
@Default(.createMeetingService) var createMeetingService
@Default(.enableShortcuts) var enableShortcuts

let calendars: [EKCalendar]

Expand All @@ -41,6 +42,9 @@ struct ContentView: View {
}

Divider()
Toggle(isOn: $enableShortcuts) {
Text("Shortcuts")
}
Toggle(isOn: $launchAtLogin) {
Text("Launch at login")
}
Expand Down

0 comments on commit ee81f69

Please sign in to comment.