auto restart server
This commit is contained in:
@@ -1,43 +1,16 @@
|
||||
import Foundation
|
||||
import Sparkle
|
||||
|
||||
private let lastVersionKey = "lastLaunchedVersion"
|
||||
|
||||
@MainActor
|
||||
final class Updater {
|
||||
static let shared = Updater()
|
||||
private lazy var controller = SPUStandardUpdaterController(startingUpdater: true, updaterDelegate: nil, userDriverDelegate: nil)
|
||||
|
||||
func start() {
|
||||
let version = Bundle.main.object(forInfoDictionaryKey: "CFBundleVersion") as? String
|
||||
let last = UserDefaults.standard.string(forKey: lastVersionKey)
|
||||
UserDefaults.standard.set(version, forKey: lastVersionKey)
|
||||
if last != nil && last != version {
|
||||
restartServer()
|
||||
}
|
||||
_ = controller
|
||||
}
|
||||
|
||||
func check() {
|
||||
controller.checkForUpdates(nil)
|
||||
}
|
||||
|
||||
private func restartServer() {
|
||||
guard let data = try? Data(contentsOf: agentPlist),
|
||||
let plist = try? PropertyListDecoder().decode(LaunchAgent.self, from: data),
|
||||
plist.programArguments.first == serverHelper
|
||||
else {
|
||||
return
|
||||
}
|
||||
let p = Process()
|
||||
p.executableURL = URL(filePath: "/bin/launchctl")
|
||||
p.arguments = ["kickstart", "-k", "gui/\(getuid())/run.fc.byre"]
|
||||
do {
|
||||
try p.run()
|
||||
p.waitUntilExit()
|
||||
log.info("restarted byre server: status \(p.terminationStatus)")
|
||||
} catch {
|
||||
log.error("restart byre server: \(errorText(error), privacy: .public)")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user