diff --git a/internal/app/app.go b/internal/app/app.go index 3df3d0d..557ef17 100644 --- a/internal/app/app.go +++ b/internal/app/app.go @@ -155,7 +155,7 @@ func Run(ctx context.Context, params RunParams) error { logger.Debug("Command received", "cmd", cmd.Name()) switch c := cmd.(type) { - case terminal.CommandAddDestination: + case domain.CommandAddDestination: newCfg := cfg newCfg.Destinations = append(newCfg.Destinations, config.Destination{ Name: c.DestinationName, @@ -169,7 +169,7 @@ func Run(ctx context.Context, params RunParams) error { cfg = newCfg handleConfigUpdate(cfg, state, ui) ui.DestinationAdded() - case terminal.CommandRemoveDestination: + case domain.CommandRemoveDestination: repl.StopDestination(c.URL) // no-op if not live newCfg := cfg newCfg.Destinations = slices.DeleteFunc(newCfg.Destinations, func(dest config.Destination) bool { @@ -183,16 +183,16 @@ func Run(ctx context.Context, params RunParams) error { cfg = newCfg handleConfigUpdate(cfg, state, ui) ui.DestinationRemoved() - case terminal.CommandStartDestination: + case domain.CommandStartDestination: if !state.Source.Live { ui.ShowSourceNotLiveModal() continue } repl.StartDestination(c.URL) - case terminal.CommandStopDestination: + case domain.CommandStopDestination: repl.StopDestination(c.URL) - case terminal.CommandQuit: + case domain.CommandQuit: return nil } case <-uiUpdateT.C: diff --git a/internal/terminal/command.go b/internal/domain/commands.go similarity index 98% rename from internal/terminal/command.go rename to internal/domain/commands.go index 57aeecc..1793e8d 100644 --- a/internal/terminal/command.go +++ b/internal/domain/commands.go @@ -1,4 +1,4 @@ -package terminal +package domain // CommandAddDestination adds a destination. type CommandAddDestination struct { diff --git a/internal/terminal/terminal.go b/internal/terminal/terminal.go index 7693cfe..cc065a3 100644 --- a/internal/terminal/terminal.go +++ b/internal/terminal/terminal.go @@ -40,7 +40,7 @@ const ( // UI is responsible for managing the terminal user interface. type UI struct { - commandC chan Command + commandC chan domain.Command clipboardAvailable bool configFilePath string rtmpURL, rtmpsURL string @@ -106,7 +106,7 @@ const defaultChanSize = 64 // StartUI starts the terminal user interface. func StartUI(ctx context.Context, params StartParams) (*UI, error) { chanSize := cmp.Or(params.ChanSize, defaultChanSize) - commandCh := make(chan Command, chanSize) + commandCh := make(chan domain.Command, chanSize) app := tview.NewApplication() @@ -268,7 +268,7 @@ func (ui *UI) renderAboutView() { } // C returns a channel that receives commands from the user interface. -func (ui *UI) C() <-chan Command { +func (ui *UI) C() <-chan domain.Command { return ui.commandC } @@ -444,7 +444,7 @@ func (ui *UI) ShowFatalErrorModal(errString string) { []string{"Quit"}, false, func(int, string) { - ui.commandC <- CommandQuit{} + ui.commandC <- domain.CommandQuit{} }, ) }) @@ -697,7 +697,7 @@ func (ui *UI) handleMediaServerClosed(exitReason string) { SetBackgroundColor(tcell.ColorBlack). SetTextColor(tcell.ColorWhite). SetDoneFunc(func(int, string) { - ui.commandC <- CommandQuit{} + ui.commandC <- domain.CommandQuit{} }) modal.SetBorderStyle(tcell.StyleDefault.Background(tcell.ColorBlack).Foreground(tcell.ColorWhite)) @@ -887,7 +887,7 @@ func (ui *UI) addDestination() { AddInputField(inputLabelName, "My stream", inputLen, nil, nil). AddInputField(inputLabelURL, "rtmp://", inputLen, nil, nil). AddButton("Add", func() { - ui.commandC <- CommandAddDestination{ + ui.commandC <- domain.CommandAddDestination{ DestinationName: form.GetFormItemByLabel(inputLabelName).(*tview.InputField).GetText(), URL: form.GetFormItemByLabel(inputLabelURL).(*tview.InputField).GetText(), } @@ -945,7 +945,7 @@ func (ui *UI) removeDestination() { false, func(buttonIndex int, _ string) { if buttonIndex == 0 { - ui.commandC <- CommandRemoveDestination{URL: url} + ui.commandC <- domain.CommandRemoveDestination{URL: url} } }, ) @@ -1009,12 +1009,12 @@ func (ui *UI) toggleDestination() { switch ss { case startStateNotStarted: ui.urlsToStartState[url] = startStateStarting - ui.commandC <- CommandStartDestination{URL: url} + ui.commandC <- domain.CommandStartDestination{URL: url} case startStateStarting: // do nothing return case startStateStarted: - ui.commandC <- CommandStopDestination{URL: url} + ui.commandC <- domain.CommandStopDestination{URL: url} } } @@ -1067,7 +1067,7 @@ func (ui *UI) confirmQuit() { false, func(buttonIndex int, _ string) { if buttonIndex == 0 { - ui.commandC <- CommandQuit{} + ui.commandC <- domain.CommandQuit{} } }, )