feat: load optional XDG TOML configuration with session overrides

This commit is contained in:
2026-10-11 14:41:11 +02:00
parent 0dce073287
commit 722a225da5
16 changed files with 461 additions and 89 deletions
+14 -2
View File
@@ -1,5 +1,6 @@
import AppKit
import Darwin
import TerebiConfiguration
@main
@MainActor
@@ -14,7 +15,16 @@ enum TerebiCLI {
switch command {
case .help:
print(PlayerCommand.usage)
case .launch(let url, let newInstance):
case .launch(let url, let newInstance, let noConfig):
let configURL = PlayerConfiguration.fileURL(environment: ProcessInfo.processInfo.environment,
homeDirectory: FileManager.default.homeDirectoryForCurrentUser)
if !noConfig {
do {
_ = try PlayerConfiguration.load(from: configURL)
} catch {
fail(error.localizedDescription, code: 78)
}
}
guard let executable = Bundle.main.executableURL else {
fail("Could not locate the CLI executable.", code: 69)
}
@@ -25,8 +35,10 @@ enum TerebiCLI {
}
let configuration = NSWorkspace.OpenConfiguration()
configuration.createsNewApplicationInstance = newInstance
// LaunchServices does not inherit the invoking shell's XDG environment.
configuration.arguments = noConfig ? ["--no-config"] : ["--config-file", configURL.absoluteString]
if newInstance, let url {
configuration.arguments = ["--open-media", url.absoluteString]
configuration.arguments += ["--open-media", url.absoluteString]
}
do {
// Launch an application, not a document, so SwiftUI creates its singleton window.