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 +}