add new navigation menu to open Compose app configuration in Docker Desktop

Signed-off-by: Guillaume Lours <705411+glours@users.noreply.github.com>
This commit is contained in:
Guillaume Lours 2024-05-21 15:59:39 +02:00 committed by Nicolas De loof
parent 2cee028e99
commit 3635303372
4 changed files with 45 additions and 4 deletions

View File

@ -106,6 +106,7 @@ type LogKeyboard struct {
Watch KeyboardWatch Watch KeyboardWatch
IsDockerDesktopActive bool IsDockerDesktopActive bool
IsWatchConfigured bool IsWatchConfigured bool
IsDDComposeUIActive bool
logLevel KEYBOARD_LOG_LEVEL logLevel KEYBOARD_LOG_LEVEL
signalChannel chan<- os.Signal signalChannel chan<- os.Signal
} }
@ -113,7 +114,7 @@ type LogKeyboard struct {
var KeyboardManager *LogKeyboard var KeyboardManager *LogKeyboard
var eg multierror.Group var eg multierror.Group
func NewKeyboardManager(ctx context.Context, isDockerDesktopActive, isWatchConfigured bool, func NewKeyboardManager(ctx context.Context, isDockerDesktopActive, isWatchConfigured, isDockerDesktopConfigActive bool,
sc chan<- os.Signal, sc chan<- os.Signal,
watchFn func(ctx context.Context, watchFn func(ctx context.Context,
project *types.Project, project *types.Project,
@ -124,6 +125,7 @@ func NewKeyboardManager(ctx context.Context, isDockerDesktopActive, isWatchConfi
km := LogKeyboard{} km := LogKeyboard{}
km.IsDockerDesktopActive = isDockerDesktopActive km.IsDockerDesktopActive = isDockerDesktopActive
km.IsWatchConfigured = isWatchConfigured km.IsWatchConfigured = isWatchConfigured
km.IsDDComposeUIActive = isDockerDesktopConfigActive
km.logLevel = INFO km.logLevel = INFO
km.Watch.Watching = false km.Watch.Watching = false
@ -192,8 +194,16 @@ func (lk *LogKeyboard) navigationMenu() string {
if lk.IsDockerDesktopActive { if lk.IsDockerDesktopActive {
openDDInfo = shortcutKeyColor("v") + navColor(" View in Docker Desktop") openDDInfo = shortcutKeyColor("v") + navColor(" View in Docker Desktop")
} }
var watchInfo string
var openDDUI string
if openDDInfo != "" { if openDDInfo != "" {
openDDUI = navColor(" ")
}
if lk.IsDDComposeUIActive {
openDDUI = openDDUI + shortcutKeyColor("o") + navColor(" View Config")
}
var watchInfo string
if openDDInfo != "" || openDDUI != "" {
watchInfo = navColor(" ") watchInfo = navColor(" ")
} }
var isEnabled = " Enable" var isEnabled = " Enable"
@ -201,7 +211,7 @@ func (lk *LogKeyboard) navigationMenu() string {
isEnabled = " Disable" isEnabled = " Disable"
} }
watchInfo = watchInfo + shortcutKeyColor("w") + navColor(isEnabled+" Watch") watchInfo = watchInfo + shortcutKeyColor("w") + navColor(isEnabled+" Watch")
return openDDInfo + watchInfo return openDDInfo + openDDUI + watchInfo
} }
func (lk *LogKeyboard) clearNavigationMenu() { func (lk *LogKeyboard) clearNavigationMenu() {
@ -234,6 +244,23 @@ func (lk *LogKeyboard) openDockerDesktop(ctx context.Context, project *types.Pro
) )
} }
func (lk *LogKeyboard) openDDComposeUI(ctx context.Context, project *types.Project) {
if !lk.IsDDComposeUIActive {
return
}
eg.Go(tracing.EventWrapFuncForErrGroup(ctx, "menu/gui/composeview", tracing.SpanOptions{},
func(ctx context.Context) error {
link := fmt.Sprintf("docker-desktop://dashboard/docker-compose/%s", project.Name)
err := open.Run(link)
if err != nil {
err = fmt.Errorf("Could not open Docker Desktop Compose UI")
lk.keyboardError("View Config", err)
}
return err
}),
)
}
func (lk *LogKeyboard) keyboardError(prefix string, err error) { func (lk *LogKeyboard) keyboardError(prefix string, err error) {
lk.kError.addError(prefix, err) lk.kError.addError(prefix, err)
@ -284,6 +311,8 @@ func (lk *LogKeyboard) HandleKeyEvents(event keyboard.KeyEvent, ctx context.Cont
lk.openDockerDesktop(ctx, project) lk.openDockerDesktop(ctx, project)
case 'w': case 'w':
lk.StartWatch(ctx, project, options) lk.StartWatch(ctx, project, options)
case 'o':
lk.openDDComposeUI(ctx, project)
} }
switch key := event.Key; key { switch key := event.Key; key {
case keyboard.KeyCtrlC: case keyboard.KeyCtrlC:

View File

@ -71,6 +71,10 @@ func (s *State) NavBar() bool {
return s.determineFeatureState("ComposeNav") return s.determineFeatureState("ComposeNav")
} }
func (s *State) ComposeUI() bool {
return s.determineFeatureState("ComposeUIView")
}
func (s *State) determineFeatureState(name string) bool { func (s *State) determineFeatureState(name string) bool {
if s == nil || !s.active || s.desktopValues == nil { if s == nil || !s.active || s.desktopValues == nil {
return false return false

View File

@ -324,3 +324,10 @@ func (s *composeService) RuntimeVersion(ctx context.Context) (string, error) {
func (s *composeService) isDesktopIntegrationActive() bool { func (s *composeService) isDesktopIntegrationActive() bool {
return s.desktopCli != nil return s.desktopCli != nil
} }
func (s *composeService) isDesktopUIEnabled() bool {
if !s.isDesktopIntegrationActive() {
return false
}
return s.experiments.ComposeUI()
}

View File

@ -97,9 +97,10 @@ func (s *composeService) Up(ctx context.Context, project *types.Project, options
} else { } else {
isWatchConfigured := s.shouldWatch(project) isWatchConfigured := s.shouldWatch(project)
isDockerDesktopActive := s.isDesktopIntegrationActive() isDockerDesktopActive := s.isDesktopIntegrationActive()
isDDComposeUI := s.isDesktopUIEnabled()
tracing.KeyboardMetrics(ctx, options.Start.NavigationMenu, isDockerDesktopActive, isWatchConfigured) tracing.KeyboardMetrics(ctx, options.Start.NavigationMenu, isDockerDesktopActive, isWatchConfigured)
formatter.NewKeyboardManager(ctx, isDockerDesktopActive, isWatchConfigured, signalChan, s.Watch) formatter.NewKeyboardManager(ctx, isDockerDesktopActive, isWatchConfigured, isDDComposeUI, signalChan, s.Watch)
if options.Start.Watch { if options.Start.Watch {
formatter.KeyboardManager.StartWatch(ctx, project, options) formatter.KeyboardManager.StartWatch(ctx, project, options)
} }