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

[v3] Make Windows window class configurable #3682

Merged
merged 1 commit into from
Aug 20, 2024

Conversation

windom
Copy link

@windom windom commented Aug 15, 2024

Description

This patch makes the window class configurable on Windows. Kept the current hard-coded value as default.
This can come handy for example in NSIS installer scripts, where we want to check if an instance of the app is running using FindWindow with an own window class.

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 configurable WndClass property to enhance the flexibility of Windows application options.
    • Improved the initialization of the window class name to be dynamically determined from application configuration.
  • Bug Fixes

    • Addressed issues related to the generation of the syso icon file.
  • Documentation

    • Updated the changelog to include new configuration options for Windows applications.

Copy link
Contributor

coderabbitai bot commented Aug 15, 2024

Walkthrough

The recent changes enhance the Windows application by introducing a dynamic WndClass property in the WindowsOptions struct. This allows the window class name to default to "WailsWebviewWindow" when unspecified, thereby improving configurability and maintainability across various components that utilize the window class.

Changes

Files Change Summary
application.go, application_options.go, application_windows.go, mainthread_windows.go, systemtray_windows.go, webview_window_windows.go Introduced a WndClass field in WindowsOptions for flexible class name configuration. Updated components to retrieve the window class name dynamically from the application options.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant App as Application
    participant Options as WindowsOptions

    User->>App: Start Application
    App->>Options: Check WndClass
    alt WndClass is empty
        Options-->>App: Set WndClass to "WailsWebviewWindow"
    else WndClass is provided
        Options-->>App: Use provided WndClass
    end
    App->>App: Initialize Window with ClassName
    App-->>User: Launch Application Window
Loading

Poem

In a world where windows gleam,
A rabbit hops with joy and dream.
"WailsWebview," a name anew,
Configurations bright and true.
With options set, we dance and play,
Windows open, come what may! 🐇✨


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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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 as 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.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

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

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between cfab21b and fd8accd.

Files selected for processing (6)
  • v3/pkg/application/application.go (1 hunks)
  • v3/pkg/application/application_options.go (1 hunks)
  • v3/pkg/application/application_windows.go (2 hunks)
  • v3/pkg/application/mainthread_windows.go (1 hunks)
  • v3/pkg/application/systemtray_windows.go (1 hunks)
  • v3/pkg/application/webview_window_windows.go (1 hunks)
Additional comments not posted (6)
v3/pkg/application/mainthread_windows.go (1)

37-37: Enhancement: Dynamic window class configuration.

The use of w32.MustStringToUTF16Ptr(m.parent.options.Windows.WndClass) allows for dynamic configuration of the window class name, enhancing flexibility. Ensure that the default value is correctly set and documented.

v3/pkg/application/application_options.go (1)

185-187: Enhancement: Added WndClass to WindowsOptions.

The addition of the WndClass field allows for configurable window class names, improving flexibility. Ensure that the default value "WailsWebviewWindow" is correctly set and documented.

v3/pkg/application/systemtray_windows.go (1)

153-153: Enhancement: Dynamic window class configuration in system tray.

The use of w32.MustStringToUTF16Ptr(globalApplication.options.Windows.WndClass) allows for dynamic configuration of the window class name, enhancing flexibility and maintainability. Ensure that the default value is correctly set and documented.

v3/pkg/application/application_windows.go (1)

211-211: Ensure the default value for WndClass is set.

The assignment of m.windowClass.ClassName now relies on m.parent.options.Windows.WndClass. Ensure that the default value is properly set elsewhere in the codebase to avoid potential nil dereference or empty string issues.

Verification successful

Default value for WndClass is properly set.

The code in v3/pkg/application/application.go ensures that WndClass is assigned a default value of "WailsWebviewWindow" if it is initially empty. This addresses the concern about potential nil dereference or empty string issues.

  • v3/pkg/application/application.go: Default assignment of WndClass.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that the default value for `WndClass` is set in the codebase.

# Test: Search for the default assignment of `WndClass`. Expect: Default value assignment to ensure non-empty string.
rg --type go --word-regexp 'WndClass' -A 5

Length of output: 2799

v3/pkg/application/application.go (1)

171-173: Good use of default value assignment for WndClass.

This change ensures that a default window class name is assigned, improving robustness and preventing potential issues with uninitialized values.

v3/pkg/application/webview_window_windows.go (1)

252-252: Dynamic window class name enhances flexibility.

The use of globalApplication.options.Windows.WndClass allows for a configurable window class name, which is a significant improvement for flexibility.

Ensure that this change is compatible with all scenarios where the window class name is utilized.

Verification successful

Consistent Usage of Configurable Window Class Name

The WndClass field is consistently used across multiple files in the codebase, ensuring compatibility with the configurable window class name feature. The default value assignment in application.go further ensures robustness. No issues found with the current implementation.

  • Files with WndClass usage:
    • v3/pkg/application/mainthread_windows.go
    • v3/pkg/application/webview_window_windows.go
    • v3/pkg/application/systemtray_windows.go
    • v3/pkg/application/application_windows.go
    • v3/pkg/application/application.go
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of the configurable window class name across the codebase.

# Test: Search for all occurrences of `WndClass` usage. Expect: Consistent usage of the configurable class name.
rg --type go --word-regexp 'WndClass' -A 5

Length of output: 2799

@leaanthony
Copy link
Member

Thanks 🙏 Please could you add an entry to the changelog located at mkdocs-website/docs/changelog.md? Thanks!

Copy link

sonarcloud bot commented Aug 19, 2024

@windom
Copy link
Author

windom commented Aug 19, 2024

Updated changelog, force-pushed.

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

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between fd8accd and 590cdcc.

Files selected for processing (7)
  • mkdocs-website/docs/en/changelog.md (1 hunks)
  • v3/pkg/application/application.go (1 hunks)
  • v3/pkg/application/application_options.go (1 hunks)
  • v3/pkg/application/application_windows.go (2 hunks)
  • v3/pkg/application/mainthread_windows.go (1 hunks)
  • v3/pkg/application/systemtray_windows.go (1 hunks)
  • v3/pkg/application/webview_window_windows.go (1 hunks)
Files skipped from review as they are similar to previous changes (6)
  • v3/pkg/application/application.go
  • v3/pkg/application/application_options.go
  • v3/pkg/application/application_windows.go
  • v3/pkg/application/mainthread_windows.go
  • v3/pkg/application/systemtray_windows.go
  • v3/pkg/application/webview_window_windows.go
Additional comments not posted (1)
mkdocs-website/docs/en/changelog.md (1)

20-21: Changelog entry is well-structured.

The addition of the "Window class name option" is correctly documented under the "Added" section. It includes proper attribution and a link to the pull request, ensuring clarity and traceability.

@leaanthony leaanthony merged commit 46dbbb3 into wailsapp:v3-alpha Aug 20, 2024
9 of 10 checks passed
@windom windom deleted the v3/customize-windowclass branch August 21, 2024 19:35
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