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

🏗 Initial working version of the updater

This class is in dire need of a refactor, however.
This commit is contained in:
2023-02-02 12:14:30 +01:00
parent 1a17a275d4
commit ca72b79924
2 changed files with 19 additions and 8 deletions

View File

@ -63,7 +63,6 @@ class AppDelegate: NSObject, NSApplicationDelegate, UNUserNotificationCenterDele
override init() {
#if DEBUG
logger.verbosity = .performance
if let profile = CommandLine.arguments.first(where: { $0.matches(pattern: "--configuration:*") }) {
Self.initializeTestingProfile(profile.replacingOccurrences(of: "--configuration:", with: ""))
}

View File

@ -146,12 +146,12 @@ class AppUpdateChecker {
.withPrimary(
text: "updater.alerts.buttons.install".localized,
action: { vc in
print(Self.latestCaskFileContents)
let updater = Bundle.main.resourceURL!.path + "/PHP Monitor Self-Updater.app"
// TODO: Find the bundle asset named 'PHP Monitor Self-Updater.app'
// TODO: Move the self-updater to ~/.config/phpmon
// TODO: Write the manifest file to disk (~/.config/phpmon/updater/update.json)
// TODO: Launch the updater app
let updaterDirectory = "~/.config/phpmon/updater"
.replacingOccurrences(of: "~", with: NSHomeDirectory())
system_quiet("cp -R \"\(updater)\" \"\(updaterDirectory)/PHP Monitor Self-Updater.app\"")
let sha256 = system("echo \"\(Self.latestCaskFileContents)\" | grep sha256")
.trimmingCharacters(in: .whitespacesAndNewlines)
@ -162,8 +162,20 @@ class AppUpdateChecker {
.replacingOccurrences(of: "'", with: "")
.split(separator: " ").last ?? ""
print(sha256)
print(url)
try! FileSystem.writeAtomicallyToFile("\(updaterDirectory)/update.json", content: """
{
"url": "\(url)",
"sha256": "\(sha256)"
}
""")
vc.close(with: .OK)
let updaterUrl = NSURL(fileURLWithPath: updater, isDirectory: true) as URL
let configuration = NSWorkspace.OpenConfiguration()
NSWorkspace.shared.openApplication(at: updaterUrl, configuration: configuration) { _, _ in
print("The updater has been launched successfully")
}
}
)
.withSecondary(