refactor: extract commands to domain package
Some checks are pending
ci-build / build (push) Blocked by required conditions
ci-build / release (push) Blocked by required conditions
ci-build / lint (push) Waiting to run
ci-scan / Analyze (go) (push) Waiting to run
ci-scan / Analyze (actions) (push) Waiting to run

This commit is contained in:
Rob Watson 2025-04-20 20:55:10 +02:00
parent 7afa84505e
commit add511e3dd
3 changed files with 16 additions and 16 deletions

View File

@ -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:

View File

@ -1,4 +1,4 @@
package terminal
package domain
// CommandAddDestination adds a destination.
type CommandAddDestination struct {

View File

@ -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{}
}
},
)