Initial commit.
This commit is contained in:
92
src/AppDelegate.swift
Normal file
92
src/AppDelegate.swift
Normal file
@@ -0,0 +1,92 @@
|
||||
import Cocoa
|
||||
import ServiceManagement
|
||||
|
||||
class AppDelegate: NSObject, NSApplicationDelegate {
|
||||
// MARK: - State
|
||||
private var aboutWindow: MenulessWindow!
|
||||
private var updateWindow: MenulessWindow!
|
||||
|
||||
// MARK: - Lifecycle
|
||||
func applicationDidFinishLaunching(_ notification: Notification) {
|
||||
setupAboutWindow()
|
||||
setupUpdateWindow()
|
||||
setupNotifications()
|
||||
|
||||
setupLicense()
|
||||
|
||||
CmdManager.standard.configure()
|
||||
}
|
||||
|
||||
private func setupLicense() {
|
||||
let licenseManager = LicenseManager.standard
|
||||
if !licenseManager.isRegistered() {
|
||||
showAbout()
|
||||
licenseManager.clearLicense()
|
||||
licenseManager.startTimer()
|
||||
}
|
||||
}
|
||||
|
||||
private func setupUpdateWindow() {
|
||||
let controller = UpdateViewController()
|
||||
controller.setUpdateDelegate()
|
||||
|
||||
updateWindow = MenulessWindow(viewController: controller)
|
||||
updateWindow.title = "Software Update"
|
||||
}
|
||||
|
||||
func applicationWillTerminate(_ notification: Notification) {
|
||||
persistMenuBar(false)
|
||||
CmdManager.standard.clearItems()
|
||||
}
|
||||
|
||||
// MARK: - Notifications
|
||||
private func setupNotifications() {
|
||||
NSWorkspace.shared.notificationCenter.addObserver(
|
||||
self,
|
||||
selector: #selector(wakeUp),
|
||||
name: NSWorkspace.didWakeNotification,
|
||||
object: nil)
|
||||
}
|
||||
|
||||
@objc private func wakeUp() {
|
||||
CmdManager.standard.resetTimers()
|
||||
}
|
||||
|
||||
// MARK: - Status Items
|
||||
@objc func reloadWidgets() {
|
||||
CmdManager.standard.reloadItems()
|
||||
}
|
||||
|
||||
@objc func terminateApp() {
|
||||
DispatchQueue.main.async {
|
||||
NSApplication.shared.terminate(self)
|
||||
}
|
||||
}
|
||||
|
||||
@objc func checkForUpdates() {
|
||||
NSApplication.shared.activate(ignoringOtherApps: true)
|
||||
updateWindow.makeKeyAndOrderFront(nil)
|
||||
updateWindow.center()
|
||||
}
|
||||
|
||||
// MARK: - Setup About Window
|
||||
private func setupAboutWindow() {
|
||||
aboutWindow = MenulessWindow(viewController: AboutViewController())
|
||||
}
|
||||
|
||||
// MARK: - Show About Window
|
||||
@objc func showAbout() {
|
||||
NSApplication.shared.activate(ignoringOtherApps: true)
|
||||
aboutWindow.makeKeyAndOrderFront(nil)
|
||||
}
|
||||
|
||||
// MARK: - Launch at Login
|
||||
func toggleLaunchAtLogin() {
|
||||
let service = SMAppService.mainApp
|
||||
if service.status == .enabled {
|
||||
try? service.unregister()
|
||||
} else {
|
||||
try? service.register()
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user