prop.go 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. // Copyright (c) 2020 Tailscale Inc & AUTHORS All rights reserved.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE file.
  4. package version
  5. import (
  6. "os"
  7. "path/filepath"
  8. "runtime"
  9. "strings"
  10. "sync/atomic"
  11. )
  12. // IsMobile reports whether this is a mobile client build.
  13. func IsMobile() bool {
  14. return runtime.GOOS == "android" || runtime.GOOS == "ios"
  15. }
  16. // OS returns runtime.GOOS, except instead of returning "darwin" it
  17. // returns "iOS" or "macOS".
  18. func OS() string {
  19. if runtime.GOOS == "ios" {
  20. return "iOS"
  21. }
  22. if runtime.GOOS == "darwin" {
  23. return "macOS"
  24. }
  25. return runtime.GOOS
  26. }
  27. // IsSandboxedMacOS reports whether this process is a sandboxed macOS
  28. // process. It is true for the Mac App Store and macsys (System
  29. // Extension) version on macOS, and false for tailscaled-on-macOS.
  30. func IsSandboxedMacOS() bool {
  31. if runtime.GOOS != "darwin" {
  32. return false
  33. }
  34. if IsMacSysExt() {
  35. return true
  36. }
  37. exe, _ := os.Executable()
  38. return strings.HasSuffix(exe, "/Contents/MacOS/Tailscale")
  39. }
  40. var isMacSysExt atomic.Value
  41. // IsMacSysExt whether this binary is from the standalone "System
  42. // Extension" (a.k.a. "macsys") version of Tailscale for macOS.
  43. func IsMacSysExt() bool {
  44. if runtime.GOOS != "darwin" {
  45. return false
  46. }
  47. if b, ok := isMacSysExt.Load().(bool); ok {
  48. return b
  49. }
  50. exe, err := os.Executable()
  51. if err != nil {
  52. return false
  53. }
  54. v := filepath.Base(exe) == "io.tailscale.ipn.macsys.network-extension"
  55. isMacSysExt.Store(v)
  56. return v
  57. }