From bb4e4552d83e3d273a9efd6fb9f9a5c655d1dd4b Mon Sep 17 00:00:00 2001 From: kevin Date: Wed, 8 Jul 2026 21:05:32 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E8=AE=B0=E4=BD=8F=E4=B8=8A=E6=AC=A1?= =?UTF-8?q?=E9=80=89=E4=B8=AD=E7=9A=84=E9=85=8D=E7=BD=AE=EF=BC=8C=E4=B8=8B?= =?UTF-8?q?=E6=AC=A1=E5=90=AF=E5=8A=A8=E8=87=AA=E5=8A=A8=E9=80=89=E4=B8=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 启用 AppConfig.DefaultProfileID 字段(此前声明但未使用) - 启动时 loadProfiles() 优先选中上次记录的配置,找不到则回退到第一个 - 切换配置时立即持久化到 config.yml,防止崩溃丢失 - 使用 Profile ID 而非名称,避免重命名后失效 --- Makefile | 2 +- internal/ui/app.go | 49 ++++++++++++++++++++++++++++++++++++++------- internal/ui/view.go | 1 + 3 files changed, 44 insertions(+), 8 deletions(-) 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.