fix(ui): allow multiple destination error modals
Some checks failed
ci-build / release (push) Has been cancelled
ci-build / lint (push) Has been cancelled
ci-build / build (push) Has been cancelled

This commit is contained in:
Rob Watson 2025-04-15 09:23:01 +02:00
parent 52b0616d5f
commit b05ae25809

View File

@ -13,6 +13,7 @@ import (
"time" "time"
"git.netflux.io/rob/octoplex/internal/domain" "git.netflux.io/rob/octoplex/internal/domain"
"git.netflux.io/rob/octoplex/internal/shortid"
"github.com/gdamore/tcell/v2" "github.com/gdamore/tcell/v2"
"github.com/rivo/tview" "github.com/rivo/tview"
"golang.design/x/clipboard" "golang.design/x/clipboard"
@ -333,6 +334,7 @@ func (ui *UI) ShowSourceNotLiveModal() {
pageNameModalStartupCheck, pageNameModalStartupCheck,
fmt.Sprintf("Waiting for stream.\nStart streaming to the source URL then try again:\n\n%s", ui.sourceViews.url.GetText(true)), fmt.Sprintf("Waiting for stream.\nStart streaming to the source URL then try again:\n\n%s", ui.sourceViews.url.GetText(true)),
[]string{"Ok"}, []string{"Ok"},
false,
nil, nil,
) )
}) })
@ -352,6 +354,7 @@ func (ui *UI) ShowStartupCheckModal() bool {
pageNameModalStartupCheck, pageNameModalStartupCheck,
"Another instance of Octoplex may already be running.\n\nPressing continue will close that instance. Continue?", "Another instance of Octoplex may already be running.\n\nPressing continue will close that instance. Continue?",
[]string{"Continue", "Exit"}, []string{"Continue", "Exit"},
false,
func(buttonIndex int, _ string) { func(buttonIndex int, _ string) {
if buttonIndex == 0 { if buttonIndex == 0 {
done <- true done <- true
@ -375,6 +378,7 @@ func (ui *UI) ShowDestinationErrorModal(name string, err error) {
err, err,
), ),
[]string{"Ok"}, []string{"Ok"},
true,
nil, nil,
) )
}) })
@ -391,6 +395,7 @@ func (ui *UI) ShowFatalErrorModal(err error) {
err, err,
), ),
[]string{"Quit"}, []string{"Quit"},
false,
func(int, string) { func(int, string) {
ui.commandC <- CommandQuit{} ui.commandC <- CommandQuit{}
}, },
@ -584,8 +589,16 @@ func (ui *UI) selectLastDestination() {
} }
} }
func (ui *UI) showModal(pageName string, text string, buttons []string, doneFunc func(int, string)) { func (ui *UI) showModal(
if ui.pages.HasPage(pageName) { pageName string,
text string,
buttons []string,
allowMultiple bool,
doneFunc func(int, string),
) {
if allowMultiple {
pageName = pageName + "-" + shortid.New().String()
} else if ui.pages.HasPage(pageName) {
return return
} }
@ -796,6 +809,7 @@ func (ui *UI) ConfigUpdateFailed(err error) {
pageNameConfigUpdateFailed, pageNameConfigUpdateFailed,
"Configuration update failed:\n\n"+err.Error(), "Configuration update failed:\n\n"+err.Error(),
[]string{"Ok"}, []string{"Ok"},
false,
func(int, string) { func(int, string) {
pageName, frontPage := ui.pages.GetFrontPage() pageName, frontPage := ui.pages.GetFrontPage()
if pageName != pageNameAddDestination { if pageName != pageNameAddDestination {
@ -881,6 +895,7 @@ func (ui *UI) removeDestination() {
pageNameModalRemoveDestination, pageNameModalRemoveDestination,
text, text,
[]string{"Remove", "Cancel"}, []string{"Remove", "Cancel"},
false,
func(buttonIndex int, _ string) { func(buttonIndex int, _ string) {
if buttonIndex == 0 { if buttonIndex == 0 {
ui.commandC <- CommandRemoveDestination{URL: url} ui.commandC <- CommandRemoveDestination{URL: url}
@ -971,6 +986,7 @@ func (ui *UI) copySourceURLToClipboard(clipboardAvailable bool) {
pageNameModalClipboard, pageNameModalClipboard,
text, text,
[]string{"Ok"}, []string{"Ok"},
false,
nil, nil,
) )
} }
@ -992,6 +1008,7 @@ func (ui *UI) copyConfigFilePathToClipboard(clipboardAvailable bool, configFileP
pageNameModalClipboard, pageNameModalClipboard,
text, text,
[]string{"Ok"}, []string{"Ok"},
false,
nil, nil,
) )
} }
@ -1001,6 +1018,7 @@ func (ui *UI) confirmQuit() {
pageNameModalQuit, pageNameModalQuit,
"Are you sure you want to quit?", "Are you sure you want to quit?",
[]string{"Quit", "Cancel"}, []string{"Quit", "Cancel"},
false,
func(buttonIndex int, _ string) { func(buttonIndex int, _ string) {
if buttonIndex == 0 { if buttonIndex == 0 {
ui.commandC <- CommandQuit{} ui.commandC <- CommandQuit{}
@ -1026,6 +1044,7 @@ func (ui *UI) showAbout() {
ui.buildInfo.GoVersion, ui.buildInfo.GoVersion,
), ),
[]string{"Ok"}, []string{"Ok"},
false,
nil, nil,
) )
} }