From 0244fd108d71e83828652945af6b522068219574 Mon Sep 17 00:00:00 2001 From: Denton Gentry Date: Sat, 17 Dec 2022 20:36:00 -0800 Subject: [PATCH] cmd/tailscale: fix alternate ControlURL handling. (#72) With the Fast User Switching support in Tailscale 1.34, it is no longer necessary (nor sufficient) to exit and restart the app, as the settings are saved upon first connection. Therefore: - do not restart the app after changing the control URL, just go back to the authentication screen. - call `ipn/ipnlocal/local.go:Start()` to reinitialize the backend using the new auth URL. Fixes https://github.com/tailscale/tailscale/issues/6671 Signed-off-by: Denton Gentry Signed-off-by: Denton Gentry --- cmd/tailscale/main.go | 12 +++++++++--- cmd/tailscale/ui.go | 5 +++-- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/cmd/tailscale/main.go b/cmd/tailscale/main.go index 0686458..03c0a2c 100644 --- a/cmd/tailscale/main.go +++ b/cmd/tailscale/main.go @@ -441,9 +441,15 @@ func (a *App) runBackend() error { case SetLoginServerEvent: state.Prefs.ControlURL = e.URL b.backend.SetPrefs(state.Prefs) - // A hack to get around ipnlocal's inability to update - // ControlURL after Start()... Can we re-init instead? - os.Exit(0) + // Need to restart to force the login URL to be regenerated + // with the new control URL. Start from a goroutine to avoid + // deadlock. + go func() { + err := b.backend.Start(ipn.Options{}) + if err != nil { + fatalErr(err) + } + }() case LogoutEvent: go b.backend.Logout() case ConnectEvent: diff --git a/cmd/tailscale/ui.go b/cmd/tailscale/ui.go index 118ec79..15a73d1 100644 --- a/cmd/tailscale/ui.go +++ b/cmd/tailscale/ui.go @@ -396,8 +396,9 @@ func (ui *UI) layout(gtx layout.Context, sysIns system.Insets, state *clientStat if ui.loginServerSave.Clicked() { text := ui.loginServer.Text() - ui.showMessage(gtx, "Login server saved, relaunch the app") + ui.showMessage(gtx, "Login server saved") events = append(events, SetLoginServerEvent{URL: text}) + ui.setLoginServer = false } if ui.loginServerCancel.Clicked() { ui.setLoginServer = false @@ -725,7 +726,7 @@ func (ui *UI) layoutSignIn(gtx layout.Context, state *BackendState) layout.Dimen layout.Rigid(func(gtx C) D { return layout.Inset{Bottom: unit.Dp(16)}.Layout(gtx, func(gtx C) D { return border.Layout(gtx, func(gtx C) D { - button := material.Button(ui.theme, &ui.loginServerSave, "Save and restart") + button := material.Button(ui.theme, &ui.loginServerSave, "Save") button.Background = color.NRGBA{} // transparent button.Color = rgb(textColor) return button.Layout(gtx)