5
0
mirror of https://github.com/wailsapp/wails.git synced 2025-05-02 13:02:04 +08:00

Added initial Windows 11-supporting branding

This commit is contained in:
Ronen Lapushner 2025-01-21 21:15:24 +02:00
parent 481c145cd3
commit 2aea5e2dae
2 changed files with 39 additions and 3 deletions

View File

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

View File

@ -4,10 +4,44 @@ package operatingsystem
import ( import (
"fmt" "fmt"
"strings"
"syscall"
"unsafe"
"golang.org/x/sys/windows"
"golang.org/x/sys/windows/registry" "golang.org/x/sys/windows/registry"
) )
func stripNulls(str string) string {
// Split the string into substrings at each null character
substrings := strings.Split(str, "\x00")
// Join the substrings back into a single string
strippedStr := strings.Join(substrings, "")
return strippedStr
}
func mustStringToUTF16Ptr(input string) *uint16 {
input = stripNulls(input)
result, err := syscall.UTF16PtrFromString(input)
if err != nil {
panic(err)
}
return result
}
func getBranding() string {
var modBranding = syscall.NewLazyDLL("winbrand.dll")
var brandingFormatString = modBranding.NewProc("BrandingFormatString")
windowsLong := mustStringToUTF16Ptr("%WINDOWS_LONG%\x00")
ret, _, _ := brandingFormatString.Call(
uintptr(unsafe.Pointer(windowsLong)),
)
return windows.UTF16PtrToString((*uint16)(unsafe.Pointer(ret)))
}
func platformInfo() (*OS, error) { func platformInfo() (*OS, error) {
// Default value // Default value
var result OS var result OS
@ -27,6 +61,7 @@ func platformInfo() (*OS, error) {
result.Name = productName result.Name = productName
result.Version = fmt.Sprintf("%s (Build: %s)", releaseId, currentBuild) result.Version = fmt.Sprintf("%s (Build: %s)", releaseId, currentBuild)
result.ID = displayVersion result.ID = displayVersion
result.Branding = getBranding()
return &result, key.Close() return &result, key.Close()
} }