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

@ -760,7 +760,7 @@
C4068CA327B0780A00544CD5 /* CheckboxPreferenceView.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = CheckboxPreferenceView.xib; sourceTree = "<group>"; };
C4068CA627B07A1300544CD5 /* SelectPreferenceView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SelectPreferenceView.swift; sourceTree = "<group>"; };
C4068CA927B0890D00544CD5 /* MenuBarIcons.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MenuBarIcons.swift; sourceTree = "<group>"; };
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 = "<group>"; };
C406A5F6298AD2CF00B5B85A /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
C406A5FB298AD2CF00B5B85A /* phpmon-updater.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = "phpmon-updater.entitlements"; sourceTree = "<group>"; };
@ -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 = "<group>";
@ -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 */,

View File

@ -15,8 +15,8 @@
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "C406A5EF298AD2CE00B5B85A"
BuildableName = "PHP Monitor Updater.app"
BlueprintName = "PHP Monitor Updater"
BuildableName = "PHP Monitor Self-Updater.app"
BlueprintName = "PHP Monitor Self-Updater"
ReferencedContainer = "container:PHP Monitor.xcodeproj">
</BuildableReference>
</BuildActionEntry>
@ -45,8 +45,8 @@
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "C406A5EF298AD2CE00B5B85A"
BuildableName = "PHP Monitor Updater.app"
BlueprintName = "PHP Monitor Updater"
BuildableName = "PHP Monitor Self-Updater.app"
BlueprintName = "PHP Monitor Self-Updater"
ReferencedContainer = "container:PHP Monitor.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
@ -62,8 +62,8 @@
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "C406A5EF298AD2CE00B5B85A"
BuildableName = "PHP Monitor Updater.app"
BlueprintName = "PHP Monitor Updater"
BuildableName = "PHP Monitor Self-Updater.app"
BlueprintName = "PHP Monitor Self-Updater"
ReferencedContainer = "container:PHP Monitor.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>

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()
}
}