From 1260022d517041b66852e883fdca6b070553bf55 Mon Sep 17 00:00:00 2001 From: Nico Verbruggen Date: Thu, 2 Feb 2023 12:20:12 +0100 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Working=20self-updater=20(needs=20r?= =?UTF-8?q?efactor)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- phpmon/Domain/App/AppUpdateChecker.swift | 66 +++++++++++++----------- 1 file changed, 37 insertions(+), 29 deletions(-) diff --git a/phpmon/Domain/App/AppUpdateChecker.swift b/phpmon/Domain/App/AppUpdateChecker.swift index 3ef34ad..fd85ca9 100644 --- a/phpmon/Domain/App/AppUpdateChecker.swift +++ b/phpmon/Domain/App/AppUpdateChecker.swift @@ -77,6 +77,10 @@ class AppUpdateChecker { _ onlineVersion: AppVersion, _ background: Bool ) { + // TODO: Restore original behaviour + notifyAboutNewerVersion(version: onlineVersion) + return + switch onlineVersion.version.versionCompare(currentVersion.version) { case .orderedAscending: Log.info("You are running a newer version of PHP Monitor " @@ -146,36 +150,8 @@ class AppUpdateChecker { .withPrimary( text: "updater.alerts.buttons.install".localized, action: { vc in - let updater = Bundle.main.resourceURL!.path + "/PHP Monitor Self-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) - .replacingOccurrences(of: "'", with: "") - .split(separator: " ").last ?? "" - let url = system("echo \"\(Self.latestCaskFileContents)\" | grep url") - .trimmingCharacters(in: .whitespacesAndNewlines) - .replacingOccurrences(of: "'", with: "") - .split(separator: " ").last ?? "" - - try! FileSystem.writeAtomicallyToFile("\(updaterDirectory)/update.json", content: """ - { - "url": "\(url)", - "sha256": "\(sha256)" - } - """) - + Self.installUpdate() 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( @@ -195,6 +171,38 @@ class AppUpdateChecker { } } + private static func installUpdate() { + let updater = Bundle.main.resourceURL!.path + "/PHP Monitor Self-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) + .replacingOccurrences(of: "'", with: "") + .split(separator: " ").last ?? "" + + let url = system("echo \"\(Self.latestCaskFileContents)\" | grep url") + .trimmingCharacters(in: .whitespacesAndNewlines) + .replacingOccurrences(of: "'", with: "") + .split(separator: " ").last ?? "" + + try! FileSystem.writeAtomicallyToFile( + "\(updaterDirectory)/update.json", + content: """ + { "url": "\(url)", "sha256": "\(sha256)" } + """ + ) + + 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!") + } + } + private static func notifyAboutConnectionIssue() { Task { @MainActor in BetterAlert().withInformation(