Skip to content

Commit dbf7bba

Browse files
authoredMar 1, 2025··
Merge pull request #3891 from ronen25/master
Fix Windows 11 identification in `wails doctor`
2 parents 76e41a6 + b2f84d0 commit dbf7bba

File tree

4 files changed

+43
-4
lines changed

4 files changed

+43
-4
lines changed
 

‎v2/cmd/wails/doctor.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@ package main
22

33
import (
44
"fmt"
5-
"github.com/wailsapp/wails/v2/internal/shell"
65
"runtime"
76
"runtime/debug"
87
"strconv"
98
"strings"
109

10+
"github.com/wailsapp/wails/v2/internal/shell"
11+
1112
"github.com/pterm/pterm"
1213

1314
"github.com/jaypipes/ghw"
@@ -78,6 +79,7 @@ func diagnoseEnvironment(f *flags.Doctor) error {
7879
{pterm.Bold.Sprint("OS"), info.OS.Name},
7980
{pterm.Bold.Sprint("Version"), info.OS.Version},
8081
{pterm.Bold.Sprint("ID"), info.OS.ID},
82+
{pterm.Bold.Sprint("Branding"), info.OS.Branding},
8183
{pterm.Bold.Sprint("Go Version"), runtime.Version()},
8284
{pterm.Bold.Sprint("Platform"), runtime.GOOS},
8385
{pterm.Bold.Sprint("Architecture"), runtime.GOARCH},

‎v2/internal/system/operatingsystem/os.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@ package operatingsystem
22

33
// OS contains information about the operating system
44
type OS struct {
5-
ID string
6-
Name string
7-
Version string
5+
ID string
6+
Name string
7+
Version string
8+
Branding string
89
}
910

1011
// Info retrieves information about the current platform

‎v2/internal/system/operatingsystem/os_windows.go

+35
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,44 @@ package operatingsystem
44

55
import (
66
"fmt"
7+
"strings"
8+
"syscall"
9+
"unsafe"
710

11+
"golang.org/x/sys/windows"
812
"golang.org/x/sys/windows/registry"
913
)
1014

15+
func stripNulls(str string) string {
16+
// Split the string into substrings at each null character
17+
substrings := strings.Split(str, "\x00")
18+
19+
// Join the substrings back into a single string
20+
strippedStr := strings.Join(substrings, "")
21+
22+
return strippedStr
23+
}
24+
25+
func mustStringToUTF16Ptr(input string) *uint16 {
26+
input = stripNulls(input)
27+
result, err := syscall.UTF16PtrFromString(input)
28+
if err != nil {
29+
panic(err)
30+
}
31+
return result
32+
}
33+
34+
func getBranding() string {
35+
var modBranding = syscall.NewLazyDLL("winbrand.dll")
36+
var brandingFormatString = modBranding.NewProc("BrandingFormatString")
37+
38+
windowsLong := mustStringToUTF16Ptr("%WINDOWS_LONG%\x00")
39+
ret, _, _ := brandingFormatString.Call(
40+
uintptr(unsafe.Pointer(windowsLong)),
41+
)
42+
return windows.UTF16PtrToString((*uint16)(unsafe.Pointer(ret)))
43+
}
44+
1145
func platformInfo() (*OS, error) {
1246
// Default value
1347
var result OS
@@ -27,6 +61,7 @@ func platformInfo() (*OS, error) {
2761
result.Name = productName
2862
result.Version = fmt.Sprintf("%s (Build: %s)", releaseId, currentBuild)
2963
result.ID = displayVersion
64+
result.Branding = getBranding()
3065

3166
return &result, key.Close()
3267
}

‎website/src/pages/changelog.mdx

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2828

2929
### Added
3030
- Added option to set window class name on Windows. Added in [PR](https://github.com/wailsapp/wails/pull/3828) by @APshenkin
31+
- 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)
3132

3233
### Fixed
3334
- Fixed dev mode logging bug by @attperac in [#3972](https://wailsapp/wails/pull/3972)

0 commit comments

Comments
 (0)
Please sign in to comment.