Files
terebi/Checks/player-command.swift
T
hl-valdemar 230949bb95 feat: add a native CLI launcher for local and YouTube playback
Build .build/terebi beside the app. Parse a single local file or YouTube URL, --url, --, and help; reject invalid commands before GUI launch. Resolve the adjacent app through symlinks and launch through NSWorkspace, reusing its process/window and saved progress.

Launch the app without media before delivering URL events. Raw media argv suppress SwiftUI's initial singleton window. Own warm document and internet Apple events because SwiftUI's default external-event routing closes that window; retain initial Finder document delivery to create it.

Verified actual CLI 0/64/69 exit behavior, PATH/symlink discovery from another directory, cold local/YouTube playback, warm local/YouTube replacement in the same native window/process, resume, Finder-style cold launch, and make all check.
2026-10-11 00:45:24 +02:00

42 lines
2.3 KiB
Swift

import Foundation
@main
struct PlayerCommandChecks {
static func require(_ condition: Bool, _ message: String) {
if !condition { fatalError("FAIL: " + message) }
}
static func main() throws {
let directory = FileManager.default.temporaryDirectory.appendingPathComponent("terebi.cli-check.\(UUID().uuidString)")
try FileManager.default.createDirectory(at: directory, withIntermediateDirectories: true)
defer { try? FileManager.default.removeItem(at: directory) }
let movie = directory.appendingPathComponent("video with spaces.mp4")
let optionFile = directory.appendingPathComponent("--help")
let colonFile = directory.appendingPathComponent("part:1.mp4")
for file in [movie, optionFile, colonFile] { try Data().write(to: file) }
func opened(_ arguments: [String]) throws -> URL? {
guard case .launch(let url) = try PlayerCommand.parse(arguments, directory: directory) else {
fatalError("FAIL: expected a launch command")
}
return url
}
require(try opened([movie.lastPathComponent]) == movie, "relative paths resolve against invocation directory, preserving spaces")
require(try opened([movie.absoluteString]) == movie, "encoded local file URLs preserve filename identity")
require(try opened(["--", "--help"]) == optionFile, "option terminator allows filenames that look like commands")
require(try opened([colonFile.path]) == colonFile, "colons in filesystem paths are not URL schemes")
let canonical = URL(string: "https://www.youtube.com/watch?v=jNQXAC9IVRw")!
require(try opened(["https://youtu.be/jNQXAC9IVRw"]) == canonical, "YouTube positional URLs canonicalize for resume identity")
for arguments in [["--url"], ["--url", canonical.absoluteString, movie.path], ["--"],
[movie.path, movie.path], ["--unknown"], ["missing.mp4"], [directory.path],
["file://remote-host/video.mp4"], ["https://example.com/video.mp4"]] {
do {
_ = try PlayerCommand.parse(arguments, directory: directory)
fatalError("FAIL: accepted an invalid command")
} catch {}
}
print("Player command checks passed")
}
}