on main help sign in
fix(models): fix sorting of hyper
841eec8Kieran Klukas
internal/config/provider.go+10−2
@@ -147,6 +147,9 @@ func Providers(cfg *Config) ([]catwalk.Provider, error) {
147 ctx, cancel := context.WithTimeout(context.Background(), 45*time.Second)
147 ctx, cancel := context.WithTimeout(context.Background(), 45*time.Second)
148 defer cancel()
148 defer cancel()
149
149
150+ var hyperProvider catwalk.Provider
151+ var hyperFound bool
152+
150 wg.Go(func() {
153 wg.Go(func() {
151 if customProvidersOnly {
154 if customProvidersOnly {
152 return
155 return
@@ -177,12 +180,17 @@ func Providers(cfg *Config) ([]catwalk.Provider, error) {
177 errs = append(errs, fmt.Errorf("Crush was unable to fetch updated information from Hyper: %w", err)) //nolint:staticcheck
180 errs = append(errs, fmt.Errorf("Crush was unable to fetch updated information from Hyper: %w", err)) //nolint:staticcheck
178 return
181 return
179 }
182 }
180− providers.Append(item)
183+ hyperProvider = item
184+ hyperFound = true
181 })
185 })
182
186
183 wg.Wait()
187 wg.Wait()
184
188
189+ if hyperFound {
185− providerList = slices.Collect(providers.Seq())
190+ providerList = append([]catwalk.Provider{hyperProvider}, slices.Collect(providers.Seq())...)
191+ } else {
192+ providerList = slices.Collect(providers.Seq())
193+ }
186 providerErr = errors.Join(errs...)
194 providerErr = errors.Join(errs...)
187 })
195 })
188 return providerList, providerErr
196 return providerList, providerErr
internal/ui/dialog/models.go+2−14
@@ -408,20 +408,8 @@ func (m *Models) setProviderItems() error {
408 }
408 }
409 }
409 }
410
410
411− // Move "Charm Hyper" to first position.
412− // (But still after recent models and custom providers).
413− slices.SortStableFunc(m.providers, func(a, b catwalk.Provider) int {
414− switch {
415− case a.ID == "hyper":
416− return -1
417− case b.ID == "hyper":
418− return 1
419− default:
420− return 0
421− }
422− })
423−
424− // Now add known providers from the predefined list
411+ // Now add known providers from the predefined list.
412+ // Providers already has Hyper at the front of the list.
425 for _, provider := range m.providers {
413 for _, provider := range m.providers {
426 providerID := string(provider.ID)
414 providerID := string(provider.ID)
427 if addedProviders[providerID] {
415 if addedProviders[providerID] {