From 8dccb9fddc0cdcf7e5aa3045f97ed11db46189d3 Mon Sep 17 00:00:00 2001 From: administrator Date: Mon, 6 Apr 2026 09:49:39 +0700 Subject: [PATCH] Guard GUI click handlers against stale button slices --- internal/gui/app.go | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/internal/gui/app.go b/internal/gui/app.go index e6a2c9d..f8ad612 100644 --- a/internal/gui/app.go +++ b/internal/gui/app.go @@ -219,7 +219,7 @@ func (u *ui) handleClicks(gtx layout.Context) { u.addWireGuardFromFile() } - for i := range u.vlessConnectBtns { + for i := 0; i < minInt(len(u.configs.VLESS), len(u.vlessConnectBtns), len(u.vlessDeleteBtns), len(u.vlessPingBtns)); i++ { for u.vlessConnectBtns[i].Clicked(gtx) { if i < len(u.configs.VLESS) { name := u.configs.VLESS[i].Name @@ -251,7 +251,7 @@ func (u *ui) handleClicks(gtx layout.Context) { } } - for i := range u.wgConnectBtns { + for i := 0; i < minInt(len(u.configs.WireGuard), len(u.wgConnectBtns), len(u.wgDeleteBtns)); i++ { for u.wgConnectBtns[i].Clicked(gtx) { if i < len(u.configs.WireGuard) { name := u.configs.WireGuard[i].Name @@ -268,7 +268,7 @@ func (u *ui) handleClicks(gtx layout.Context) { } } - for i := range u.subUpdateBtns { + for i := 0; i < minInt(len(u.subs.Subscriptions), len(u.subUpdateBtns), len(u.subDeleteBtns), len(u.subTestBtns)); i++ { for u.subUpdateBtns[i].Clicked(gtx) { if i < len(u.subs.Subscriptions) { name := u.subs.Subscriptions[i].Name @@ -1041,3 +1041,15 @@ func trimForPreview(value string, limit int) string { func rgb(r, g, b uint8) color.NRGBA { return color.NRGBA{R: r, G: g, B: b, A: 255} } +func minInt(values ...int) int { + if len(values) == 0 { + return 0 + } + min := values[0] + for _, value := range values[1:] { + if value < min { + min = value + } + } + return min +}