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 5 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

    • Enhanced identification of Windows version, now accurately distinguishing between Windows 10 and Windows 11.
    • Added the ability to set the window class name specifically for Windows.
    • Introduced option to specify the minimum macOS version externally.
  • Bug Fixes

    • Resolved cross-compilation issues with CGO.
    • Fixed identification of Windows 11 in the wails doctor command.
    • Addressed native webview2loader problems and updated to go-webview2 v0.1.17.
    • Corrected macOS menu example and ensured proper file drop event functionality on Windows.
  • Documentation

    • Updated changelog to reflect various modifications and removed irrelevant documentation references.

Copy link
Contributor

coderabbitai bot commented Nov 17, 2024

Walkthrough

The changes introduced in this pull request enhance the functionality of the platformInfo method in the os_windows.go file to accurately identify Windows versions based on their build numbers. Specifically, the logic now distinguishes between Windows 10 and Windows 11 by checking if the build number is 22000 or higher. Additionally, the changelog has been updated to reflect various modifications, including fixes for Windows 11 identification in the wails doctor command and the addition of features such as setting a window class name for Windows applications.

Changes

File Path Change Summary
v2/internal/system/operatingsystem/os_windows.go Added logic to differentiate between Windows 10 and Windows 11 based on the build number.
website/src/pages/changelog.mdx Updated changelog to reflect various modifications, including fixing Windows 11 identification and adding new features.

Assessment against linked issues

Objective Addressed Explanation
Fix wails doctor to report Windows 11 correctly

Possibly related PRs

Suggested reviewers

  • leeanthony

Poem

🐰 In the land of code where rabbits hop,
Windows 11 now gets the top!
With build numbers clear, we cheer and play,
Accurate reports brighten the day!
Hopping through changes, we make it right,
Coding with joy, our future is bright! 🌟

Warning

Rate limit exceeded

@ronen25 has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 20 minutes and 14 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

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


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

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

📒 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 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 :-)

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