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
+1 -1
View File
@@ -10,7 +10,7 @@ build:
codesign --force --sign - $(APP)
run: build
open $(APP)
swift Scripts/run.swift "$(APP)"
test:
swift test
+1 -1
View File
@@ -10,7 +10,7 @@ Requires macOS 14 or later and a Swift 6 toolchain (Xcode 16 or later).
make run
```
This builds a release executable, assembles an ad-hoc-signed application at `.build/Conjure.app`, and opens it through Launch Services. You can also open that app directly in Finder. The local signature is for development, not notarized distribution.
This builds a release executable, assembles an ad-hoc-signed application at `.build/Conjure.app`, gracefully quits any running instance of that exact development bundle, and launches a fresh process through Launch Services. This ensures rebuilt code is loaded; simply opening an already-running app in Finder does not reload its executable. Other copies of Conjure are left running. The local signature is for development, not notarized distribution.
```sh
make build # Build the application without opening it.
+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()