fix: restart development launcher after rebuilding

This commit is contained in:
2026-10-11 19:33:15 +02:00
parent d02fdadd94
commit 62e813f58f
3 changed files with 36 additions and 2 deletions
+34
View File
@@ -0,0 +1,34 @@
import AppKit
func fail(_ message: String) -> Never {
FileHandle.standardError.write(Data("\(message)\n".utf8))
exit(1)
}
guard CommandLine.arguments.count == 2 else {
fail("Usage: swift Scripts/run.swift <Conjure.app>")
}
let target = URL(fileURLWithPath: CommandLine.arguments[1]).standardizedFileURL.resolvingSymlinksInPath()
let running = NSRunningApplication.runningApplications(withBundleIdentifier: "dev.conjure.launcher")
.filter { $0.bundleURL?.resolvingSymlinksInPath().path == target.path }
for app in running {
guard app.terminate() else { fail("Could not quit the existing Conjure instance.") }
}
for _ in 0..<100 {
if running.allSatisfy(\.isTerminated) { break }
// AppKit refreshes running-application state on the main run loop.
RunLoop.main.run(until: Date(timeIntervalSinceNow: 0.05))
}
guard running.allSatisfy(\.isTerminated) else {
fail("Conjure did not quit; the rebuilt app was not launched. Quit it and try again.")
}
let configuration = NSWorkspace.OpenConfiguration()
configuration.createsNewApplicationInstance = true
NSWorkspace.shared.openApplication(at: target, configuration: configuration) { app, error in
if let error { fail("Could not launch Conjure: \(error.localizedDescription)") }
guard let app else { fail("Launch Services did not return a running application.") }
print("Opened rebuilt Conjure (PID \(app.processIdentifier)).")
exit(0)
}
RunLoop.main.run()