Initial commit

This commit is contained in:
2024-05-26 22:20:37 +02:00
commit d37a11fa61
10 changed files with 382 additions and 0 deletions

View File

@ -0,0 +1,29 @@
//
// Created by Nico Verbruggen on 26/05/2024.
// Copyright © 2024 Nico Verbruggen. All rights reserved.
//
import Foundation
import Cocoa
class Alert {
public static var appName: String = ""
public static func show(description: String, shouldExit: Bool = true) async {
await withUnsafeContinuation { continuation in
DispatchQueue.main.async {
let alert = NSAlert()
alert.messageText = "\(Alert.appName) could not be updated."
alert.informativeText = description
alert.addButton(withTitle: "OK")
alert.alertStyle = .critical
alert.runModal()
if shouldExit {
exit(0)
}
continuation.resume()
}
}
}
}

View File

@ -0,0 +1,44 @@
//
// Created by Nico Verbruggen on 26/05/2024.
// Copyright © 2024 Nico Verbruggen. All rights reserved.
//
import Foundation
import Cocoa
class LaunchControl {
public static func smartRestart(priority: [String]) async {
for appPath in priority {
if FileManager.default.fileExists(atPath: appPath) {
let app = await LaunchControl.startApplication(at: appPath)
if app != nil {
return
}
}
}
}
public static func terminateApplications(bundleIds: [String]) async {
let runningApplications = NSWorkspace.shared.runningApplications
// Terminate all instances found
for id in bundleIds {
if let phpmon = runningApplications.first(where: {
(application) in return application.bundleIdentifier == id
}) {
phpmon.terminate()
}
}
}
public static func startApplication(at path: String) async -> NSRunningApplication? {
await withCheckedContinuation { continuation in
let url = NSURL(fileURLWithPath: path, isDirectory: true) as URL
let configuration = NSWorkspace.OpenConfiguration()
NSWorkspace.shared.openApplication(at: url, configuration: configuration) { phpmon, error in
continuation.resume(returning: phpmon)
}
}
}
}

View File

@ -0,0 +1,9 @@
//
// Created by Nico Verbruggen on 26/05/2024.
// Copyright © 2024 Nico Verbruggen. All rights reserved.
//
struct ReleaseManifest: Codable {
let url: String
let sha256: String
}

View File

@ -0,0 +1,40 @@
//
// Created by Nico Verbruggen on 26/05/2024.
// Copyright © 2024 Nico Verbruggen. All rights reserved.
//
import Foundation
/**
Run a simple blocking Shell command on the user's own system.
*/
func system(_ command: String) -> String {
let task = Process()
task.launchPath = "/bin/sh"
task.arguments = ["-c", command]
let pipe = Pipe()
task.standardOutput = pipe
task.launch()
let data = pipe.fileHandleForReading.readDataToEndOfFile()
let output: String = NSString(data: data, encoding: String.Encoding.utf8.rawValue)! as String
return output
}
/**
Same as the `system` command, but does not return the output.
*/
func system_quiet(_ command: String) {
let task = Process()
task.launchPath = "/bin/sh"
task.arguments = ["-c", command]
let pipe = Pipe()
task.standardOutput = pipe
task.launch()
_ = pipe.fileHandleForReading.readDataToEndOfFile()
return
}