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 {
|
||||
|
||||
@@ -1167,9 +1167,6 @@ final class AppDelegate: NSObject, NSApplicationDelegate {
|
||||
}
|
||||
}
|
||||
|
||||
#if !PLAYER_CHECK
|
||||
@main
|
||||
#endif
|
||||
@MainActor
|
||||
struct TerebiApp: App {
|
||||
@NSApplicationDelegateAdaptor(AppDelegate.self) private var delegate
|
||||
@@ -1228,3 +1225,11 @@ struct TerebiApp: App {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#if !PLAYER_CHECK
|
||||
@_cdecl("terebi_app_main")
|
||||
@MainActor
|
||||
public func terebiAppMain() {
|
||||
TerebiApp.main()
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -32,7 +32,7 @@ enum FFmpegRuntime {
|
||||
let detail = dlerror().map { String(cString: $0) } ?? "The dynamic loader could not load this library."
|
||||
return "The FFmpeg libraries required by this build are unavailable or broken.\n\nRequired library: \(path)\n\(detail)\n\nInstall FFmpeg with `brew install ffmpeg`. If FFmpeg was upgraded or its library versions changed, rebuild and reinstall terebi."
|
||||
}
|
||||
// Deliberately never dlclose: retain successful loads until exit or bootstrap exec.
|
||||
// Deliberately never dlclose: retain successful loads until exit.
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user