mirror of
https://github.com/nicoverbruggen/phpmon.git
synced 2025-08-12 05:50:07 +02:00
✨ Working self-updater (needs refactor)
This commit is contained in:
@@ -77,6 +77,10 @@ class AppUpdateChecker {
|
|||||||
_ onlineVersion: AppVersion,
|
_ onlineVersion: AppVersion,
|
||||||
_ background: Bool
|
_ background: Bool
|
||||||
) {
|
) {
|
||||||
|
// TODO: Restore original behaviour
|
||||||
|
notifyAboutNewerVersion(version: onlineVersion)
|
||||||
|
return
|
||||||
|
|
||||||
switch onlineVersion.version.versionCompare(currentVersion.version) {
|
switch onlineVersion.version.versionCompare(currentVersion.version) {
|
||||||
case .orderedAscending:
|
case .orderedAscending:
|
||||||
Log.info("You are running a newer version of PHP Monitor "
|
Log.info("You are running a newer version of PHP Monitor "
|
||||||
@@ -146,36 +150,8 @@ class AppUpdateChecker {
|
|||||||
.withPrimary(
|
.withPrimary(
|
||||||
text: "updater.alerts.buttons.install".localized,
|
text: "updater.alerts.buttons.install".localized,
|
||||||
action: { vc in
|
action: { vc in
|
||||||
let updater = Bundle.main.resourceURL!.path + "/PHP Monitor Self-Updater.app"
|
Self.installUpdate()
|
||||||
|
|
||||||
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)"
|
|
||||||
}
|
|
||||||
""")
|
|
||||||
|
|
||||||
vc.close(with: .OK)
|
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(
|
.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() {
|
private static func notifyAboutConnectionIssue() {
|
||||||
Task { @MainActor in
|
Task { @MainActor in
|
||||||
BetterAlert().withInformation(
|
BetterAlert().withInformation(
|
||||||
|
Reference in New Issue
Block a user