mirror of
https://github.com/wailsapp/wails.git
synced 2025-05-02 19:50:15 +08:00

* Add Windows version helper * Initial theme support * Support custom themes * Update docs * Honour HighContrast theme. Remove import "C". Refactor * Small refactor * Support inactive theme * Update Docs
60 lines
1.4 KiB
Go
60 lines
1.4 KiB
Go
package operatingsystem
|
|
|
|
import (
|
|
"golang.org/x/sys/windows/registry"
|
|
"strconv"
|
|
)
|
|
|
|
type WindowsVersionInfo struct {
|
|
Major int
|
|
Minor int
|
|
Build int
|
|
DisplayVersion string
|
|
}
|
|
|
|
func (w *WindowsVersionInfo) IsWindowsVersionAtLeast(major, minor, buildNumber int) bool {
|
|
return w.Major >= major && w.Minor >= minor && w.Build >= buildNumber
|
|
}
|
|
|
|
func GetWindowsVersionInfo() (*WindowsVersionInfo, error) {
|
|
key, err := registry.OpenKey(registry.LOCAL_MACHINE, `SOFTWARE\Microsoft\Windows NT\CurrentVersion`, registry.QUERY_VALUE)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return &WindowsVersionInfo{
|
|
Major: regDWORDKeyAsInt(key, "CurrentMajorVersionNumber"),
|
|
Minor: regDWORDKeyAsInt(key, "CurrentMinorVersionNumber"),
|
|
Build: regStringKeyAsInt(key, "CurrentBuildNumber"),
|
|
DisplayVersion: regKeyAsString(key, "DisplayVersion"),
|
|
}, nil
|
|
}
|
|
|
|
func regDWORDKeyAsInt(key registry.Key, name string) int {
|
|
result, _, err := key.GetIntegerValue(name)
|
|
if err != nil {
|
|
return -1
|
|
}
|
|
return int(result)
|
|
}
|
|
|
|
func regStringKeyAsInt(key registry.Key, name string) int {
|
|
resultStr, _, err := key.GetStringValue(name)
|
|
if err != nil {
|
|
return -1
|
|
}
|
|
result, err := strconv.Atoi(resultStr)
|
|
if err != nil {
|
|
return -1
|
|
}
|
|
return result
|
|
}
|
|
|
|
func regKeyAsString(key registry.Key, name string) string {
|
|
resultStr, _, err := key.GetStringValue(name)
|
|
if err != nil {
|
|
return ""
|
|
}
|
|
return resultStr
|
|
}
|