diff --git a/PHP Monitor.xcodeproj/project.pbxproj b/PHP Monitor.xcodeproj/project.pbxproj index ec1f2f5..7e01af3 100644 --- a/PHP Monitor.xcodeproj/project.pbxproj +++ b/PHP Monitor.xcodeproj/project.pbxproj @@ -760,7 +760,7 @@ C4068CA327B0780A00544CD5 /* CheckboxPreferenceView.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = CheckboxPreferenceView.xib; sourceTree = ""; }; C4068CA627B07A1300544CD5 /* SelectPreferenceView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SelectPreferenceView.swift; sourceTree = ""; }; C4068CA927B0890D00544CD5 /* MenuBarIcons.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MenuBarIcons.swift; sourceTree = ""; }; - C406A5F0298AD2CE00B5B85A /* PHP Monitor Updater.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "PHP Monitor Updater.app"; sourceTree = BUILT_PRODUCTS_DIR; }; + C406A5F0298AD2CE00B5B85A /* PHP Monitor Self-Updater.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "PHP Monitor Self-Updater.app"; sourceTree = BUILT_PRODUCTS_DIR; }; C406A5F2298AD2CE00B5B85A /* main.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = main.swift; sourceTree = ""; }; C406A5F6298AD2CF00B5B85A /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; C406A5FB298AD2CF00B5B85A /* phpmon-updater.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = "phpmon-updater.entitlements"; sourceTree = ""; }; @@ -1185,7 +1185,7 @@ C4F7807925D7F84B000DBC97 /* Unit Tests.xctest */, C471E7AD28F9B4940021E251 /* Feature Tests.xctest */, C471E7BC28F9B90F0021E251 /* UI Tests.xctest */, - C406A5F0298AD2CE00B5B85A /* PHP Monitor Updater.app */, + C406A5F0298AD2CE00B5B85A /* PHP Monitor Self-Updater.app */, ); name = Products; sourceTree = ""; @@ -1805,9 +1805,9 @@ /* End PBXGroup section */ /* Begin PBXNativeTarget section */ - C406A5EF298AD2CE00B5B85A /* PHP Monitor Updater */ = { + C406A5EF298AD2CE00B5B85A /* PHP Monitor Self-Updater */ = { isa = PBXNativeTarget; - buildConfigurationList = C406A5FC298AD2CF00B5B85A /* Build configuration list for PBXNativeTarget "PHP Monitor Updater" */; + buildConfigurationList = C406A5FC298AD2CF00B5B85A /* Build configuration list for PBXNativeTarget "PHP Monitor Self-Updater" */; buildPhases = ( C406A5EC298AD2CE00B5B85A /* Sources */, C406A5ED298AD2CE00B5B85A /* Frameworks */, @@ -1817,9 +1817,9 @@ ); dependencies = ( ); - name = "PHP Monitor Updater"; + name = "PHP Monitor Self-Updater"; productName = "PHP Monitor Updater"; - productReference = C406A5F0298AD2CE00B5B85A /* PHP Monitor Updater.app */; + productReference = C406A5F0298AD2CE00B5B85A /* PHP Monitor Self-Updater.app */; productType = "com.apple.product-type.application"; }; C41C1B3222B0097F00E7CF16 /* PHP Monitor */ = { @@ -1942,7 +1942,7 @@ projectRoot = ""; targets = ( C41C1B3222B0097F00E7CF16 /* PHP Monitor */, - C406A5EF298AD2CE00B5B85A /* PHP Monitor Updater */, + C406A5EF298AD2CE00B5B85A /* PHP Monitor Self-Updater */, C4F7807825D7F84B000DBC97 /* Unit Tests */, C471E7AC28F9B4940021E251 /* Feature Tests */, C471E7BB28F9B90F0021E251 /* UI Tests */, @@ -2794,7 +2794,7 @@ DEVELOPMENT_TEAM = 8M54J5J787; ENABLE_HARDENED_RUNTIME = YES; GENERATE_INFOPLIST_FILE = YES; - INFOPLIST_KEY_CFBundleDisplayName = "PHP Monitor Updater"; + INFOPLIST_KEY_CFBundleDisplayName = "PHP Monitor Self-Updater"; INFOPLIST_KEY_LSApplicationCategoryType = "public.app-category.developer-tools"; INFOPLIST_KEY_NSHumanReadableCopyright = "Copyright © 2023 Nico Verbruggen. All rights reserved."; INFOPLIST_KEY_NSPrincipalClass = NSApplication; @@ -2826,7 +2826,7 @@ DEVELOPMENT_TEAM = 8M54J5J787; ENABLE_HARDENED_RUNTIME = YES; GENERATE_INFOPLIST_FILE = YES; - INFOPLIST_KEY_CFBundleDisplayName = "PHP Monitor Updater"; + INFOPLIST_KEY_CFBundleDisplayName = "PHP Monitor Self-Updater"; INFOPLIST_KEY_LSApplicationCategoryType = "public.app-category.developer-tools"; INFOPLIST_KEY_NSHumanReadableCopyright = "Copyright © 2023 Nico Verbruggen. All rights reserved."; INFOPLIST_KEY_NSPrincipalClass = NSApplication; @@ -2858,7 +2858,7 @@ DEVELOPMENT_TEAM = 8M54J5J787; ENABLE_HARDENED_RUNTIME = YES; GENERATE_INFOPLIST_FILE = YES; - INFOPLIST_KEY_CFBundleDisplayName = "PHP Monitor Updater"; + INFOPLIST_KEY_CFBundleDisplayName = "PHP Monitor Self-Updater"; INFOPLIST_KEY_LSApplicationCategoryType = "public.app-category.developer-tools"; INFOPLIST_KEY_NSHumanReadableCopyright = "Copyright © 2023 Nico Verbruggen. All rights reserved."; INFOPLIST_KEY_NSPrincipalClass = NSApplication; @@ -2890,7 +2890,7 @@ DEVELOPMENT_TEAM = 8M54J5J787; ENABLE_HARDENED_RUNTIME = YES; GENERATE_INFOPLIST_FILE = YES; - INFOPLIST_KEY_CFBundleDisplayName = "PHP Monitor Updater"; + INFOPLIST_KEY_CFBundleDisplayName = "PHP Monitor Self-Updater"; INFOPLIST_KEY_LSApplicationCategoryType = "public.app-category.developer-tools"; INFOPLIST_KEY_NSHumanReadableCopyright = "Copyright © 2023 Nico Verbruggen. All rights reserved."; INFOPLIST_KEY_NSPrincipalClass = NSApplication; @@ -3486,7 +3486,7 @@ /* End XCBuildConfiguration section */ /* Begin XCConfigurationList section */ - C406A5FC298AD2CF00B5B85A /* Build configuration list for PBXNativeTarget "PHP Monitor Updater" */ = { + C406A5FC298AD2CF00B5B85A /* Build configuration list for PBXNativeTarget "PHP Monitor Self-Updater" */ = { isa = XCConfigurationList; buildConfigurations = ( C406A5FD298AD2CF00B5B85A /* Debug */, diff --git a/PHP Monitor.xcodeproj/xcshareddata/xcschemes/PHP Monitor Updater.xcscheme b/PHP Monitor.xcodeproj/xcshareddata/xcschemes/PHP Monitor Self-Updater.xcscheme similarity index 88% rename from PHP Monitor.xcodeproj/xcshareddata/xcschemes/PHP Monitor Updater.xcscheme rename to PHP Monitor.xcodeproj/xcshareddata/xcschemes/PHP Monitor Self-Updater.xcscheme index f28c4b8..67f26b9 100644 --- a/PHP Monitor.xcodeproj/xcshareddata/xcschemes/PHP Monitor Updater.xcscheme +++ b/PHP Monitor.xcodeproj/xcshareddata/xcschemes/PHP Monitor Self-Updater.xcscheme @@ -15,8 +15,8 @@ @@ -45,8 +45,8 @@ @@ -62,8 +62,8 @@ diff --git a/phpmon-updater/AppDelegate.swift b/phpmon-updater/AppDelegate.swift index f0548b0..5f07354 100644 --- a/phpmon-updater/AppDelegate.swift +++ b/phpmon-updater/AppDelegate.swift @@ -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() + } }