[v3 mac] Improved operating system detection

This commit is contained in:
Lea Anthony
2023-08-18 10:34:32 +10:00
parent 946a4c56a0
commit 8bde3d7522
4 changed files with 42 additions and 16 deletions
+13 -3
View File
@@ -2,9 +2,19 @@ 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
}
func (o *OS) AsLogSlice() []any {
return []any{
"ID", o.ID,
"Name", o.Name,
"Version", o.Version,
"Branding", o.Branding,
}
}
// Info retrieves information about the current platform
+27 -12
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[trimmedVersion]
if ok {
return name
}
return "MacOS " + version
}
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
}
@@ -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()
}
+1 -1
View File
@@ -277,6 +277,6 @@ func (a *App) logPlatformInfo() {
return
}
a.info("Platform Info:", "name", info.Name, "version", info.Version, "id", info.ID)
a.info("Platform Info:", info.AsLogSlice()...)
}