client/systray: allow specifying tailscaled socket

Pass a local.Client to systray.Run, so we can use the existing global
localClient in the cmd/tailscale CLI.  Add socket flag to cmd/systray.

Updates #1708

Change-Id: Ia101a4a3005adb9118051b3416f5a64a4a45987d
Signed-off-by: Will Norris <will@tailscale.com>
This commit is contained in:
Will Norris 2025-08-04 17:09:32 -07:00 committed by Will Norris
parent 5bb42e3018
commit 9f29c428f4
3 changed files with 17 additions and 5 deletions

View File

@ -48,7 +48,12 @@
) )
// Run starts the systray menu and blocks until the menu exits. // Run starts the systray menu and blocks until the menu exits.
func (menu *Menu) Run() { // If client is nil, a default local.Client is used.
func (menu *Menu) Run(client *local.Client) {
if client == nil {
client = &local.Client{}
}
menu.lc = client
menu.updateState() menu.updateState()
// exit cleanly on SIGINT and SIGTERM // exit cleanly on SIGINT and SIGTERM
@ -71,7 +76,7 @@ func (menu *Menu) Run() {
type Menu struct { type Menu struct {
mu sync.Mutex // protects the entire Menu mu sync.Mutex // protects the entire Menu
lc local.Client lc *local.Client
status *ipnstate.Status status *ipnstate.Status
curProfile ipn.LoginProfile curProfile ipn.LoginProfile
allProfiles []ipn.LoginProfile allProfiles []ipn.LoginProfile

View File

@ -7,9 +7,17 @@
package main package main
import ( import (
"flag"
"tailscale.com/client/local"
"tailscale.com/client/systray" "tailscale.com/client/systray"
"tailscale.com/paths"
) )
var socket = flag.String("socket", paths.DefaultTailscaledSocket(), "path to tailscaled socket")
func main() { func main() {
new(systray.Menu).Run() flag.Parse()
lc := &local.Client{Socket: *socket}
new(systray.Menu).Run(lc)
} }

View File

@ -17,8 +17,7 @@
ShortUsage: "tailscale systray", ShortUsage: "tailscale systray",
ShortHelp: "Run a systray application to manage Tailscale", ShortHelp: "Run a systray application to manage Tailscale",
Exec: func(_ context.Context, _ []string) error { Exec: func(_ context.Context, _ []string) error {
// TODO(will): pass localClient to menu to use the global --socket flag new(systray.Menu).Run(&localClient)
new(systray.Menu).Run()
return nil return nil
}, },
} }