fix: preserve app identity through FFmpeg preflight
This commit is contained in:
@@ -9,13 +9,17 @@ enum TerebiBootstrap {
|
||||
if let error = FFmpegRuntime.error(for: app) {
|
||||
fail(error)
|
||||
}
|
||||
let payload = app.appendingPathComponent("Contents/MacOS/terebi-player")
|
||||
let errorCode = payload.path.withCString { path in
|
||||
_ = execv(path, CommandLine.unsafeArgv)
|
||||
return errno
|
||||
let payload = app.appendingPathComponent("Contents/Frameworks/libterebi-player.dylib")
|
||||
guard let library = dlopen(payload.path, RTLD_NOW | RTLD_LOCAL) else {
|
||||
let detail = dlerror().map { String(cString: $0) } ?? "The dynamic loader could not load the player."
|
||||
fail("Could not load the player: \(detail)\n\nPlayer library: \(payload.path)\nRebuild and reinstall terebi.")
|
||||
}
|
||||
let detail = String(cString: strerror(errorCode))
|
||||
fail("Could not start the player: \(detail)\n\nPlayer executable: \(payload.path)\nRebuild and reinstall terebi.")
|
||||
guard let entry = dlsym(library, "terebi_app_main") else {
|
||||
fail("The player library is missing its application entry point. Rebuild and reinstall terebi.")
|
||||
}
|
||||
// Keep the declared app executable alive so LaunchServices retains its identity.
|
||||
typealias PlayerMain = @convention(c) () -> Void
|
||||
unsafeBitCast(entry, to: PlayerMain.self)()
|
||||
}
|
||||
|
||||
private static func fail(_ message: String) -> Never {
|
||||
|
||||
Reference in New Issue
Block a user