Skip to content

Commit

Permalink
add new navigation menu to open Compose app configuration in Docker D…
Browse files Browse the repository at this point in the history
…esktop

Signed-off-by: Guillaume Lours <705411+glours@users.noreply.github.com>
  • Loading branch information
glours authored and ndeloof committed May 22, 2024
1 parent 2cee028 commit 3635303
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 4 deletions.
35 changes: 32 additions & 3 deletions cmd/formatter/shortcut.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,14 +106,15 @@ type LogKeyboard struct {
Watch KeyboardWatch
IsDockerDesktopActive bool
IsWatchConfigured bool
IsDDComposeUIActive bool
logLevel KEYBOARD_LOG_LEVEL
signalChannel chan<- os.Signal
}

var KeyboardManager *LogKeyboard
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,
watchFn func(ctx context.Context,
project *types.Project,
Expand All @@ -124,6 +125,7 @@ func NewKeyboardManager(ctx context.Context, isDockerDesktopActive, isWatchConfi
km := LogKeyboard{}
km.IsDockerDesktopActive = isDockerDesktopActive
km.IsWatchConfigured = isWatchConfigured
km.IsDDComposeUIActive = isDockerDesktopConfigActive
km.logLevel = INFO

km.Watch.Watching = false
Expand Down Expand Up @@ -192,16 +194,24 @@ func (lk *LogKeyboard) navigationMenu() string {
if lk.IsDockerDesktopActive {
openDDInfo = shortcutKeyColor("v") + navColor(" View in Docker Desktop")
}
var watchInfo string

var openDDUI string
if openDDInfo != "" {
openDDUI = navColor(" ")
}
if lk.IsDDComposeUIActive {
openDDUI = openDDUI + shortcutKeyColor("o") + navColor(" View Config")
}
var watchInfo string
if openDDInfo != "" || openDDUI != "" {
watchInfo = navColor(" ")
}
var isEnabled = " Enable"
if lk.Watch.Watching {
isEnabled = " Disable"
}
watchInfo = watchInfo + shortcutKeyColor("w") + navColor(isEnabled+" Watch")
return openDDInfo + watchInfo
return openDDInfo + openDDUI + watchInfo
}

func (lk *LogKeyboard) clearNavigationMenu() {
Expand Down Expand Up @@ -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) {
lk.kError.addError(prefix, err)

Expand Down Expand Up @@ -284,6 +311,8 @@ func (lk *LogKeyboard) HandleKeyEvents(event keyboard.KeyEvent, ctx context.Cont
lk.openDockerDesktop(ctx, project)
case 'w':
lk.StartWatch(ctx, project, options)
case 'o':
lk.openDDComposeUI(ctx, project)
}
switch key := event.Key; key {
case keyboard.KeyCtrlC:
Expand Down
4 changes: 4 additions & 0 deletions internal/experimental/experimental.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ func (s *State) NavBar() bool {
return s.determineFeatureState("ComposeNav")
}

func (s *State) ComposeUI() bool {
return s.determineFeatureState("ComposeUIView")
}

func (s *State) determineFeatureState(name string) bool {
if s == nil || !s.active || s.desktopValues == nil {
return false
Expand Down
7 changes: 7 additions & 0 deletions pkg/compose/compose.go
Original file line number Diff line number Diff line change
Expand Up @@ -324,3 +324,10 @@ func (s *composeService) RuntimeVersion(ctx context.Context) (string, error) {
func (s *composeService) isDesktopIntegrationActive() bool {
return s.desktopCli != nil
}

func (s *composeService) isDesktopUIEnabled() bool {
if !s.isDesktopIntegrationActive() {
return false
}
return s.experiments.ComposeUI()
}
3 changes: 2 additions & 1 deletion pkg/compose/up.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,10 @@ func (s *composeService) Up(ctx context.Context, project *types.Project, options
} else {
isWatchConfigured := s.shouldWatch(project)
isDockerDesktopActive := s.isDesktopIntegrationActive()
isDDComposeUI := s.isDesktopUIEnabled()
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 {
formatter.KeyboardManager.StartWatch(ctx, project, options)
}
Expand Down

0 comments on commit 3635303

Please sign in to comment.