close
Skip to content

Allow set window class name via options for Windows#3828

Merged
leaanthony merged 3 commits into
wailsapp:masterfrom
APshenkin:feature/allow-set-windows-window-class-name
Oct 20, 2024
Merged

Allow set window class name via options for Windows#3828
leaanthony merged 3 commits into
wailsapp:masterfrom
APshenkin:feature/allow-set-windows-window-class-name

Conversation

@APshenkin

@APshenkin APshenkin commented Oct 14, 2024

Copy link
Copy Markdown
Contributor

Description

There could be cases, when developers need to get window handle and pass it to some Windows functions. For example, you may want to pass window handle to nCrypt API (https://learn.microsoft.com/en-us/windows/win32/seccng/key-storage-property-identifiers#ncrypt_window_handle_property). This change will allow to set unique className for your app, so that searching for window handle will not be affected if different Wails based apps are presented on the system

Fixes # (issue)

Type of change

Please delete options that are not 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?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration using wails doctor.

  • Windows
  • macOS
  • Linux

Test Configuration

Please paste the output of wails doctor. If you are unable to run this command, please describe your environment in as much detail as possible.

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

    • Introduced a customizable WindowClassName option for Windows application windows.
    • Enhanced configurability for window options, including translucency and icon handling.
  • Bug Fixes

    • Resolved cross-compilation issues and improved file drop events on Windows.
    • Fixed CGO memory issues and ensured JSON compatibility for author names.
  • Documentation

    • Updated documentation to reflect the new WindowClassName field and other configuration options.
    • Clarified deprecated fields and added details on various options and callbacks.
  • Chores

    • Updated changelog to include recent features, bug fixes, and ongoing improvements.

@coderabbitai

coderabbitai Bot commented Oct 14, 2024

Copy link
Copy Markdown
Contributor

Walkthrough

The changes involve modifications to the NewWindow function in the Window struct to incorporate a new configurable option, WindowClassName, allowing users to specify a custom class name for application windows on Windows platforms. This option defaults to "wailsWindow" if not provided. Additionally, updates were made to the Options struct to include this new field, and the documentation was revised to reflect these changes and clarify existing options. The changelog was also updated to note these enhancements and related bug fixes.

Changes

File Path Change Summary
v2/internal/frontend/desktop/windows/window.go Modified NewWindow function to include a check for WindowClassName and adjusted window options handling.
v2/pkg/options/windows/windows.go Added WindowClassName field to Options struct, defaulting to 'wailsWindow' if empty.
website/docs/reference/options.mdx Updated documentation to include WindowClassName, clarified existing fields, and noted deprecated options.
website/src/pages/changelog.mdx Updated changelog to reflect new features, including the window class name option, and documented bug fixes and changes.

Possibly related PRs

Suggested reviewers

  • leaanthony

Poem

🐰 In a world of windows, bright and new,
A class name added, just for you!
With options aplenty, so much to see,
Configurable magic, hop with glee!
So raise your glass, let’s celebrate,
For wails of joy, we can’t wait! 🎉


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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Outside diff range and nitpick comments (5)
v2/pkg/options/windows/windows.go (1)

121-123: LGTM! Consider adding validation and a constant for the default value.

The addition of the WindowClassName field to the Options struct is well-placed and documented. It aligns with the PR objectives by allowing users to specify a custom class name for the window.

Suggestions for improvement:

  1. Consider adding validation for the WindowClassName to ensure it meets Windows requirements for class names.
  2. It might be beneficial to define a constant for the default value "wailsWindow" for consistency and easier maintenance.

Here's a suggested implementation incorporating these improvements:

const DefaultWindowClassName = "wailsWindow"

type Options struct {
    // ... other fields ...

    // Class name for the window. If empty or invalid, DefaultWindowClassName will be used.
    WindowClassName string
}

// ValidateWindowClassName checks if the provided class name is valid for Windows
func ValidateWindowClassName(className string) bool {
    // Implement validation logic here
    // For example, check length, allowed characters, etc.
    return true // Placeholder
}

This approach provides a clear default value and allows for validation of the class name.

v2/internal/frontend/desktop/windows/window.go (1)

73-79: LGTM! Consider a minor readability improvement.

The implementation of a configurable window class name is well done and aligns with the PR objectives. It maintains backward compatibility while allowing for customization.

For slightly improved readability, consider using a ternary-like operation:

windowClassName := "wailsWindow"
if windowsOptions != nil {
    windowClassName = winc.FirstNonEmpty(windowsOptions.WindowClassName, windowClassName)
}

This assumes the existence of a FirstNonEmpty helper function, which you might need to implement if it doesn't exist:

func FirstNonEmpty(s ...string) string {
    for _, v := range s {
        if v != "" {
            return v
        }
    }
    return ""
}

This suggestion is optional and doesn't affect the functionality of the code.

website/docs/reference/options.mdx (2)

102-104: LGTM! Consider clarifying the default behavior in the comment.

The new WebviewGpuDisabled field is well-placed and appropriately typed. The comment is clear, but it could be enhanced slightly.

Consider updating the comment to explicitly mention the default behavior:

-// Disable GPU hardware acceleration for the webview
+// Disable GPU hardware acceleration for the webview. Default is false (GPU acceleration enabled).

809-815: LGTM! Minor formatting suggestion.

The new WindowClassName field is well-documented and appropriately placed within the Windows options.

Consider adjusting the formatting for consistency with other options:

-#### WindowClassName
+#### WindowClassName
-
-Class name for the window. If empty, 'wailsWindow' will be used.
-
-Name: WindowClassName<br/>
-Type: `string`
+Class name for the window. If empty, 'wailsWindow' will be used.
+
+Name: WindowClassName<br/>
+Type: `string`

This aligns the format with other option descriptions in the document.

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

16-16: Minor typo in the Unreleased section header

There's a small typo in the Unreleased section header. The word "Added" is repeated.

Consider removing the duplicate "Added":

-## [Unreleased] ### Added - Added option to set window class name on Windows.
+## [Unreleased] ### Added - Option to set window class name on Windows.
🧰 Tools
🪛 LanguageTool

[duplication] ~16-~16: Possible typo: you repeated a word
Context: ...f vulnerabilities. ## [Unreleased] ### Added - Added option to set window class name on Wind...

(ENGLISH_WORD_REPEAT_RULE)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 26ff639 and f5fae6e.

📒 Files selected for processing (4)
  • v2/internal/frontend/desktop/windows/window.go (1 hunks)
  • v2/pkg/options/windows/windows.go (1 hunks)
  • website/docs/reference/options.mdx (3 hunks)
  • website/src/pages/changelog.mdx (1 hunks)
🧰 Additional context used
🪛 LanguageTool
website/src/pages/changelog.mdx

[duplication] ~16-~16: Possible typo: you repeated a word
Context: ...f vulnerabilities. ## [Unreleased] ### Added - Added option to set window class name on Wind...

(ENGLISH_WORD_REPEAT_RULE)

🔇 Additional comments (5)
v2/pkg/options/windows/windows.go (1)

121-123: Summary: Valuable addition with minor suggestions for improvement

The addition of the WindowClassName field is a valuable enhancement that aligns well with the PR objectives. It allows developers to set a unique class name for their applications, which is particularly useful for obtaining window handles for various Windows functions.

Key points:

  1. The change is minimal and focused, which is good for maintainability.
  2. The new field is well-documented within the struct.
  3. We've suggested adding validation and a constant for the default value to improve robustness.
  4. Verification of the field's usage in other parts of the codebase is recommended to ensure full implementation.

Overall, this change appears to be a positive addition to the project, addressing the need for custom window class names in Wails applications on Windows.

v2/internal/frontend/desktop/windows/window.go (1)

Line range hint 1-479: Overall, the changes look good. Consider additional testing and documentation.

The implementation of the configurable window class name is well-executed and fulfills the PR objectives without introducing breaking changes. The code is consistent with the existing style and doesn't raise any apparent security or performance concerns.

To ensure the changes work as expected across different scenarios, consider the following:

  1. Add unit tests to verify the behavior with different WindowClassName values.
  2. Update the documentation to reflect this new configurable option.
  3. Consider adding a comment explaining the purpose of the custom window class name for future maintainers.

To verify the impact of these changes, you can run the following script:

This script will help ensure that the new feature is properly tested, documented, and explained.

website/docs/reference/options.mdx (2)

Line range hint 327-332: LGTM! Important compatibility information added.

This note provides crucial information about compatibility issues between vite v5.0.0+ and wails v2, along with guidance for users and a link to more detailed information.

The addition of this note is valuable for users and helps prevent potential issues. It's well-placed within the AssetServer options context.


Line range hint 1-1000: Overall changes improve documentation and add valuable options.

The updates to this file enhance the Wails options documentation in several ways:

  1. Addition of the WindowClassName option for Windows, allowing for greater customization.
  2. Introduction of the WebviewGpuDisabled option, providing more control over hardware acceleration.
  3. Important compatibility note regarding vite and wails versions.

These changes provide developers with more flexibility and crucial information for using the Wails framework effectively.

The additions and modifications are well-integrated into the existing documentation structure and provide valuable enhancements to the Wails options.

🧰 Tools
🪛 LanguageTool

[uncategorized] ~818-~818: When ‘Mac-specific’ is used as a modifier, it is usually spelled with a hyphen.
Context: ... Type: string ### Mac This defines Mac specific options. Name: Mac
Type: `...

(SPECIFIC_HYPHEN)

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

Line range hint 1-1000: Missing changelog entry for v2.0.0-beta.41

The changelog appears to be missing an entry for version v2.0.0-beta.41. This could be an oversight, or there might not have been any significant changes in this version.

To verify if this version exists and if there were any changes, you can run the following script:

If there were changes, consider adding an entry for this version in the changelog.

🧰 Tools
🪛 LanguageTool

[duplication] ~16-~16: Possible typo: you repeated a word
Context: ...f vulnerabilities. ## [Unreleased] ### Added - Added option to set window class name on Wind...

(ENGLISH_WORD_REPEAT_RULE)


[duplication] ~19-~19: Possible typo: you repeated a word
Context: ...app/wails/pull/3828) by @APshenkin ### Fixed - Fixed cross compilation failed with CGO [PR](...

(ENGLISH_WORD_REPEAT_RULE)

Comment on lines +121 to +123

// Class name for the window. If empty, 'wailsWindow' will be used.
WindowClassName string

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

💡 Codebase verification

WindowClassName is not utilized in window creation functions

The WindowClassName field is defined but not used in any window creation calls. Please ensure that this field is correctly integrated into the window creation logic.

  • Update the window creation functions to utilize the WindowClassName field where appropriate.
🔗 Analysis chain

Verify usage of the new WindowClassName field

The addition of the WindowClassName field looks good. To ensure full implementation:

  1. Verify that this new option is properly utilized in the window creation logic.
  2. Update any relevant documentation or examples to showcase this new feature.
  3. Consider adding a unit test to verify the behavior when this option is set.

Run the following script to check for usage of the new field:

This will help ensure that the new option is properly integrated into the existing codebase.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for usage of WindowClassName in the codebase

# Test: Search for WindowClassName usage
echo "Searching for WindowClassName usage:"
rg --type go 'WindowClassName'

# Test: Search for window creation logic that might need updating
echo "\nSearching for window creation logic:"
rg --type go 'CreateWindowEx|RegisterClassEx'

Length of output: 2332


Script:

#!/bin/bash
# Description: Verify if WindowClassName is used in window creation functions

# Search for WindowClassName near CreateWindowEx and RegisterClassEx

echo "Searching for WindowClassName usage near CreateWindowEx:"
rg --type go -C 2 'CreateWindowEx' | rg 'WindowClassName'

echo -e "\nSearching for WindowClassName usage near RegisterClassEx:"
rg --type go -C 2 'RegisterClassEx' | rg 'WindowClassName'

Length of output: 366

@sonarqubecloud

Copy link
Copy Markdown

@leaanthony
leaanthony merged commit 1b6ed1b into wailsapp:master Oct 20, 2024
@leaanthony

Copy link
Copy Markdown
Member

Thanks for this @APshenkin 🙏

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.

2 participants