feat: headless mode
Some checks are pending
build / lint (push) Waiting to run
build / build (push) Blocked by required conditions
build / release (push) Blocked by required conditions

This commit is contained in:
Rob Watson 2025-04-30 22:46:27 +02:00
parent 750e9432be
commit 06a1501fbe
2 changed files with 28 additions and 19 deletions

View File

@ -27,6 +27,9 @@ type App struct {
dispatchC chan event.Command
dockerClient container.DockerClient
screen *terminal.Screen // Screen may be nil.
// TODO: startup check
// TODO: handle SIGINT
headless bool
clipboardAvailable bool
configFilePath string
buildInfo domain.BuildInfo
@ -39,6 +42,7 @@ type Params struct {
DockerClient container.DockerClient
ChanSize int
Screen *terminal.Screen // Screen may be nil.
Headless bool
ClipboardAvailable bool
ConfigFilePath string
BuildInfo domain.BuildInfo
@ -57,6 +61,7 @@ func New(params Params) *App {
dispatchC: make(chan event.Command, cmp.Or(params.ChanSize, defaultChanSize)),
dockerClient: params.DockerClient,
screen: params.Screen,
headless: params.Headless,
clipboardAvailable: params.ClipboardAvailable,
configFilePath: params.ConfigFilePath,
buildInfo: params.BuildInfo,
@ -75,6 +80,7 @@ func (a *App) Run(ctx context.Context) error {
return errors.New("config: either sources.mediaServer.rtmp.enabled or sources.mediaServer.rtmps.enabled must be set")
}
if !a.headless {
ui, err := terminal.StartUI(ctx, terminal.StartParams{
EventBus: a.eventBus,
Dispatcher: func(cmd event.Command) { a.dispatchC <- cmd },
@ -88,6 +94,7 @@ func (a *App) Run(ctx context.Context) error {
return fmt.Errorf("start terminal user interface: %w", err)
}
defer ui.Close()
}
// emptyUI is a dummy function that sets the UI state to an empty state, and
// re-renders the screen.

View File

@ -100,6 +100,7 @@ func run(ctx context.Context) error {
app := app.New(app.Params{
ConfigService: configService,
DockerClient: dockerClient,
Headless: os.Getenv("OCTO_HEADLESS") != "",
ClipboardAvailable: clipboardAvailable,
ConfigFilePath: configService.Path(),
BuildInfo: domain.BuildInfo{
@ -160,7 +161,8 @@ func printUsage() {
os.Stderr.WriteString(" help Print this help message\n")
os.Stderr.WriteString("\n")
os.Stderr.WriteString("Additionally, Octoplex can be configured with the following environment variables:\n\n")
os.Stderr.WriteString(" OCTO_DEBUG Enables debug logging if set\n")
os.Stderr.WriteString(" OCTO_DEBUG Enables debug logging if set\n\n")
os.Stderr.WriteString(" OCTO_HEADLESS Enables headless mode if set (experimental)\n")
}
// buildLogger builds the logger, which may be a no-op logger.