dotBeatBar/dotBeatBar_old/AppDelegate.swift

42 lines
1.2 KiB
Swift

//
// AppDelegate.swift
// dotBeatBar_old
//
// Created by Aaron Bieber on 7/26/19.
// Copyright © 2019 Aaron Bieber. All rights reserved.
//
import Beat
import Cocoa
import Foundation
@NSApplicationMain
class AppDelegate: NSObject, NSApplicationDelegate {
var timer = Timer()
let si = NSStatusBar.system.statusItem(withLength:NSStatusItem.variableLength)
@objc func updateStatBar(_ sender: Any?) {
if let button = si.button {
button.title = "@\(Beat().text())"
}
}
func applicationDidFinishLaunching(_ aNotification: Notification) {
updateStatBar(self)
timer = Timer.scheduledTimer(timeInterval: 1,
target: self,
selector: #selector(updateStatBar),
userInfo: nil,
repeats: true)
let menu = NSMenu()
menu.addItem(NSMenuItem(title: "Quit", action:
#selector(NSApplication.terminate(_:)), keyEquivalent: "q"))
si.menu = menu
}
func applicationWillTerminate(_ aNotification: Notification) {
// Insert code here to tear down your application
timer.invalidate()
}
}