fix(os): use correct Android platform name

This commit is contained in:
Jan De Dobbeleer 2023-07-14 15:39:18 +02:00 committed by Jan De Dobbeleer
parent 9b011b45a8
commit 1f283051d2
3 changed files with 70 additions and 98 deletions

View file

@ -19,50 +19,6 @@ const (
Linux properties.Property = "linux"
// Windows the string/icon to use for windows
Windows properties.Property = "windows"
// Alma the string/icon to use for Alma
Alma properties.Property = "alma"
// Alpine the string/icon to use for Alpine
Alpine properties.Property = "alpine"
// Aosc the string/icon to use for Aosc
Aosc properties.Property = "aosc"
// Arch the string/icon to use for Arch
Arch properties.Property = "arch"
// Centos the string/icon to use for Centos
Centos properties.Property = "centos"
// Coreos the string/icon to use for Coreos
Coreos properties.Property = "coreos"
// Debian the string/icon to use for Debian
Debian properties.Property = "debian"
// Devuan the string/icon to use for Devuan
Devuan properties.Property = "devuan"
// Raspbian the string/icon to use for Raspbian
Raspbian properties.Property = "raspbian"
// Elementary the string/icon to use for Elementary
Elementary properties.Property = "elementary"
// Fedora the string/icon to use for Fedora
Fedora properties.Property = "fedora"
// Gentoo the string/icon to use for Gentoo
Gentoo properties.Property = "gentoo"
// Mageia the string/icon to use for Mageia
Mageia properties.Property = "mageia"
// Manjaro the string/icon to use for Manjaro
Manjaro properties.Property = "manjaro"
// Mint the string/icon to use for Mint
Mint properties.Property = "mint"
// Nixos the string/icon to use for Nixos
Nixos properties.Property = "nixos"
// Opensuse the string/icon to use for Opensuse
Opensuse properties.Property = "opensuse"
// Redhat the string/icon to use for Redhat
Redhat properties.Property = "redhat"
// Rocky the string/icon to use for Rocky linux
Rocky properties.Property = "rocky"
// Sabayon the string/icon to use for Sabayon
Sabayon properties.Property = "sabayon"
// Slackware the string/icon to use for Slackware
Slackware properties.Property = "slackware"
// Ubuntu the string/icon to use for Ubuntu
Ubuntu properties.Property = "ubuntu"
// DisplayDistroName display the distro name or not
DisplayDistroName properties.Property = "display_distro_name"
)
@ -93,54 +49,42 @@ func (oi *Os) Enabled() bool {
}
func (oi *Os) getDistroIcon(distro string) string {
switch distro {
case "alma":
return oi.props.GetString(Alma, "\uF31D")
case "alpine":
return oi.props.GetString(Alpine, "\uF300")
case "aosc":
return oi.props.GetString(Aosc, "\uF301")
case "arch":
return oi.props.GetString(Arch, "\uF303")
case "centos":
return oi.props.GetString(Centos, "\uF304")
case "coreos":
return oi.props.GetString(Coreos, "\uF305")
case "debian":
return oi.props.GetString(Debian, "\uF306")
case "devuan":
return oi.props.GetString(Devuan, "\uF307")
case "raspbian":
return oi.props.GetString(Raspbian, "\uF315")
case "elementary":
return oi.props.GetString(Elementary, "\uF309")
case "fedora":
return oi.props.GetString(Fedora, "\uF30a")
case "gentoo":
return oi.props.GetString(Gentoo, "\uF30d")
case "mageia":
return oi.props.GetString(Mageia, "\uF310")
case "manjaro":
return oi.props.GetString(Manjaro, "\uF312")
case "mint":
return oi.props.GetString(Mint, "\uF30e")
case "nixos":
return oi.props.GetString(Nixos, "\uF313")
case "opensuse", "opensuse-tumbleweed":
return oi.props.GetString(Opensuse, "\uF314")
case "redhat":
return oi.props.GetString(Redhat, "\uF316")
case "rocky":
return oi.props.GetString(Rocky, "\uF32B")
case "sabayon":
return oi.props.GetString(Sabayon, "\uF317")
case "slackware":
return oi.props.GetString(Slackware, "\uF319")
case "ubuntu":
return oi.props.GetString(Ubuntu, "\uF31b")
case "android":
return oi.props.GetString(Ubuntu, "\uf17b")
iconMap := map[string]string{
"alma": "\uF31D",
"alpine": "\uF300",
"aosc": "\uF301",
"arch": "\uF303",
"centos": "\uF304",
"coreos": "\uF305",
"debian": "\uF306",
"devuan": "\uF307",
"raspbian": "\uF315",
"elementary": "\uF309",
"fedora": "\uF30a",
"gentoo": "\uF30d",
"mageia": "\uF310",
"manjaro": "\uF312",
"mint": "\uF30e",
"nixos": "\uF313",
"opensuse": "\uF314",
"opensuse-tumbleweed": "\uF314",
"redhat": "\uF316",
"rocky": "\uF32B",
"sabayon": "\uF317",
"slackware": "\uF319",
"ubuntu": "\uF31b",
"android": "\uf17b",
}
if icon, ok := iconMap[distro]; ok {
return oi.props.GetString(properties.Property(distro), icon)
}
icon := oi.props.GetString(properties.Property(distro), "")
if len(icon) > 0 {
return icon
}
return oi.props.GetString(Linux, "\uF17C")
}

View file

@ -18,6 +18,7 @@ func TestOSInfo(t *testing.T) {
IsWSL bool
Platform string
DisplayDistroName bool
Icon string
}{
{
Case: "WSL debian - icon",
@ -62,6 +63,19 @@ func TestOSInfo(t *testing.T) {
ExpectedString: "unknown",
GOOS: "unknown",
},
{
Case: "crazy distro, specific icon",
ExpectedString: "crazy distro",
GOOS: "linux",
Platform: "crazy",
Icon: "crazy distro",
},
{
Case: "crazy distro, not mapped",
ExpectedString: "\uf17c",
GOOS: "linux",
Platform: "crazy",
},
}
for _, tc := range cases {
env := new(mock.MockedEnvironment)
@ -71,14 +85,22 @@ func TestOSInfo(t *testing.T) {
Env: make(map[string]string),
WSL: tc.IsWSL,
})
osInfo := &Os{
env: env,
props: properties.Map{
props := properties.Map{
DisplayDistroName: tc.DisplayDistroName,
Windows: "windows",
MacOS: "darwin",
},
}
if len(tc.Icon) != 0 {
props[properties.Property(tc.Platform)] = tc.Icon
}
osInfo := &Os{
env: env,
props: props,
}
_ = osInfo.Enabled()
assert.Equal(t, tc.ExpectedString, renderTemplate(env, osInfo.Template(), osInfo), tc.Case)
}

View file

@ -1705,6 +1705,12 @@
"title": "Alma Icon",
"description": "The icon to use for Alma",
"default": "\uF31D"
},
"android": {
"type": "string",
"title": "Android Icon",
"description": "The icon to use for Alma",
"default": "\uf17b"
}
}
}