1
0
mirror of https://github.com/nicoverbruggen/phpmon.git synced 2025-08-07 03:50:08 +02:00

🏗 Let self-updater quit PHP Monitor first

This commit is contained in:
2023-02-01 19:31:04 +01:00
parent 8fa270fd54
commit 173206bed9

View File

@ -10,12 +10,20 @@ import Cocoa
class AppDelegate: NSObject, NSApplicationDelegate { class AppDelegate: NSObject, NSApplicationDelegate {
func applicationDidFinishLaunching(_ aNotification: Notification) { func applicationDidFinishLaunching(_ aNotification: Notification) {
print("PHP MONITOR SELF-UPDATER by Nico Verbruggen") print("PHP MONITOR SELF-UPDATER by Nico Verbruggen")
// Figure out where the updater would like to find the
let path = "~/config/phpmon/updater/phpmon.zip" let path = "~/config/phpmon/updater/phpmon.zip"
.replacingOccurrences(of: "~", with: NSHomeDirectory()) .replacingOccurrences(of: "~", with: NSHomeDirectory())
// Terminating all instances of PHP Monitor first
terminatePhpMon()
// Checking if the updated file exists
print("Checking path: \(path)") print("Checking path: \(path)")
// If the file does not exist, exit gracefully
if !FileManager.default.fileExists(atPath: path) { if !FileManager.default.fileExists(atPath: path) {
print("The update has not been downloaded. Sadly, that means we will not update!") print("The update has not been downloaded. Sadly, that means we will not update!")
@ -42,12 +50,28 @@ class AppDelegate: NSObject, NSApplicationDelegate {
return true return true
} }
private func terminatePhpMon() {
let runningApplications = NSWorkspace.shared.runningApplications
let ids = [
"com.nicoverbruggen.phpmon.dev",
"com.nicoverbruggen.phpmon"
]
for id in ids {
if let phpmon = runningApplications
.first(where: { (application) in return application.bundleIdentifier == id }) {
phpmon.terminate()
}
}
}
private func restartPhpMon(dev: Bool) { private func restartPhpMon(dev: Bool) {
let path = dev ? "/Applications/PHP Monitor DEV.app" : "/Applications/PHP Monitor.app" let path = dev ? "/Applications/PHP Monitor DEV.app" : "/Applications/PHP Monitor.app"
let url = NSURL(fileURLWithPath: path, isDirectory: true) as URL let url = NSURL(fileURLWithPath: path, isDirectory: true) as URL
let configuration = NSWorkspace.OpenConfiguration() let configuration = NSWorkspace.OpenConfiguration()
NSWorkspace.shared.openApplication(at: url, configuration: configuration) { app, error in NSWorkspace.shared.openApplication(at: url, configuration: configuration) { phpmon, error in
print(app) // Once we've opened PHP Monitor again... quit the updater
exit(0) exit(0)
} }
} }