mirror of
https://github.com/tailscale/tailscale.git
synced 2025-12-26 04:20:33 +00:00
clientupdate, util/osshare, util/winutil, version: improve Windows GUI filename resolution and WinUI build awareness
On Windows arm64 we are going to need to ship two different GUI builds; one for Win10 (GOARCH=386) and one for Win11 (GOARCH=amd64, tags += winui). Due to quirks in MSI packaging, they cannot both share the same filename. This requires some fixes in places where we have hardcoded "tailscale-ipn" as the GUI filename. We also do some cleanup in clientupdate to ensure that autoupdates will continue to work correctly with the temporary "-winui" package variant. Fixes #17480 Updates https://github.com/tailscale/corp/issues/29940 Signed-off-by: Aaron Klotz <aaron@tailscale.com>
This commit is contained in:
@@ -9,30 +9,31 @@ import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"sync"
|
||||
"runtime"
|
||||
|
||||
"golang.org/x/sys/windows/registry"
|
||||
"tailscale.com/types/lazy"
|
||||
"tailscale.com/types/logger"
|
||||
"tailscale.com/util/winutil"
|
||||
)
|
||||
|
||||
const (
|
||||
sendFileShellKey = `*\shell\tailscale`
|
||||
)
|
||||
|
||||
var ipnExePath struct {
|
||||
sync.Mutex
|
||||
cache string // absolute path of tailscale-ipn.exe, populated lazily on first use
|
||||
}
|
||||
var ipnExePath lazy.SyncValue[string] // absolute path of the GUI executable
|
||||
|
||||
func getIpnExePath(logf logger.Logf) string {
|
||||
ipnExePath.Lock()
|
||||
defer ipnExePath.Unlock()
|
||||
|
||||
if ipnExePath.cache != "" {
|
||||
return ipnExePath.cache
|
||||
exe, err := winutil.GUIPathFromReg()
|
||||
if err == nil {
|
||||
return exe
|
||||
}
|
||||
|
||||
// Find the absolute path of tailscale-ipn.exe assuming that it's in the same
|
||||
return findGUIInSameDirAsThisExe(logf)
|
||||
}
|
||||
|
||||
func findGUIInSameDirAsThisExe(logf logger.Logf) string {
|
||||
// Find the absolute path of the GUI, assuming that it's in the same
|
||||
// directory as this executable (tailscaled.exe).
|
||||
p, err := os.Executable()
|
||||
if err != nil {
|
||||
@@ -43,14 +44,23 @@ func getIpnExePath(logf logger.Logf) string {
|
||||
logf("filepath.EvalSymlinks error: %v", err)
|
||||
return ""
|
||||
}
|
||||
p = filepath.Join(filepath.Dir(p), "tailscale-ipn.exe")
|
||||
if p, err = filepath.Abs(p); err != nil {
|
||||
logf("filepath.Abs error: %v", err)
|
||||
return ""
|
||||
}
|
||||
ipnExePath.cache = p
|
||||
|
||||
return p
|
||||
d := filepath.Dir(p)
|
||||
candidates := []string{"tailscale-ipn.exe"}
|
||||
if runtime.GOARCH == "arm64" {
|
||||
// This name may be used on Windows 10 ARM64.
|
||||
candidates = append(candidates, "tailscale-gui-386.exe")
|
||||
}
|
||||
for _, c := range candidates {
|
||||
testPath := filepath.Join(d, c)
|
||||
if _, err := os.Stat(testPath); err == nil {
|
||||
return testPath
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
// SetFileSharingEnabled adds/removes "Send with Tailscale" from the Windows shell menu.
|
||||
@@ -64,7 +74,9 @@ func SetFileSharingEnabled(enabled bool, logf logger.Logf) {
|
||||
}
|
||||
|
||||
func enableFileSharing(logf logger.Logf) {
|
||||
path := getIpnExePath(logf)
|
||||
path := ipnExePath.Get(func() string {
|
||||
return getIpnExePath(logf)
|
||||
})
|
||||
if path == "" {
|
||||
return
|
||||
}
|
||||
@@ -79,7 +91,7 @@ func enableFileSharing(logf logger.Logf) {
|
||||
logf("k.SetStringValue error: %v", err)
|
||||
return
|
||||
}
|
||||
if err := k.SetStringValue("Icon", path+",0"); err != nil {
|
||||
if err := k.SetStringValue("Icon", path+",1"); err != nil {
|
||||
logf("k.SetStringValue error: %v", err)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -8,8 +8,10 @@ import (
|
||||
"fmt"
|
||||
"log"
|
||||
"math"
|
||||
"os"
|
||||
"os/exec"
|
||||
"os/user"
|
||||
"path/filepath"
|
||||
"reflect"
|
||||
"runtime"
|
||||
"strings"
|
||||
@@ -33,6 +35,10 @@ var ErrNoShell = errors.New("no Shell process is present")
|
||||
// ErrNoValue is returned when the value doesn't exist in the registry.
|
||||
var ErrNoValue = registry.ErrNotExist
|
||||
|
||||
// ErrBadRegValueFormat is returned when a string value does not match the
|
||||
// expected format.
|
||||
var ErrBadRegValueFormat = errors.New("registry value formatted incorrectly")
|
||||
|
||||
// GetDesktopPID searches the PID of the process that's running the
|
||||
// currently active desktop. Returns ErrNoShell if the shell is not present.
|
||||
// Usually the PID will be for explorer.exe.
|
||||
@@ -947,3 +953,22 @@ func IsDomainName(name string) (bool, error) {
|
||||
|
||||
return isDomainName(name16)
|
||||
}
|
||||
|
||||
// GUIPathFromReg obtains the path to the client GUI executable from the
|
||||
// registry value that was written during installation.
|
||||
func GUIPathFromReg() (string, error) {
|
||||
regPath, err := GetRegString("GUIPath")
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
if !filepath.IsAbs(regPath) {
|
||||
return "", ErrBadRegValueFormat
|
||||
}
|
||||
|
||||
if _, err := os.Stat(regPath); err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
return regPath, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user