1 Commits
Author SHA1 Message Date
kevin bb4e4552d8 feat: 记住上次选中的配置,下次启动自动选中
Release / build-macos (push) Canceled after 0s
Release / build-windows (push) Canceled after 0s
Release / release (push) Canceled after 0s
- 启用 AppConfig.DefaultProfileID 字段(此前声明但未使用)
- 启动时 loadProfiles() 优先选中上次记录的配置,找不到则回退到第一个
- 切换配置时立即持久化到 config.yml,防止崩溃丢失
- 使用 Profile ID 而非名称,避免重命名后失效
2026-07-08 21:05:32 +08:00
3 changed files with 44 additions and 8 deletions
+1 -1
View File
@@ -11,7 +11,7 @@ GO = go
CGO_ENABLED = 1 CGO_ENABLED = 1
WINDRES ?= x86_64-w64-mingw32-windres WINDRES ?= x86_64-w64-mingw32-windres
MINGW_CC ?= x86_64-w64-mingw32-gcc 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) GIT_HASH = $(shell git rev-parse --short HEAD 2>/dev/null || echo unknown)
VERSION = $(SEMVER)-$(GIT_HASH) VERSION = $(SEMVER)-$(GIT_HASH)
LDFLAGS = -s -w -X lmvpn/internal/version.Version=$(VERSION) LDFLAGS = -s -w -X lmvpn/internal/version.Version=$(VERSION)
+35
View File
@@ -52,6 +52,7 @@ type App struct {
ipcClient *ipc.Client ipcClient *ipc.Client
profiles []model.ServerProfile profiles []model.ServerProfile
currentProfile *model.ServerProfile currentProfile *model.ServerProfile
defaultProfileID int64
langSetting string langSetting string
} }
@@ -84,6 +85,7 @@ func Run() {
db: store, db: store,
kc: keychain.New(), kc: keychain.New(),
langSetting: cfg.Language, langSetting: cfg.Language,
defaultProfileID: cfg.DefaultProfileID,
listSelectedIndex: -1, listSelectedIndex: -1,
} }
@@ -144,8 +146,21 @@ func (a *App) loadProfiles() {
names := a.profileNames() names := a.profileNames()
a.profileSelect.Options = names a.profileSelect.Options = names
if len(names) > 0 { if len(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.profileSelect.SetSelectedIndex(0)
a.selectProfileByName(names[0]) a.selectProfileByName(names[0])
}
} else { } else {
a.currentProfile = nil a.currentProfile = nil
a.profileSelect.SetSelected("") 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. // onAddProfile shows a dialog to create a new profile.
func (a *App) onAddProfile() { func (a *App) onAddProfile() {
a.showProfileDialog(nil) a.showProfileDialog(nil)
+1
View File
@@ -54,6 +54,7 @@ func (a *App) buildMainWindow() fyne.CanvasObject {
// Profile selector. // Profile selector.
a.profileSelect = widget.NewSelect(a.profileNames(), func(sel string) { a.profileSelect = widget.NewSelect(a.profileNames(), func(sel string) {
a.selectProfileByName(sel) a.selectProfileByName(sel)
a.saveDefaultProfile()
}) })
// Status display. // Status display.