[v3] Port operating system detection

This commit is contained in:
Lea Anthony 2023-08-18 10:24:45 +10:00
commit c169d26d95
3 changed files with 32 additions and 15 deletions

View file

@ -2,9 +2,10 @@ package operatingsystem
// OS contains information about the operating system
type OS struct {
ID string
Name string
Version string
ID string
Name string
Version string
Branding string
}
// Info retrieves information about the current platform

View file

@ -7,6 +7,32 @@ import (
"strings"
)
var macOSNames = map[string]string{
"10.10": "Yosemite",
"10.11": "El Capitan",
"10.12": "Sierra",
"10.13": "High Sierra",
"10.14": "Mojave",
"10.15": "Catalina",
"11": "Big Sur",
"12": "Monterey",
"13": "Ventura",
"14": "Sonoma",
// Add newer versions as they are released...
}
func getOSName(version string) string {
trimmedVersion := version
if !strings.HasPrefix(version, "10.") {
trimmedVersion = strings.SplitN(version, ".", 2)[0]
}
name, ok := macOSNames[version]
if ok {
return name
}
return "MacOS " + trimmedVersion
}
func getSysctlValue(key string) (string, error) {
// Run "sysctl" command
command := exec.Command("sysctl", key)
@ -39,18 +65,7 @@ func platformInfo() (*OS, error) {
return nil, err
}
result.ID = ID
// cmd := CreateCommand(directory, command, args...)
// var stdo, stde bytes.Buffer
// cmd.Stdout = &stdo
// cmd.Stderr = &stde
// err := cmd.Run()
// return stdo.String(), stde.String(), err
// }
// sysctl := shell.NewCommand("sysctl")
// kern.ostype: Darwin
// kern.osrelease: 20.1.0
// kern.osrevision: 199506
result.Branding = getOSName(result.Version)
return &result, nil
}

View file

@ -27,6 +27,7 @@ func platformInfo() (*OS, error) {
result.Name = productName
result.Version = fmt.Sprintf("%s (Build: %s)", releaseId, currentBuild)
result.ID = displayVersion
result.Branding = w32.GetBranding()
return &result, key.Close()
}