diff --git a/v2/cmd/wails/doctor.go b/v2/cmd/wails/doctor.go index 5306cab1742..eac5048b3f2 100644 --- a/v2/cmd/wails/doctor.go +++ b/v2/cmd/wails/doctor.go @@ -2,12 +2,13 @@ package main import ( "fmt" - "github.com/wailsapp/wails/v2/internal/shell" "runtime" "runtime/debug" "strconv" "strings" + "github.com/wailsapp/wails/v2/internal/shell" + "github.com/pterm/pterm" "github.com/jaypipes/ghw" @@ -78,6 +79,7 @@ func diagnoseEnvironment(f *flags.Doctor) error { {pterm.Bold.Sprint("OS"), info.OS.Name}, {pterm.Bold.Sprint("Version"), info.OS.Version}, {pterm.Bold.Sprint("ID"), info.OS.ID}, + {pterm.Bold.Sprint("Branding"), info.OS.Branding}, {pterm.Bold.Sprint("Go Version"), runtime.Version()}, {pterm.Bold.Sprint("Platform"), runtime.GOOS}, {pterm.Bold.Sprint("Architecture"), runtime.GOARCH}, diff --git a/v2/internal/system/operatingsystem/os.go b/v2/internal/system/operatingsystem/os.go index 39f1de8e086..028a97b2e60 100644 --- a/v2/internal/system/operatingsystem/os.go +++ b/v2/internal/system/operatingsystem/os.go @@ -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 diff --git a/v2/internal/system/operatingsystem/os_windows.go b/v2/internal/system/operatingsystem/os_windows.go index 38ea43a1264..a9aa05a924b 100644 --- a/v2/internal/system/operatingsystem/os_windows.go +++ b/v2/internal/system/operatingsystem/os_windows.go @@ -4,10 +4,44 @@ package operatingsystem import ( "fmt" + "strings" + "syscall" + "unsafe" + "golang.org/x/sys/windows" "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) { // Default value var result OS @@ -27,6 +61,7 @@ func platformInfo() (*OS, error) { result.Name = productName result.Version = fmt.Sprintf("%s (Build: %s)", releaseId, currentBuild) result.ID = displayVersion + result.Branding = getBranding() return &result, key.Close() } diff --git a/website/src/pages/changelog.mdx b/website/src/pages/changelog.mdx index 3cc504c9050..023a2e89da9 100644 --- a/website/src/pages/changelog.mdx +++ b/website/src/pages/changelog.mdx @@ -19,6 +19,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added - Added option to set window class name on Windows. Added in [PR](https://github.com/wailsapp/wails/pull/3828) by @APshenkin +- Added "Branding" section to `wails doctor` to correctly identify Windows 11 [#3891](https://github.com/wailsapp/wails/pull/3891) by [@ronen25](https://github.com/ronen25) ### Fixed - Fixed dev mode logging bug by @attperac in [#3972](https://wailsapp/wails/pull/3972)