diff --git a/Stats/AppDelegate.swift b/Stats/AppDelegate.swift
index aa7607e8..97b8362b 100755
--- a/Stats/AppDelegate.swift
+++ b/Stats/AppDelegate.swift
@@ -24,10 +24,12 @@ var smc: SMCService = SMCService()
var modules: [Module] = [Battery(&store), Network(&store), Sensors(&store, &smc), Disk(&store), Memory(&store), CPU(&store, &smc)].reversed()
var log = OSLog(subsystem: Bundle.main.bundleIdentifier!, category: "Stats")
-class AppDelegate: NSObject, NSApplicationDelegate {
+class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCenterDelegate {
private let settingsWindow: SettingsWindow = SettingsWindow()
private let updateWindow: UpdateWindow = UpdateWindow()
+ let notification = NSUserNotification()
+
func applicationDidFinishLaunching(_ aNotification: Notification) {
let startingPoint = Date()
@@ -45,6 +47,17 @@ class AppDelegate: NSObject, NSApplicationDelegate {
os_log(.info, log: log, "Stats started in %.4f seconds", startingPoint.timeIntervalSinceNow * -1)
}
+ func userNotificationCenter(_ center: NSUserNotificationCenter, didActivate notification: NSUserNotification) {
+ if let uri = notification.userInfo?["url"] as? String {
+ os_log(.error, log: log, "Downloading new version of app...")
+ if let url = URL(string: uri) {
+ updater.download(url)
+ }
+ }
+
+ NSUserNotificationCenter.default.removeDeliveredNotification(self.notification)
+ }
+
func applicationWillTerminate(_ aNotification: Notification) {
modules.forEach{ $0.terminate() }
_ = smc.close()
@@ -163,7 +176,18 @@ class AppDelegate: NSObject, NSApplicationDelegate {
if version.newest {
DispatchQueue.main.async(execute: {
os_log(.error, log: log, "show update window because new version of app found: %s", "\(version.latest)")
- self.updateWindow.open(version)
+
+ self.notification.identifier = UUID().uuidString
+ self.notification.title = "New version available"
+ self.notification.subtitle = "Click to install the new version of Stats"
+ self.notification.soundName = NSUserNotificationDefaultSoundName
+
+ self.notification.hasActionButton = true
+ self.notification.actionButtonTitle = "Install"
+ self.notification.userInfo = ["url": version.url]
+
+ NSUserNotificationCenter.default.delegate = self
+ NSUserNotificationCenter.default.deliver(self.notification)
})
}
}
diff --git a/Stats/Supporting Files/Info.plist b/Stats/Supporting Files/Info.plist
index f82c114b..99ea1e00 100755
--- a/Stats/Supporting Files/Info.plist
+++ b/Stats/Supporting Files/Info.plist
@@ -30,5 +30,7 @@
Copyright © 2020 Serhiy Mytrovtsiy. All rights reserved.
NSPrincipalClass
NSApplication
+ NSUserNotificationAlertStyle
+ alert