 
 extension AppDelegate: NSMenuDelegate {
     func menuWillOpen(_ menu: NSMenu) {
+        var syncMenuItemTitle: String
         if isSyncing {
-            syncMenuItem.title = "Sync (Syncing)"
+            syncMenuItemTitle = "Sync (Syncing)"
+        } else if let lastSyncDate = lastSyncDate {
+            syncMenuItemTitle = "Sync (Last Sync: \(lastSyncDate.timeAgo))"
         } else {
-            syncMenuItem.title = "Sync (Last Sync: \(lastSyncDate.timeAgo))"
-        }
+            syncMenuItemTitle = "Sync (Last Sync: Never)"
+        }
+        syncMenuItem.title = syncMenuItemTitle
     }
 }


let VERBOSE = true

@NSApplicationMain
class AppDelegate: NSObject, NSApplicationDelegate {
    let statusItem = NSStatusBar.system.statusItem(withLength: NSStatusItem.squareLength)
    let popover = NSPopover()
    let menu = NSMenu()
    let syncMenuItem = NSMenuItem(title: "Sync", action: #selector(sync(sender:)), keyEquivalent: "s")
    let quitMenuItem = NSMenuItem(title: "Quit", action: #selector(terminate(sender:)), keyEquivalent: "q")
    let environment: [String: String] = [:]
    var lastSyncDate = Date()
    let dateFormatter = DateFormatter()
    let repo = "git@github.com:ivanfoong/xcode-swift-snippets.git" // TODO: needs to be configurable
    var isSyncing = false
    let githubToken = "<github token>"
    
    func applicationDidFinishLaunching(_ aNotification: Notification) {
        // Insert code here to initialize your application

        }
        menu.addItem(syncMenuItem)
        menu.addItem(NSMenuItem.separator())
        menu.addItem(configRepoMenuItem)
        menu.addItem(configGithubAPIUrlMenuItem)
        menu.addItem(configGithubTokenMenuItem)
        menu.addItem(configShowMenuItem)
        menu.addItem(configResetMenuItem)
        menu.addItem(quitMenuItem)
        menu.delegate = self
        statusItem.menu = menu
    }

    func applicationWillTerminate(_ aNotification: Notification) {
