Skip to content

Commit

Permalink
Add create meeting feature
Browse files Browse the repository at this point in the history
  • Loading branch information
leits committed May 20, 2020
1 parent f602aee commit 1254ae3
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 12 deletions.
57 changes: 45 additions & 12 deletions MeetingBar/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ struct LinksRegex {
static let zoom = try! NSRegularExpression(pattern: #"https://zoom.us/j/.*"#)
}

enum MeetingServices: String, Codable, CaseIterable {
case meet = "Google Meet"
case zoom = "Zoom"
}

enum AuthResult {
case success(Bool), failure(Error)
}
Expand All @@ -27,6 +32,7 @@ extension Defaults.Keys {
static let useChromeForMeetLinks = Key<Bool>("useChromeForMeetLinks", default: false)
static let launchAtLogin = Key<Bool>("launchAtLogin", default: false)
static let showEventDetails = Key<Bool>("showEventDetails", default: true)
static let createMeetingService = Key<MeetingServices>("createMeetingService", default: .meet)
}

@NSApplicationMain
Expand All @@ -37,7 +43,8 @@ class AppDelegate: NSObject, NSApplicationDelegate {

private let eventStore = EKEventStore()
private var calendar: EKCalendar?
private let hotKey = HotKey(key: .j, modifiers: [.command])
private let jHotKey = HotKey(key: .j, modifiers: [.command])
private let kHotKey = HotKey(key: .k, modifiers: [.command])

var calendarTitleObserver: DefaultsObservation?
var launchAtLoginObserver: DefaultsObservation?
Expand Down Expand Up @@ -75,9 +82,13 @@ class AppDelegate: NSObject, NSApplicationDelegate {
self.updateStatusBarMenu()
self.updateStatusBarTitle()

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

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

self.scheduleUpdateStatusBarTitle()
self.scheduleUpdateEvents()
Expand Down Expand Up @@ -185,22 +196,28 @@ class AppDelegate: NSObject, NSApplicationDelegate {
statusBarMenu.removeAllItems()

if calendar != nil {
createJoinNextSection(menu: statusBarMenu)
statusBarMenu.addItem(NSMenuItem.separator())

createTodaySection(menu: statusBarMenu)
statusBarMenu.addItem(NSMenuItem.separator())
}
createJoinSection(menu: statusBarMenu)
statusBarMenu.addItem(NSMenuItem.separator())

createPreferencesSection(menu: statusBarMenu)
}

func createJoinNextSection(menu: NSMenu) {
let item = menu.addItem(
withTitle: "Join next meeting",
action: #selector(AppDelegate.joinNextMeeting),
keyEquivalent: "j")
let nextEvent = getNextEvent(eventStore: eventStore, calendar: calendar!)
item.isEnabled = (nextEvent != nil)
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)
}
menu.addItem(
withTitle: "Create meeting",
action: #selector(AppDelegate.createMeeting),
keyEquivalent: "k")
}

func createTodaySection(menu: NSMenu) {
Expand Down Expand Up @@ -393,6 +410,22 @@ class AppDelegate: NSObject, NSApplicationDelegate {
openEvent(nextEvent!)
}

@objc func createMeeting(_: NSStatusBarButton? = nil) {
NSLog("Create meeting in \(Defaults[.createMeetingService].rawValue)")
switch Defaults[.createMeetingService] {
case .meet:
let meetLink = "https://meet.google.com/new"
if Defaults[.useChromeForMeetLinks] {
openLinkInChrome(meetLink)
} else {
openLinkInDefaultBrowser(meetLink)
}
case .zoom:
openLinkInDefaultBrowser("https://zoom.us/start/videomeeting")

}
}

@objc func clickOnEvent(sender: NSMenuItem) {
NSLog("Click on event (\(sender.title))!")
let event: EKEvent = sender.representedObject as! EKEvent
Expand Down
6 changes: 6 additions & 0 deletions MeetingBar/Preferences.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ struct ContentView: View {
@Default(.useChromeForMeetLinks) var useChromeForMeetLinks
@Default(.launchAtLogin) var launchAtLogin
@Default(.showEventDetails) var showEventDetails
@Default(.createMeetingService) var createMeetingService

let calendars: [EKCalendar]

Expand All @@ -26,6 +27,11 @@ struct ContentView: View {
.tag(self.calendars[index].title)
}
}
Picker(selection: $createMeetingService, label: Text("Create meetings in ")) {
ForEach(MeetingServices.allCases, id: \.self) {
Text($0.rawValue).tag($0)
}
}
Toggle(isOn: $useChromeForMeetLinks) {
Text("Use Chrome for Google Meet links")
}
Expand Down

0 comments on commit 1254ae3

Please sign in to comment.