diff --git a/Makefile b/Makefile index 5f59cd5..bcfa0bb 100644 --- a/Makefile +++ b/Makefile @@ -11,7 +11,7 @@ GO = go CGO_ENABLED = 1 WINDRES ?= x86_64-w64-mingw32-windres MINGW_CC ?= x86_64-w64-mingw32-gcc -SEMVER ?= 0.4.2 +SEMVER ?= 0.4.3 GIT_HASH = $(shell git rev-parse --short HEAD 2>/dev/null || echo unknown) VERSION = $(SEMVER)-$(GIT_HASH) LDFLAGS = -s -w -X lmvpn/internal/version.Version=$(VERSION) diff --git a/internal/ui/app.go b/internal/ui/app.go index 1b7f0a2..ae34780 100644 --- a/internal/ui/app.go +++ b/internal/ui/app.go @@ -48,11 +48,12 @@ type App struct { disconnectBtn *widget.Button // State - mu sync.Mutex - ipcClient *ipc.Client - profiles []model.ServerProfile - currentProfile *model.ServerProfile - langSetting string + mu sync.Mutex + ipcClient *ipc.Client + profiles []model.ServerProfile + currentProfile *model.ServerProfile + defaultProfileID int64 + langSetting string } // Run initialises and starts the GUI application. @@ -84,6 +85,7 @@ func Run() { db: store, kc: keychain.New(), langSetting: cfg.Language, + defaultProfileID: cfg.DefaultProfileID, listSelectedIndex: -1, } @@ -144,8 +146,21 @@ func (a *App) loadProfiles() { names := a.profileNames() a.profileSelect.Options = names if len(names) > 0 { - a.profileSelect.SetSelectedIndex(0) - a.selectProfileByName(names[0]) + selected := false + if a.defaultProfileID > 0 { + for i := range a.profiles { + if a.profiles[i].ID == a.defaultProfileID { + a.profileSelect.SetSelectedIndex(i) + a.selectProfileByName(a.profiles[i].Name) + selected = true + break + } + } + } + if !selected { + a.profileSelect.SetSelectedIndex(0) + a.selectProfileByName(names[0]) + } } else { a.currentProfile = nil a.profileSelect.SetSelected("") @@ -182,6 +197,26 @@ func (a *App) selectProfileByName(name string) { } } +// saveDefaultProfile persists the currently selected profile ID to the +// config file so it can be restored on the next launch. +func (a *App) saveDefaultProfile() { + if a.currentProfile == nil { + return + } + a.defaultProfileID = a.currentProfile.ID + cfg, err := config.Load() + if err != nil { + cfg = config.Default() + } + if cfg.DefaultProfileID == a.currentProfile.ID { + return + } + cfg.DefaultProfileID = a.currentProfile.ID + if err := config.Save(cfg); err != nil { + log.L().Error("save default profile", "error", err) + } +} + // onAddProfile shows a dialog to create a new profile. func (a *App) onAddProfile() { a.showProfileDialog(nil) diff --git a/internal/ui/view.go b/internal/ui/view.go index b15f5ed..d7747ef 100644 --- a/internal/ui/view.go +++ b/internal/ui/view.go @@ -54,6 +54,7 @@ func (a *App) buildMainWindow() fyne.CanvasObject { // Profile selector. a.profileSelect = widget.NewSelect(a.profileNames(), func(sel string) { a.selectProfileByName(sel) + a.saveDefaultProfile() }) // Status display.