Skip to content

Commit

Permalink
Show join the next event if there is a next one
Browse files Browse the repository at this point in the history
  • Loading branch information
leits committed May 20, 2020
1 parent 1254ae3 commit 08cab0e
Showing 1 changed file with 21 additions and 11 deletions.
32 changes: 21 additions & 11 deletions MeetingBar/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class AppDelegate: NSObject, NSApplicationDelegate {
self.jHotKey.keyDownHandler = {
self.joinNextMeeting()
}

self.kHotKey.keyDownHandler = {
self.createMeeting()
}
Expand All @@ -101,7 +101,7 @@ class AppDelegate: NSObject, NSApplicationDelegate {
self.updateStatusBarMenu()
self.updateStatusBarTitle()
}

self.showEventDetailsObserver = Defaults.observe(.showEventDetails) { change in
NSLog("Change showEventDetails from \(change.oldValue) to \(change.newValue)")
self.updateStatusBarMenu()
Expand Down Expand Up @@ -136,12 +136,12 @@ class AppDelegate: NSObject, NSApplicationDelegate {
completion(NSBackgroundActivityScheduler.Result.finished)
}
}

private func scheduleUpdateEvents() {
let activity = NSBackgroundActivityScheduler(identifier: "leits.MeetingBar.updateevents")

activity.repeats = true
activity.interval = 60*5
activity.interval = 60 * 5
activity.qualityOfService = QualityOfService.userInitiated

activity.schedule { (completion: @escaping NSBackgroundActivityScheduler.CompletionHandler) in
Expand Down Expand Up @@ -201,18 +201,19 @@ class AppDelegate: NSObject, NSApplicationDelegate {
}
createJoinSection(menu: statusBarMenu)
statusBarMenu.addItem(NSMenuItem.separator())

createPreferencesSection(menu: statusBarMenu)
}

func createJoinSection(menu: NSMenu) {
if calendar != nil {
let item = menu.addItem(
withTitle: "Join next event",
action: #selector(AppDelegate.joinNextMeeting),
keyEquivalent: "j")
let nextEvent = getNextEvent(eventStore: eventStore, calendar: calendar!)
item.isEnabled = (nextEvent != nil)
if nextEvent != nil {
menu.addItem(
withTitle: "Join next event",
action: #selector(AppDelegate.joinNextMeeting),
keyEquivalent: "j")
}
}
menu.addItem(
withTitle: "Create meeting",
Expand All @@ -237,6 +238,15 @@ class AppDelegate: NSObject, NSApplicationDelegate {
titleItem.isEnabled = false

let sortedEvents = events.sorted(by: { $0.startDate < $1.startDate })

if sortedEvents.count == 0 {
let item = menu.addItem(
withTitle: "Nothing for today",
action: nil,
keyEquivalent: "")
item.isEnabled = false
}

for event in sortedEvents {
createEventItem(event: event, menu: menu)
}
Expand Down Expand Up @@ -276,7 +286,7 @@ class AppDelegate: NSObject, NSApplicationDelegate {
eventItem.state = .off
}
eventItem.representedObject = event

if Defaults[.showEventDetails] {

let eventMenu = NSMenu(title: "Item \(eventTitle) menu")
Expand Down

0 comments on commit 08cab0e

Please sign in to comment.