From ca72b799243ea5899c584ff4448e698c66d0d06d Mon Sep 17 00:00:00 2001 From: Nico Verbruggen Date: Thu, 2 Feb 2023 12:14:30 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=8F=97=20Initial=20working=20version=20of?= =?UTF-8?q?=20the=20updater?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This class is in dire need of a refactor, however. --- phpmon/Domain/App/AppDelegate.swift | 1 - phpmon/Domain/App/AppUpdateChecker.swift | 26 +++++++++++++++++------- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/phpmon/Domain/App/AppDelegate.swift b/phpmon/Domain/App/AppDelegate.swift index fc72c1f..eea5904 100644 --- a/phpmon/Domain/App/AppDelegate.swift +++ b/phpmon/Domain/App/AppDelegate.swift @@ -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: "")) } diff --git a/phpmon/Domain/App/AppUpdateChecker.swift b/phpmon/Domain/App/AppUpdateChecker.swift index 0ab6fd8..3ef34ad 100644 --- a/phpmon/Domain/App/AppUpdateChecker.swift +++ b/phpmon/Domain/App/AppUpdateChecker.swift @@ -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(