diff --git a/ui/app/header.go b/ui/app/header.go index dc0df7f..15fb192 100644 --- a/ui/app/header.go +++ b/ui/app/header.go @@ -140,6 +140,11 @@ func (h *Header) Layout(gtx layout.Context, theme *chapartheme.Theme) layout.Dim } } else { h.envState.ClearActiveEnvironment() + if h.OnSelectedEnvChanged != nil { + if err := h.OnSelectedEnvChanged(nil); err != nil { + h.showError(err) + } + } } } diff --git a/ui/app/ui.go b/ui/app/ui.go index 37c1812..eb0a578 100644 --- a/ui/app/ui.go +++ b/ui/app/ui.go @@ -124,13 +124,24 @@ func New(w *app.Window) (*UI, error) { return fmt.Errorf("failed to read preferences, %w", err) } - preferences.Spec.SelectedEnvironment.ID = env.MetaData.ID - preferences.Spec.SelectedEnvironment.Name = env.MetaData.Name + if env != nil { + preferences.Spec.SelectedEnvironment.ID = env.MetaData.ID + preferences.Spec.SelectedEnvironment.Name = env.MetaData.Name + } else { + preferences.Spec.SelectedEnvironment.ID = "" + preferences.Spec.SelectedEnvironment.Name = "" + } + if err := repo.UpdatePreferences(preferences); err != nil { return fmt.Errorf("failed to update preferences, %w", err) } - u.environmentsState.SetActiveEnvironment(env) + if env != nil { + u.environmentsState.SetActiveEnvironment(env) + } else { + u.environmentsState.ClearActiveEnvironment() + } + return nil }