Skip to content

Commit

Permalink
Hide login screen advance settings behind few taps
Browse files Browse the repository at this point in the history
By default, only show the version number in the login screen's menu.
But if you open and close it a few times, then show the alternate
control plane server option. It's always shown if you've ever edited
the value.

And rename it to just "Change server" and remove "Advanced".

Updates #45
  • Loading branch information
bradfitz committed Aug 1, 2022
1 parent 7df2413 commit 39da32f
Showing 1 changed file with 54 additions and 10 deletions.
64 changes: 54 additions & 10 deletions cmd/tailscale/ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"fmt"
"image"
"image/color"
"log"
"net/netip"
"time"

Expand All @@ -30,6 +31,7 @@ import (
"tailscale.com/client/tailscale/apitype"
"tailscale.com/ipn"
"tailscale.com/tailcfg"
"tailscale.com/version"

_ "embed"

Expand Down Expand Up @@ -78,7 +80,7 @@ type UI struct {
list layout.List
}

runningExit bool // are we an exit node now?
runningExit bool // are we an exit node now?

qr struct {
show bool
Expand All @@ -92,9 +94,11 @@ type UI struct {
}

menu struct {
open widget.Clickable
dismiss Dismiss
show bool
open widget.Clickable
dismiss Dismiss
show bool
showHistory []showChange
showDebugMenu bool

useLoginServer widget.Clickable
copy widget.Clickable
Expand Down Expand Up @@ -247,6 +251,12 @@ func newUI(store *stateStore) (*UI, error) {
ui.loginServer.SingleLine = true
ui.exitDialog.list.Axis = layout.Vertical
ui.shareDialog.list.Axis = layout.Vertical

// If they've ever set the control plane, give them the debug menu right away.
if v, _ := ui.store.ReadString(customLoginServerPrefKey, ""); v != "" {
ui.menu.showDebugMenu = true
}

return ui, nil
}

Expand Down Expand Up @@ -278,6 +288,36 @@ func (ui *UI) activeDialog() *bool {
return nil
}

type showChange struct {
at time.Time
shown bool
}

func (ui *UI) setMenuShown(v bool) {
if v == ui.menu.show {
return
}
ui.menu.show = v

now := time.Now()
const recent = 5 * time.Second
filt := ui.menu.showHistory[:0]
for _, hi := range ui.menu.showHistory {
if now.Sub(hi.at) < recent {
filt = append(filt, hi)
}
}
ui.menu.showHistory = filt
ui.menu.showHistory = append(ui.menu.showHistory, showChange{
at: now,
shown: v,
})
if len(ui.menu.showHistory) >= 6 {
ui.menu.showDebugMenu = true
}
log.Printf("history = %v; show = %v", len(ui.menu.showHistory), ui.menu.showDebugMenu)
}

func (ui *UI) layout(gtx layout.Context, sysIns system.Insets, state *clientState) []UIEvent {
// "Get started".
if ui.intro.show {
Expand All @@ -302,7 +342,7 @@ func (ui *UI) layout(gtx layout.Context, sysIns system.Insets, state *clientStat
}
}
for ui.menu.open.Clicked() {
ui.menu.show = !ui.menu.show
ui.setMenuShown(!ui.menu.show)
}

netmap := state.backend.NetworkMap
Expand Down Expand Up @@ -844,7 +884,7 @@ func (ui *UI) layoutIntro(gtx layout.Context, sysIns system.Insets) {
func (ui *UI) menuClicked(btn *widget.Clickable) bool {
cl := btn.Clicked()
if cl {
ui.menu.show = false
ui.setMenuShown(false)
}
return cl
}
Expand Down Expand Up @@ -1091,7 +1131,7 @@ func layoutDialog(gtx layout.Context, w layout.Widget) layout.Dimensions {
func (ui *UI) layoutMenu(gtx layout.Context, sysIns system.Insets, expiry time.Time, showExits bool, needsLogin bool) {
ui.menu.dismiss.Add(gtx, color.NRGBA{})
if ui.menu.dismiss.Dismissed(gtx) {
ui.menu.show = false
ui.setMenuShown(false)
}
layout.Inset{
Top: unit.Add(gtx.Metric, sysIns.Top, unit.Dp(2)),
Expand All @@ -1103,11 +1143,15 @@ func (ui *UI) layoutMenu(gtx layout.Context, sysIns system.Insets, expiry time.T
return D{}
}
if needsLogin {
items := []menuItem{
{title: "Use login server", btn: &menu.useLoginServer},
var items []menuItem
title := "Tailscale " + version.Short
if ui.menu.showDebugMenu {
items = []menuItem{
{title: "Change server", btn: &menu.useLoginServer},
}
}
return layoutMenu(ui.theme, gtx, items, func(gtx C) D {
l := material.Caption(ui.theme, "Advanced settings")
l := material.Caption(ui.theme, title)
return l.Layout(gtx)
})
}
Expand Down

0 comments on commit 39da32f

Please sign in to comment.