1
0
mirror of https://github.com/nicoverbruggen/phpmon.git synced 2025-11-09 05:40:07 +01:00

♻️ Require at least macOS 11, various refactors

This commit is contained in:
2021-12-05 02:54:03 +01:00
parent 924edf6f96
commit 46867ad25e
8 changed files with 55 additions and 27 deletions

View File

@@ -49,6 +49,10 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCenterDele
When the application initializes, create all singletons.
*/
override init() {
print("==================================")
print("PHP MONITOR by Nico Verbruggen")
print("Version \(App.version)")
print("==================================")
self.sharedShell = Shell.user
self.state = App.shared
self.menu = MainMenu.shared
@@ -61,27 +65,12 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCenterDele
/**
When the application has finished launching, we'll want to set up
the user notification center delegate, and kickoff the menu
the user notification center permissions, and kickoff the menu
startup procedure.
*/
func applicationDidFinishLaunching(_ aNotification: Notification) {
NSUserNotificationCenter.default.delegate = self
LocalNotification.askForPermission()
self.menu.startup()
}
// MARK: - NSUserNotificationCenterDelegate
/**
When a notification is sent, the delegate of the notification center
is asked whether the notification should be presented or not. Since
the user can now disable notifications per application since macOS
Catalina, any and all notifications should be displayed.
*/
func userNotificationCenter(
_ center: NSUserNotificationCenter,
shouldPresent notification: NSUserNotification
) -> Bool {
return true
}
}

View File

@@ -73,6 +73,15 @@ class App {
}
}
/**
Retrieve the version number from the main info dictionary, Info.plist.
*/
static var version: String {
let version = Bundle.main.infoDictionary?["CFBundleShortVersionString"] as! String
let build = Bundle.main.infoDictionary?["CFBundleVersion"] as! String
return "\(version) (\(build))"
}
/**
The version that the `php` formula via Brew is aliased to on the current system.

View File

@@ -578,13 +578,13 @@ Gw
<autoresizingMask key="autoresizingMask"/>
<subviews>
<scrollView autohidesScrollers="YES" horizontalLineScroll="69" horizontalPageScroll="10" verticalLineScroll="69" verticalPageScroll="10" usesPredominantAxisScrolling="NO" translatesAutoresizingMaskIntoConstraints="NO" id="p0j-eB-I2i">
<rect key="frame" x="0.0" y="0.0" width="550" height="345"/>
<rect key="frame" x="0.0" y="0.0" width="550" height="344"/>
<clipView key="contentView" id="6IL-DW-37w">
<rect key="frame" x="1" y="1" width="548" height="343"/>
<rect key="frame" x="1" y="1" width="548" height="342"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<tableView verticalHuggingPriority="750" allowsExpansionToolTips="YES" columnAutoresizingStyle="lastColumnOnly" multipleSelection="NO" autosaveColumns="NO" rowHeight="69" rowSizeStyle="automatic" viewBased="YES" id="cp3-34-pQj">
<rect key="frame" x="0.0" y="0.0" width="548" height="343"/>
<rect key="frame" x="0.0" y="0.0" width="548" height="342"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<size key="intercellSpacing" width="17" height="0.0"/>
<color key="backgroundColor" name="controlBackgroundColor" catalog="System" colorSpace="catalog"/>

View File

@@ -6,14 +6,42 @@
//
import Foundation
import UserNotifications
class LocalNotification {
public static func askForPermission() {
UNUserNotificationCenter.current().requestAuthorization(options: [.alert], completionHandler: { granted, error in
if granted {
print("PHP Monitor has permission to show notifications.")
} else {
print("PHP Monitor does not have permission to show notifications.")
}
if let error = error {
print("PHP Monitor encounted an error determining notification permissions:")
print(error)
}
})
}
public static func send(title: String, subtitle: String) {
let notification = NSUserNotification()
notification.title = title
notification.subtitle = subtitle
NSUserNotificationCenter.default.deliver(notification)
let content = UNMutableNotificationContent()
content.title = title
content.body = subtitle
let uuidString = UUID().uuidString
let request = UNNotificationRequest(
identifier: uuidString,
content: content,
trigger: nil
)
let notificationCenter = UNUserNotificationCenter.current()
notificationCenter.add(request) { (error) in
if error != nil {
print(error!)
}
}
}
}

View File

@@ -62,6 +62,7 @@ class MainMenu: NSObject, NSWindowDelegate, NSMenuDelegate {
// Attempt to find out more info about Valet
let valet = Valet()
print("PHP Monitor has extracted the version number of Valet: \(valet.version)")
print("PHP Monitor is ready to serve!")
// Schedule a request to fetch the PHP version every 60 seconds
DispatchQueue.main.async { [self] in