diff --git a/PHP Monitor.xcodeproj/project.pbxproj b/PHP Monitor.xcodeproj/project.pbxproj index 7e01af3..6ddebac 100644 --- a/PHP Monitor.xcodeproj/project.pbxproj +++ b/PHP Monitor.xcodeproj/project.pbxproj @@ -99,6 +99,7 @@ C41CD0292628D8EE0065BBED /* GlobalKeybindPreference.swift in Sources */ = {isa = PBXBuildFile; fileRef = C41CD0282628D8EE0065BBED /* GlobalKeybindPreference.swift */; }; C41E871A2763D42300161EE0 /* DomainListVC+ContextMenu.swift in Sources */ = {isa = PBXBuildFile; fileRef = C41E87192763D42300161EE0 /* DomainListVC+ContextMenu.swift */; }; C41E871B2763D42300161EE0 /* DomainListVC+ContextMenu.swift in Sources */ = {isa = PBXBuildFile; fileRef = C41E87192763D42300161EE0 /* DomainListVC+ContextMenu.swift */; }; + C41F3D08298AED0D0042ACBF /* System.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4D3660A29113F20006BD146 /* System.swift */; }; C4205A7E27F4D21800191A39 /* ValetProxy.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4205A7D27F4D21800191A39 /* ValetProxy.swift */; }; C4205A7F27F4D21800191A39 /* ValetProxy.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4205A7D27F4D21800191A39 /* ValetProxy.swift */; }; C422DDAA28A2C49900CEAC97 /* WarningListView.swift in Sources */ = {isa = PBXBuildFile; fileRef = C422DDA928A2C49900CEAC97 /* WarningListView.swift */; }; @@ -2056,6 +2057,7 @@ buildActionMask = 2147483647; files = ( C406A602298AD50D00B5B85A /* AppDelegate.swift in Sources */, + C41F3D08298AED0D0042ACBF /* System.swift in Sources */, C406A5F3298AD2CE00B5B85A /* main.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; diff --git a/phpmon-updater/AppDelegate.swift b/phpmon-updater/AppDelegate.swift index 8aa4380..b1207cb 100644 --- a/phpmon-updater/AppDelegate.swift +++ b/phpmon-updater/AppDelegate.swift @@ -14,7 +14,7 @@ class AppDelegate: NSObject, NSApplicationDelegate { 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()) // Terminating all instances of PHP Monitor first @@ -25,7 +25,7 @@ class AppDelegate: NSObject, NSApplicationDelegate { // If the file does not exist, exit gracefully 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 that PHP Monitor cannot not updated!") 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.") @@ -40,6 +40,12 @@ class AppDelegate: NSObject, NSApplicationDelegate { exit(1) } } + + // We made it! + install(zipPath: path) + + // Restart PHP Monitor, this will also close the updater + restartPhpMon(dev: false) } func applicationWillTerminate(_ aNotification: Notification) { @@ -50,6 +56,16 @@ class AppDelegate: NSObject, NSApplicationDelegate { return true } + private func install(zipPath: String) { + _ = system("rm -rf ~/.config/phpmon/updater/output") + _ = system("mkdir -p ~/.config/phpmon/updater/output") + _ = system("unzip \(zipPath) -d ~/.config/phpmon/updater/output") + _ = system("rm -rf \"/Applications/PHP Monitor.app\"") + let command = "mv \"~/.config/phpmon/updater/output/PHP Monitor.app\" \"/Applications/PHP Monitor.app\"" + .replacingOccurrences(of: "~", with: NSHomeDirectory()) + _ = system(command) + } + private func terminatePhpMon() { let runningApplications = NSWorkspace.shared.runningApplications