1
0
mirror of https://github.com/nicoverbruggen/phpmon.git synced 2025-08-06 19:40:08 +02:00

🏗 Allow self-updater to launch PHP Monitor

This commit is contained in:
2023-02-01 19:22:20 +01:00
parent 92509b5a84
commit 8fa270fd54
3 changed files with 59 additions and 20 deletions

View File

@ -10,8 +10,28 @@ import Cocoa
class AppDelegate: NSObject, NSApplicationDelegate {
func applicationDidFinishLaunching(_ aNotification: Notification) {
print("PHP MONITOR UPDATER by Nico Verbruggen")
print("Checking if contained within PHP Monitor.app...")
print("PHP MONITOR SELF-UPDATER by Nico Verbruggen")
let path = "~/config/phpmon/updater/phpmon.zip"
.replacingOccurrences(of: "~", with: NSHomeDirectory())
print("Checking path: \(path)")
if !FileManager.default.fileExists(atPath: path) {
print("The update has not been downloaded. Sadly, that means we will not update!")
showAlert(title: "The archive containing the zip appears to be missing.",
description: "PHP Monitor will not be updated, but we will restart the app for you.")
if FileManager.default.fileExists(atPath: "/Applications/PHP Monitor.app") {
restartPhpMon(dev: false)
}
else if FileManager.default.fileExists(atPath: "/Applications/PHP Monitor DEV.app") {
restartPhpMon(dev: true)
}
else {
exit(1)
}
}
}
func applicationWillTerminate(_ aNotification: Notification) {
@ -21,4 +41,23 @@ class AppDelegate: NSObject, NSApplicationDelegate {
func applicationSupportsSecureRestorableState(_ app: NSApplication) -> Bool {
return true
}
private func restartPhpMon(dev: Bool) {
let path = dev ? "/Applications/PHP Monitor DEV.app" : "/Applications/PHP Monitor.app"
let url = NSURL(fileURLWithPath: path, isDirectory: true) as URL
let configuration = NSWorkspace.OpenConfiguration()
NSWorkspace.shared.openApplication(at: url, configuration: configuration) { app, error in
print(app)
exit(0)
}
}
private func showAlert(title: String, description: String) {
let alert = NSAlert()
alert.messageText = title
alert.informativeText = description
alert.addButton(withTitle: "OK")
alert.alertStyle = .critical
alert.runModal()
}
}