c6d2958744
Add make release and make install PREFIX=/Users/valdemar/.local. Keep optimized no-debug release artifacts separate; install adjacent CLI/app under lib/terebi and link bin/terebi. Preflight FFmpeg/pkg-config before compiling or installing, including cached builds. Record the player's exact linked FFmpeg ABI paths. AppKit-only CLI/bootstrap validate native loadability and transitive dependencies before entering the FFmpeg-linked terebi-player. CLI fails with status 69 and remediation; Finder bootstrap shows a native alert and execs the player without losing initial events or process identity. Verified staged installation with spaces, reinstall preservation, absent build dependencies, missing/corrupt/transitively broken dylibs, real modal error surface, installed CLI and Finder startup across exec, local/YouTube resume and window reuse, and full make check.
44 lines
1.6 KiB
Swift
44 lines
1.6 KiB
Swift
import AppKit
|
|
import Darwin
|
|
|
|
@main
|
|
@MainActor
|
|
enum TerebiCLI {
|
|
static func main() async {
|
|
let command: PlayerCommand
|
|
do {
|
|
command = try PlayerCommand.parse(Array(CommandLine.arguments.dropFirst()))
|
|
} catch {
|
|
fail(error.localizedDescription, code: 64)
|
|
}
|
|
switch command {
|
|
case .help:
|
|
print(PlayerCommand.usage)
|
|
case .launch(let url):
|
|
guard let executable = Bundle.main.executableURL else {
|
|
fail("Could not locate the CLI executable.", code: 69)
|
|
}
|
|
let app = executable.resolvingSymlinksInPath().deletingLastPathComponent()
|
|
.appendingPathComponent("terebi.app", isDirectory: true)
|
|
if let error = FFmpegRuntime.error(for: app) {
|
|
fail(error, code: 69)
|
|
}
|
|
let configuration = NSWorkspace.OpenConfiguration()
|
|
do {
|
|
// Launch without media first so SwiftUI creates its singleton window.
|
|
_ = try await NSWorkspace.shared.openApplication(at: app, configuration: configuration)
|
|
if let url {
|
|
_ = try await NSWorkspace.shared.open([url], withApplicationAt: app, configuration: configuration)
|
|
}
|
|
} catch {
|
|
fail("Could not launch the player: \(error.localizedDescription)", code: 69)
|
|
}
|
|
}
|
|
}
|
|
|
|
private static func fail(_ message: String, code: Int32) -> Never {
|
|
FileHandle.standardError.write(Data("terebi: \(message)\n".utf8))
|
|
exit(code)
|
|
}
|
|
}
|