2020-03-02 20:37:28 +00:00
|
|
|
// Copyright (c) 2020 Tailscale Inc & AUTHORS All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
package version
|
|
|
|
|
2021-04-28 15:34:13 +00:00
|
|
|
import (
|
|
|
|
"os"
|
2021-04-28 21:57:04 +00:00
|
|
|
"path/filepath"
|
2021-04-28 15:34:13 +00:00
|
|
|
"runtime"
|
|
|
|
"strings"
|
2022-08-04 17:43:49 +00:00
|
|
|
|
|
|
|
"tailscale.com/syncs"
|
2021-04-28 15:34:13 +00:00
|
|
|
)
|
2020-03-02 20:37:28 +00:00
|
|
|
|
|
|
|
// IsMobile reports whether this is a mobile client build.
|
|
|
|
func IsMobile() bool {
|
2021-04-20 04:59:55 +00:00
|
|
|
return runtime.GOOS == "android" || runtime.GOOS == "ios"
|
2020-03-02 20:37:28 +00:00
|
|
|
}
|
2020-04-01 15:49:25 +00:00
|
|
|
|
|
|
|
// OS returns runtime.GOOS, except instead of returning "darwin" it
|
|
|
|
// returns "iOS" or "macOS".
|
|
|
|
func OS() string {
|
2021-04-20 04:59:55 +00:00
|
|
|
if runtime.GOOS == "ios" {
|
2020-11-11 17:04:34 +00:00
|
|
|
return "iOS"
|
|
|
|
}
|
2020-04-01 15:49:25 +00:00
|
|
|
if runtime.GOOS == "darwin" {
|
|
|
|
return "macOS"
|
|
|
|
}
|
|
|
|
return runtime.GOOS
|
|
|
|
}
|
2021-04-28 15:34:13 +00:00
|
|
|
|
|
|
|
// IsSandboxedMacOS reports whether this process is a sandboxed macOS
|
2022-11-16 00:55:27 +00:00
|
|
|
// process (either the app or the extension). It is true for the Mac App Store
|
|
|
|
// and macsys (System Extension) version on macOS, and false for
|
|
|
|
// tailscaled-on-macOS.
|
2021-04-28 15:34:13 +00:00
|
|
|
func IsSandboxedMacOS() bool {
|
|
|
|
if runtime.GOOS != "darwin" {
|
|
|
|
return false
|
|
|
|
}
|
2021-04-28 21:57:04 +00:00
|
|
|
if IsMacSysExt() {
|
|
|
|
return true
|
|
|
|
}
|
2021-04-28 15:34:13 +00:00
|
|
|
exe, _ := os.Executable()
|
2022-11-16 00:55:27 +00:00
|
|
|
return strings.HasSuffix(exe, "/Contents/MacOS/Tailscale") || strings.HasSuffix(exe, "/Contents/MacOS/IPNExtension")
|
2021-04-28 15:34:13 +00:00
|
|
|
}
|
2021-04-28 21:57:04 +00:00
|
|
|
|
2022-08-04 17:43:49 +00:00
|
|
|
var isMacSysExt syncs.AtomicValue[bool]
|
2021-04-28 21:57:04 +00:00
|
|
|
|
|
|
|
// IsMacSysExt whether this binary is from the standalone "System
|
|
|
|
// Extension" (a.k.a. "macsys") version of Tailscale for macOS.
|
|
|
|
func IsMacSysExt() bool {
|
|
|
|
if runtime.GOOS != "darwin" {
|
|
|
|
return false
|
|
|
|
}
|
2022-08-04 17:43:49 +00:00
|
|
|
if b, ok := isMacSysExt.LoadOk(); ok {
|
2021-04-28 21:57:04 +00:00
|
|
|
return b
|
|
|
|
}
|
|
|
|
exe, err := os.Executable()
|
|
|
|
if err != nil {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
v := filepath.Base(exe) == "io.tailscale.ipn.macsys.network-extension"
|
|
|
|
isMacSysExt.Store(v)
|
|
|
|
return v
|
|
|
|
}
|
2021-12-17 20:40:24 +00:00
|
|
|
|
|
|
|
// IsWindowsGUI reports whether the current process is the Windows GUI.
|
|
|
|
func IsWindowsGUI() bool {
|
|
|
|
if runtime.GOOS != "windows" {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
exe, _ := os.Executable()
|
|
|
|
exe = filepath.Base(exe)
|
|
|
|
return strings.EqualFold(exe, "tailscale-ipn.exe") || strings.EqualFold(exe, "tailscale-ipn")
|
|
|
|
}
|