refactor(app): add StartDestinationFailedEvent

This commit is contained in:
Rob Watson 2025-04-24 21:06:47 +02:00
parent f4021a2886
commit 3019387f38
3 changed files with 38 additions and 28 deletions

View File

@ -181,7 +181,7 @@ func (a *App) Run(ctx context.Context) error {
return nil
}
if !a.handleCommand(cmd, state, repl, ui) {
if !a.handleCommand(cmd, state, repl) {
return nil
}
case <-uiUpdateT.C:
@ -209,7 +209,6 @@ func (a *App) handleCommand(
cmd domain.Command,
state *domain.AppState,
repl *replicator.Actor,
ui *terminal.UI,
) bool {
a.logger.Debug("Command received", "cmd", cmd.Name())
switch c := cmd.(type) {
@ -243,7 +242,7 @@ func (a *App) handleCommand(
a.eventBus.Send(event.DestinationRemovedEvent{URL: c.URL})
case domain.CommandStartDestination:
if !state.Source.Live {
ui.ShowSourceNotLiveModal()
a.eventBus.Send(event.StartDestinationFailedEvent{})
break
}

View File

@ -8,6 +8,7 @@ const (
EventNameAppStateChanged Name = "app_state_changed"
EventNameDestinationAdded Name = "destination_added"
EventNameAddDestinationFailed Name = "add_destination_failed"
EventNameStartDestinationFailed Name = "start_destination_failed"
EventNameDestinationRemoved Name = "destination_removed"
EventNameRemoveDestinationFailed Name = "remove_destination_failed"
EventNameFatalErrorOccurred Name = "fatal_error_occurred"
@ -46,6 +47,13 @@ func (e AddDestinationFailedEvent) name() Name {
return EventNameAddDestinationFailed
}
// StartDestinationFailedEvent is emitted when a destination fails to start.
type StartDestinationFailedEvent struct{}
func (e StartDestinationFailedEvent) name() Name {
return EventNameStartDestinationFailed
}
// DestinationRemovedEvent is emitted when a destination is successfully
// removed.
type DestinationRemovedEvent struct {

View File

@ -282,6 +282,7 @@ func (ui *UI) run(ctx context.Context) {
appStateChangedC := ui.eventBus.Register(event.EventNameAppStateChanged)
destinationAddedC := ui.eventBus.Register(event.EventNameDestinationAdded)
addDestinationFailedC := ui.eventBus.Register(event.EventNameAddDestinationFailed)
startDestinationFailedC := ui.eventBus.Register(event.EventNameStartDestinationFailed)
destinationRemovedC := ui.eventBus.Register(event.EventNameDestinationRemoved)
removeDestinationFailedC := ui.eventBus.Register(event.EventNameRemoveDestinationFailed)
mediaServerStartedC := ui.eventBus.Register(event.EventNameMediaServerStarted)
@ -308,6 +309,10 @@ func (ui *UI) run(ctx context.Context) {
ui.app.QueueUpdateDraw(func() {
ui.handleDestinationAdded(evt.(event.DestinationAddedEvent))
})
case evt := <-startDestinationFailedC:
ui.app.QueueUpdateDraw(func() {
ui.handleStartDestinationFailed(evt.(event.StartDestinationFailedEvent))
})
case evt := <-addDestinationFailedC:
ui.app.QueueUpdateDraw(func() {
ui.handleDestinationEventError(evt.(event.AddDestinationFailedEvent).Err)
@ -413,16 +418,14 @@ func (ui *UI) fkeyHandler(key tcell.Key) {
}
}
func (ui *UI) ShowSourceNotLiveModal() {
ui.app.QueueUpdateDraw(func() {
func (ui *UI) handleStartDestinationFailed(event.StartDestinationFailedEvent) {
ui.showModal(
pageNameModalNotLive,
pageNameModalStartDestinationFailed,
"Waiting for stream.\n\nStart streaming to a source URL then try again.",
[]string{"Ok"},
false,
nil,
)
})
}
// ShowStartupCheckModal shows a modal dialog to the user, asking if they want
@ -605,8 +608,8 @@ const (
pageNameModalQuit = "modal-quit"
pageNameModalRemoveDestination = "modal-remove-destination"
pageNameModalSourceError = "modal-source-error"
pageNameModalStartDestinationFailed = "modal-start-destination-failed"
pageNameModalStartupCheck = "modal-startup-check"
pageNameModalNotLive = "modal-not-live"
)
// modalVisible returns true if any modal, including the add destination form,