Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Windows 11 identification in wails doctor #3891

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

ronen25
Copy link

@ronen25 ronen25 commented Nov 17, 2024

Description

Fixes #3890

This PR fixes a small issue in wails doctor: Windows 11 installations are reported as "Windows 10".

The SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProductName key which Wails uses to identify the Windows version does indeed report "Windows 10" on Windows 11 systems.
In this case, we have no choice but to rely on the build number to correctly identify the system. I've used a Wikipedia list (documented in the PR) to determine that any consumer version of Windows with a build number greater than 22000 is Windows 11.

Note: Windows Server versions are probably incorrectly reported as well, but at time of writing I don't have any VMs to test with. Anyways, this PR will lay some small groundwork for fixing that as well if the need arises.

It's really not a big deal, and more of an oddity on Windows' side, and I've seen this misreporting happen in many programs.

Type of change

Please select the option that is relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

Tested by running wails doctor and seeing the correct OS name reported on every test system.

Tested on:

  1. A Surface Pro 9 with Windows 11 Home
  2. An old Windows 10 Pro system

I have access to a Mac system, could test for regressions although I don't think it's necessary...

  • Windows
  • macOS
  • Linux

If you checked Linux, please specify the distro and version.

Test Configuration

# Wails
Version  | v2.9.2
Revision | bdb67632247bd95413e93b6abab2d1a805df37af
Modified | false

# System
┌─────────────────────────────────────────────────────────────────────────────────────────┐
| OS           | Windows 11 Home                                                          |
| Version      | 2009 (Build: 22631)                                                      |
| ID           | 23H2                                                                     |
| Go Version   | go1.23.3                                                                 |
| Platform     | windows                                                                  |
| Architecture | amd64                                                                    |
| CPU          | 12th Gen Intel(R) Core(TM) i7-1255U                                      |
| GPU          | Intel(R) Iris(R) Xe Graphics (Intel Corporation) - Driver: 30.0.101.3118 |
| Memory       | 16GB                                                                     |
└─────────────────────────────────────────────────────────────────────────────────────────┘

# Dependencies
┌───────────────────────────────────────────────────────┐
| Dependency | Package Name | Status    | Version       |
| WebView2   | N/A          | Installed | 130.0.2849.80 |
| Nodejs     | N/A          | Installed | 22.11.0       |
| npm        | N/A          | Installed | 10.9.0        |
| *upx       | N/A          | Available |               |
| *nsis      | N/A          | Available |               |
└─────────────── * - Optional Dependency ───────────────┘

Checklist:

  • I have updated website/src/pages/changelog.mdx with details of this PR
  • My code follows the general coding style of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

Summary by CodeRabbit

  • New Features

    • Added operating system branding information retrieval.
    • Enhanced system diagnostics to display branding details.
  • Improvements

    • Expanded OS information struct to include branding field.
    • Updated documentation to include a "Branding" section for wails doctor.

Copy link
Contributor

coderabbitai bot commented Nov 17, 2024

Walkthrough

The pull request introduces enhancements to the Windows operating system information retrieval in the Wails project. New functions have been added to the os_windows.go file to improve branding information extraction, including stripNulls for string cleaning, mustStringToUTF16Ptr for UTF-16 pointer conversion, and getBranding to retrieve Windows branding details. The OS struct in os.go has been extended with a new Branding field, and the doctor.go file now displays this branding information in the system diagnostics output.

Changes

File Change Summary
v2/internal/system/operatingsystem/os_windows.go Added stripNulls, mustStringToUTF16Ptr, and getBranding functions; modified platformInfo to include branding
v2/internal/system/operatingsystem/os.go Added Branding field to OS struct
v2/cmd/wails/doctor.go Added branding information to system table output
website/src/pages/changelog.mdx Added "Branding" section to wails doctor documentation; updated Mac App Store guide; removed outdated documentation

Assessment against linked issues

Objective Addressed Explanation
Correctly identify Windows 11 [#3890]

Possibly related PRs

  • [v3] Make Windows window class configurable #3682: This PR adds a new field Branding to the WindowsOptions struct, which is directly related to the branding information introduced in the main PR's platformInfo function.
  • V2 bugfix/windows syscall go 1.23 #3707: This PR addresses compatibility issues with Windows dialogs, which may relate to the new branding functionality in the main PR, as both involve enhancements to Windows-specific features.
  • Fix invalid path for windows dialogs #4019: This PR fixes issues related to invalid paths in Windows dialogs, which aligns with the main PR's focus on improving Windows-specific functionalities, including branding retrieval.

Suggested labels

TODO

Poem

🐰 A rabbit's tale of Windows might,
Branding secrets now brought to light!
From 10 to 11, the truth we'll tell,
With code that rings our version bell!
Hop-py debugging, code so bright! 🖥️


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 74fa413 and 98f3cc8.

📒 Files selected for processing (1)
  • website/src/pages/changelog.mdx (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • website/src/pages/changelog.mdx

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (1)
v2/internal/system/operatingsystem/os_windows.go (1)

29-36: Consider improvements to the Windows version detection logic

While the current implementation correctly identifies Windows 11, consider these improvements:

  1. Define 22000 as a named constant for better maintainability
  2. Add a comment about Windows Server handling
  3. Consider more robust product name replacement
 //go:build windows
 
 package operatingsystem
 
+const (
+    // Build number that distinguishes Windows 11 from Windows 10
+    // https://en.wikipedia.org/wiki/List_of_Microsoft_Windows_versions#Personal_computer_versions
+    windows11MinBuildNumber = 22000
+)
+
 // ... existing imports ...
 
 func platformInfo() (*OS, error) {
     // ... existing code ...
 
     // Windows 10 and 11 both declare the product name as "Windows 10"
     // We determine the difference using the build number:
     // https://en.wikipedia.org/wiki/List_of_Microsoft_Windows_versions#Personal_computer_versions
+    // Note: This logic applies to consumer Windows versions. Windows Server versions may need different handling.
     if buildNum, err := strconv.Atoi(currentBuild); err == nil {
-        if buildNum >= 22000 {
+        if buildNum >= windows11MinBuildNumber {
             productName = strings.Replace(productName, "Windows 10", "Windows 11", -1)
         }
     }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between ba38474 and bdb6763.

📒 Files selected for processing (2)
  • v2/internal/system/operatingsystem/os_windows.go (2 hunks)
  • website/src/pages/changelog.mdx (1 hunks)
🔇 Additional comments (3)
v2/internal/system/operatingsystem/os_windows.go (2)

7-8: LGTM: Required imports added

The new imports are necessary for the Windows 11 detection logic: strconv for build number conversion and strings for product name manipulation.


29-36: Verify Windows version detection across different editions

The current implementation needs verification across different Windows editions and versions.

✅ Verification successful

Let me gather more information about the Windows version detection implementation and tests.


Windows version detection implementation is robust and well-structured

The implementation is actually quite comprehensive and reliable:

  • Uses official Windows registry keys from SOFTWARE\Microsoft\Windows NT\CurrentVersion
  • Has proper build number detection (22000+) for Windows 11 distinction
  • Includes a dedicated WindowsVersionInfo struct with version comparison capabilities
  • Handles error cases gracefully with fallback values
  • Uses multiple version identifiers (build number, release ID, display version) for accurate detection

The code follows best practices and official Microsoft documentation for Windows version detection. No issues found.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for existing Windows version detection tests
echo "Searching for Windows version detection tests..."
rg -l "TestPlatformInfo|Windows.*detection|build.*number" --type go

# Look for other Windows registry key usages
echo "Checking other Windows registry key usages..."
ast-grep --pattern 'registry.OpenKey($_, $_, $_)'

# Check for potential version detection patterns
echo "Checking for version detection patterns..."
rg "Windows (10|11|Server)" --type go

Length of output: 2394


Script:

#!/bin/bash
# Check the implementation details of version detection
echo "Checking version detection implementation..."
cat v2/internal/system/operatingsystem/os_windows.go
cat v2/internal/system/operatingsystem/version_windows.go

# Look for test files
echo "Checking for test files..."
fd "_test.go" --type f --exec grep -l "Windows" {}

Length of output: 3098

website/src/pages/changelog.mdx (1)

27-27: LGTM! Well-documented changelog entry.

The changelog entry follows best practices by:

  • Clearly describing what was fixed
  • Attributing the change to the contributor
  • Being placed in the correct "Fixed" section

@leaanthony
Copy link
Member

leaanthony commented Nov 17, 2024

Thanks for taking the time to open this. If it's a big concern, I'd suggest back porting the code that's in v3 which picks up the DisplayVersion key. Would be easier than managing version numbers which doesn't always work unfortunately.

https://github.com/wailsapp/wails/blob/v3-alpha/v3%2Finternal%2Foperatingsystem%2Fversion_windows.go#L32

@ronen25
Copy link
Author

ronen25 commented Nov 19, 2024

Hi, thanks for the quick reply!

It's really not a big deal, and I see that in v3 alpha there's a "Branding" entry which pretty much does the trick. In reality I was just looking for a relatively easy first issue to start contributing to the project :-)

I'm closing this PR.

Thanks again!

@ronen25 ronen25 closed this Nov 19, 2024
@leaanthony
Copy link
Member

I'm happy for this PR to go ahead! I was just pointing out that there's a reg key that will save you calculating versions 😃

@ronen25 ronen25 reopened this Nov 19, 2024
@ronen25
Copy link
Author

ronen25 commented Nov 19, 2024

Whoops, sorry for misunderstanding. Will fix soon and commit for review :-)

@leaanthony
Copy link
Member

Hi @ronen25 - what's the status of this? Thanks 👍

@ronen25
Copy link
Author

ronen25 commented Jan 13, 2025

@leaanthony Apologies, life got in the way :-)
Will push for review this weekend (Jan. 17/18)

@ronen25 ronen25 reopened this Jan 21, 2025
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
v2/internal/system/operatingsystem/os_windows.go (1)

15-23: Simplify the stripNulls function.

The current implementation can be simplified using strings.ReplaceAll.

 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
+    return strings.ReplaceAll(str, "\x00", "")
 }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f8984df and f82c971.

📒 Files selected for processing (3)
  • v2/cmd/wails/doctor.go (2 hunks)
  • v2/internal/system/operatingsystem/os.go (1 hunks)
  • v2/internal/system/operatingsystem/os_windows.go (2 hunks)
🔇 Additional comments (4)
v2/internal/system/operatingsystem/os.go (1)

5-8: LGTM! Clean addition of the Branding field.

The addition of the Branding field to the OS struct is well-structured and aligns with the PR objectives.

v2/internal/system/operatingsystem/os_windows.go (2)

64-64: LGTM! Clean integration of branding information.

The addition of branding information to the platformInfo function is straightforward and well-integrated.


34-43: Document the usage of %WINDOWS_LONG% format string.

The getBranding function uses a hardcoded format string without documentation explaining its purpose or possible values.

Add a comment explaining the purpose and possible values of the format string:

 func getBranding() string {
+    // %WINDOWS_LONG% is a format string used by winbrand.dll to retrieve the full Windows branding
+    // It returns strings like "Windows 11 Pro" or "Windows 10 Enterprise"
     var modBranding = syscall.NewLazyDLL("winbrand.dll")
     var brandingFormatString = modBranding.NewProc("BrandingFormatString")

Also, consider error handling for the DLL and procedure calls:

✅ Verification successful

Document the format string but error handling is optional

The suggestion to document the %WINDOWS_LONG% format string is valid and will improve code maintainability. However, the error handling suggestion can be safely ignored as:

  • The current implementation follows the codebase's pattern for non-critical UI operations
  • winbrand.dll is a core Windows component, similar to user32.dll
  • The function is used for display purposes only
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Verify if winbrand.dll is consistently available across Windows versions
rg -g "*.go" "winbrand\.dll" .

Length of output: 137


Script:

#!/bin/bash
# Check error handling patterns in Windows DLL calls
ast-grep --pattern 'NewLazyDLL($$$)'

# Look for similar Windows API documentation patterns
rg -g "*.go" -B 2 "syscall\.NewLazyDLL" .

# Check for other Windows-specific error handling
rg -g "*_windows.go" "_, err :=" .

Length of output: 6773

v2/cmd/wails/doctor.go (1)

82-82: LGTM! Clean addition of branding information to diagnostics.

The addition of the branding information to the system diagnostics output is well-placed and consistent with the existing format.

Comment on lines +25 to +32
func mustStringToUTF16Ptr(input string) *uint16 {
input = stripNulls(input)
result, err := syscall.UTF16PtrFromString(input)
if err != nil {
panic(err)
}
return result
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Consider error handling instead of panic.

The mustStringToUTF16Ptr function panics on error, which could make the application unstable. Consider handling the error gracefully.

-func mustStringToUTF16Ptr(input string) *uint16 {
+func stringToUTF16Ptr(input string) (*uint16, error) {
     input = stripNulls(input)
     result, err := syscall.UTF16PtrFromString(input)
-    if err != nil {
-        panic(err)
-    }
-    return result
+    return result, err
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
func mustStringToUTF16Ptr(input string) *uint16 {
input = stripNulls(input)
result, err := syscall.UTF16PtrFromString(input)
if err != nil {
panic(err)
}
return result
}
func stringToUTF16Ptr(input string) (*uint16, error) {
input = stripNulls(input)
result, err := syscall.UTF16PtrFromString(input)
return result, err
}

@leaanthony
Copy link
Member

Thanks 🙏 Please could you add an entry to the changelog located at website/src/pages/changelog.mdx?

@ronen25
Copy link
Author

ronen25 commented Jan 23, 2025

@leaanthony Done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

wails doctor reports Windows 11 as "Windows 10"
2 participants