mirror of
https://github.com/nicoverbruggen/phpmon.git
synced 2025-11-09 13:10:24 +01:00
🚧 WIP: Notify the user about PHP switch completion (#15)
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
//
|
||||
|
||||
import Cocoa
|
||||
import UserNotifications
|
||||
|
||||
@NSApplicationMain
|
||||
class AppDelegate: NSObject, NSApplicationDelegate {
|
||||
@@ -27,8 +28,9 @@ class AppDelegate: NSObject, NSApplicationDelegate {
|
||||
}
|
||||
|
||||
// MARK: - Lifecycle
|
||||
|
||||
|
||||
func applicationDidFinishLaunching(_ aNotification: Notification) {
|
||||
NSUserNotificationCenter.default.delegate = self
|
||||
self.menu.startup()
|
||||
}
|
||||
|
||||
@@ -37,3 +39,10 @@ class AppDelegate: NSObject, NSApplicationDelegate {
|
||||
}
|
||||
}
|
||||
|
||||
extension AppDelegate: NSUserNotificationCenterDelegate {
|
||||
func userNotificationCenter(_ center: NSUserNotificationCenter,
|
||||
shouldPresent notification: NSUserNotification) -> Bool {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
19
phpmon/Classes/Helpers/LocalNotification.swift
Normal file
19
phpmon/Classes/Helpers/LocalNotification.swift
Normal file
@@ -0,0 +1,19 @@
|
||||
//
|
||||
// LocalNotification.swift
|
||||
// PHP Monitor
|
||||
//
|
||||
// Created by Nico Verbruggen on 16/07/2020.
|
||||
// Copyright © 2020 Nico Verbruggen. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
class LocalNotification {
|
||||
public static func send(title: String, subtitle: String)
|
||||
{
|
||||
let notification = NSUserNotification()
|
||||
notification.title = title
|
||||
notification.subtitle = subtitle
|
||||
NSUserNotificationCenter.default.deliver(notification)
|
||||
}
|
||||
}
|
||||
@@ -211,6 +211,10 @@ class MainMenu: NSObject, NSWindowDelegate {
|
||||
DispatchQueue.main.async {
|
||||
self.updatePhpVersionInStatusBar()
|
||||
self.update()
|
||||
LocalNotification.send(
|
||||
title: "PHP \(version) is now active",
|
||||
subtitle: "PHP Monitor has finished switching to PHP \(version)."
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user