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

View File

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

View File

@ -282,6 +282,7 @@ func (ui *UI) run(ctx context.Context) {
appStateChangedC := ui.eventBus.Register(event.EventNameAppStateChanged) appStateChangedC := ui.eventBus.Register(event.EventNameAppStateChanged)
destinationAddedC := ui.eventBus.Register(event.EventNameDestinationAdded) destinationAddedC := ui.eventBus.Register(event.EventNameDestinationAdded)
addDestinationFailedC := ui.eventBus.Register(event.EventNameAddDestinationFailed) addDestinationFailedC := ui.eventBus.Register(event.EventNameAddDestinationFailed)
startDestinationFailedC := ui.eventBus.Register(event.EventNameStartDestinationFailed)
destinationRemovedC := ui.eventBus.Register(event.EventNameDestinationRemoved) destinationRemovedC := ui.eventBus.Register(event.EventNameDestinationRemoved)
removeDestinationFailedC := ui.eventBus.Register(event.EventNameRemoveDestinationFailed) removeDestinationFailedC := ui.eventBus.Register(event.EventNameRemoveDestinationFailed)
mediaServerStartedC := ui.eventBus.Register(event.EventNameMediaServerStarted) mediaServerStartedC := ui.eventBus.Register(event.EventNameMediaServerStarted)
@ -308,6 +309,10 @@ func (ui *UI) run(ctx context.Context) {
ui.app.QueueUpdateDraw(func() { ui.app.QueueUpdateDraw(func() {
ui.handleDestinationAdded(evt.(event.DestinationAddedEvent)) ui.handleDestinationAdded(evt.(event.DestinationAddedEvent))
}) })
case evt := <-startDestinationFailedC:
ui.app.QueueUpdateDraw(func() {
ui.handleStartDestinationFailed(evt.(event.StartDestinationFailedEvent))
})
case evt := <-addDestinationFailedC: case evt := <-addDestinationFailedC:
ui.app.QueueUpdateDraw(func() { ui.app.QueueUpdateDraw(func() {
ui.handleDestinationEventError(evt.(event.AddDestinationFailedEvent).Err) ui.handleDestinationEventError(evt.(event.AddDestinationFailedEvent).Err)
@ -413,16 +418,14 @@ func (ui *UI) fkeyHandler(key tcell.Key) {
} }
} }
func (ui *UI) ShowSourceNotLiveModal() { func (ui *UI) handleStartDestinationFailed(event.StartDestinationFailedEvent) {
ui.app.QueueUpdateDraw(func() { ui.showModal(
ui.showModal( pageNameModalStartDestinationFailed,
pageNameModalNotLive, "Waiting for stream.\n\nStart streaming to a source URL then try again.",
"Waiting for stream.\n\nStart streaming to a source URL then try again.", []string{"Ok"},
[]string{"Ok"}, false,
false, nil,
nil, )
)
})
} }
// ShowStartupCheckModal shows a modal dialog to the user, asking if they want // ShowStartupCheckModal shows a modal dialog to the user, asking if they want
@ -592,21 +595,21 @@ func (ui *UI) updateProgressModal(container domain.Container) {
// Modals should generally have a unique name, which allows them to be stacked // Modals should generally have a unique name, which allows them to be stacked
// on top of other modals. // on top of other modals.
const ( const (
pageNameMain = "main" pageNameMain = "main"
pageNameAddDestination = "add-destination" pageNameAddDestination = "add-destination"
pageNameViewURLs = "view-urls" pageNameViewURLs = "view-urls"
pageNameConfigUpdateFailed = "modal-config-update-failed" pageNameConfigUpdateFailed = "modal-config-update-failed"
pageNameNoDestinations = "no-destinations" pageNameNoDestinations = "no-destinations"
pageNameModalAbout = "modal-about" pageNameModalAbout = "modal-about"
pageNameModalClipboard = "modal-clipboard" pageNameModalClipboard = "modal-clipboard"
pageNameModalDestinationError = "modal-destination-error" pageNameModalDestinationError = "modal-destination-error"
pageNameModalFatalError = "modal-fatal-error" pageNameModalFatalError = "modal-fatal-error"
pageNameModalPullProgress = "modal-pull-progress" pageNameModalPullProgress = "modal-pull-progress"
pageNameModalQuit = "modal-quit" pageNameModalQuit = "modal-quit"
pageNameModalRemoveDestination = "modal-remove-destination" pageNameModalRemoveDestination = "modal-remove-destination"
pageNameModalSourceError = "modal-source-error" pageNameModalSourceError = "modal-source-error"
pageNameModalStartupCheck = "modal-startup-check" pageNameModalStartDestinationFailed = "modal-start-destination-failed"
pageNameModalNotLive = "modal-not-live" pageNameModalStartupCheck = "modal-startup-check"
) )
// modalVisible returns true if any modal, including the add destination form, // modalVisible returns true if any modal, including the add destination form,