From 8766e2f1c6b8ead2a77c6042437ea1f4adbaa383 Mon Sep 17 00:00:00 2001 From: kari-ts Date: Tue, 27 Feb 2024 16:03:36 -0800 Subject: [PATCH] cmd/tailscale/ui: hide exit node options if N/A If exit node is being run, don't show an option to use an exit node If exit node is being used, don't show an option to run/stop running as an exit node Updates tailscale/tailscale#10992 Signed-off-by: kari-ts --- cmd/tailscale/ui.go | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/cmd/tailscale/ui.go b/cmd/tailscale/ui.go index b14fa0c..49e72a1 100644 --- a/cmd/tailscale/ui.go +++ b/cmd/tailscale/ui.go @@ -361,6 +361,7 @@ func (ui *UI) layout(gtx layout.Context, sysIns system.Insets, state *clientStat expiry time.Time userID tailcfg.UserID exitID tailcfg.StableNodeID + advertisesExitNode bool ) if netmap != nil { userID = netmap.User() @@ -372,6 +373,7 @@ func (ui *UI) layout(gtx layout.Context, sysIns system.Insets, state *clientStat } if p := state.backend.Prefs; p != nil { exitID = p.ExitNodeID() + advertisesExitNode = p.AdvertisesExitNode() } if d := &ui.exitDialog; d.show { if newID := tailcfg.StableNodeID(d.exits.Value); newID != exitID { @@ -583,7 +585,7 @@ func (ui *UI) layout(gtx layout.Context, sysIns system.Insets, state *clientStat // 3-dots menu. if ui.menu.show { - ui.layoutMenu(gtx, sysIns, expiry, exitID != "" || len(state.backend.Exits) > 0, needsLogin) + ui.layoutMenu(gtx, sysIns, expiry, exitID != "" || len(state.backend.Exits) > 0 && !advertisesExitNode, exitID != "", needsLogin) } if ui.qr.show { @@ -1195,7 +1197,7 @@ func layoutDialog(gtx layout.Context, w layout.Widget) layout.Dimensions { } // layoutMenu lays out the menu activated by the 3 dots button. -func (ui *UI) layoutMenu(gtx layout.Context, sysIns system.Insets, expiry time.Time, showExits bool, needsLogin bool) { +func (ui *UI) layoutMenu(gtx layout.Context, sysIns system.Insets, expiry time.Time, showExits bool, isUsingExitNode bool, needsLogin bool) { ui.menu.dismiss.Add(gtx, color.NRGBA{}) if ui.menu.dismiss.Dismissed(gtx) { ui.setMenuShown(false) @@ -1233,13 +1235,15 @@ func (ui *UI) layoutMenu(gtx layout.Context, sysIns system.Insets, expiry time.T menuItem{title: "Log out", btn: &menu.logout}, ) - var title string - if ui.runningExit { - title = "Stop running exit node" - } else { - title = "Run exit node" + if !isUsingExitNode { + var title string + if ui.runningExit { + title = "Stop running exit node" + } else { + title = "Run exit node" + } + items = append(items, menuItem{title: title, btn: &menu.beExit}) } - items = append(items, menuItem{title: title, btn: &menu.beExit}) items = append(items, menuItem{title: "About", btn: &menu.about})