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] Typed events #4161

Open
wants to merge 29 commits into
base: v3-alpha
Choose a base branch
from

Conversation

fbbdev
Copy link
Collaborator

@fbbdev fbbdev commented Mar 24, 2025

Description

This PR enhances the v3 binding generator with support for registered events with strict data typing. Typescript IDEs will provide autocompletion support in JS/TS files for registered events. Data types will be checked at build time on the frontend, at runtime on the Go side.

🚨 This PR includes one breaking change: EmitEvent methods (on App and Window structs) won't wrap event data in a slice anymore when at most one data argument is provided.

The change is intended to make EmitEvent's behaviour more intuitive for the most common case (one data argument) and align it with the JS runtime.

The impact is mitigated by the fact that all runtime type assertions expecting a slice in event data will break, thus alerting developers to the change.

Many thanks to @IanVS who helped with the template updates.

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?

Examples and automated regression tests have been run and verified to be working correctly. The updated templates have been tested manually.

  • Windows
  • macOS
  • Linux

Test Configuration

 Wails (v3.0.0-dev)  Wails Doctor

# System

┌──────────────────────────────────────────────────────────────────────────┐
| Name          | MacOS                                                    |
| Version       | 12.6.6                                                   |
| ID            | 21G646                                                   |
| Branding      | Monterey                                                 |
| Platform      | darwin                                                   |
| Architecture  | amd64                                                    |
| Apple Silicon | unknown                                                  |
| CPU           | Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz                 |
| CPU           | Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz                 |
| GPU           |  cores, Metal Family: Supported, Metal GPUFamily macOS 2 |
|               |       Metal Family: Supported, Metal GPUFamily macOS 2   |
| Memory        | 32 GB                                                    |
└──────────────────────────────────────────────────────────────────────────┘

# Build Environment

┌─────────────────────────────────────────────────────────┐
| Wails CLI    | v3.0.0-dev                               |
| Go Version   | go1.24.0                                 |
| Revision     | 5c6d8a9086acf1b25224632ae5fcbe193906e1a0 |
| Modified     | false                                    |
| -buildmode   | exe                                      |
| -compiler    | gc                                       |
| CGO_CFLAGS   |                                          |
| CGO_CPPFLAGS |                                          |
| CGO_CXXFLAGS |                                          |
| CGO_ENABLED  | 1                                        |
| CGO_LDFLAGS  |                                          |
| GOAMD64      | v1                                       |
| GOARCH       | amd64                                    |
| GOOS         | darwin                                   |
| vcs          | git                                      |
| vcs.modified | false                                    |
| vcs.revision | 5c6d8a9086acf1b25224632ae5fcbe193906e1a0 |
| vcs.time     | 2025-03-24T00:24:29Z                     |
└─────────────────────────────────────────────────────────┘

# Dependencies

┌───────────────────────────┐
| Xcode cli tools | 2395    |
| npm             | 10.8.2  |
| *NSIS           | v3.10   |
|                           |
└─ * - Optional Dependency ─┘

# Checking for issues

 SUCCESS  No issues found

# Diagnosis

 SUCCESS  Your system is ready for Wails development!

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

Copy link
Contributor

coderabbitai bot commented Mar 24, 2025

Important

Review skipped

More than 25% of the files skipped due to max files limit. The review is being skipped to prevent a low-quality review.

114 files out of 221 files are above the max files limit of 100. Please upgrade to Pro plan to get higher limits.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @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.

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.

@IanVS
Copy link

IanVS commented Mar 24, 2025

I'm testing out this branch, and noticed a couple of things:

  1. I am no longer able to emit events without data. Instead, I now get
internal/ui/systray-menu.go:81:17: not enough arguments in call to app.EmitEvent
    have (string)
    want (string, any)
make: *** [dnclient-desktop] Error 1
  1. When typecasting event data, it is no longer a slice, which I am happy about, but it means I need to update my typecasts:
-               nm := e.Data.([]any)[0].(map[string]dnclientd.Network)
+               nm := e.Data.(map[string]dnclientd.Network)

I'm glad to do this, but it might be considered a "breaking" change.

  1. Lastly, is there any way I can enforce that all events are registered? I would like to ensure that going forward, events are not added without first registering them in init.

@fbbdev
Copy link
Collaborator Author

fbbdev commented Mar 24, 2025

Hey @IanVS thanks for the testing work!

I am no longer able to emit events without data.

When typecasting event data, it is no longer a slice

You're right about both changes and yes, they're breaking. I had forgotten about that detail. I'll have to update the PR and changelog.

Let's discuss the details over on Discord.

@fbbdev fbbdev force-pushed the v3-alpha-feature/event-types-final branch 2 times, most recently from c2842c7 to dc90eb4 Compare April 6, 2025 08:53
@fbbdev fbbdev force-pushed the v3-alpha-feature/event-types-final branch from dc90eb4 to 2a50cb5 Compare April 6, 2025 09:08
Copy link

sonarqubecloud bot commented Apr 6, 2025

Quality Gate Failed Quality Gate failed

Failed conditions
6.9% Duplication on New Code (required ≤ 3%)
D Reliability Rating on New Code (required ≥ A)

See analysis details on SonarQube Cloud

Catch issues before they fail your Quality Gate with our IDE extension SonarQube for IDE

return ok
}

var knownEvents = map[string]struct{}{
Copy link
Member

Choose a reason for hiding this comment

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

Is this generated from events.txt?

"version": "0.24.2",
"resolved": "https://registry.npmjs.org/@esbuild/aix-ppc64/-/aix-ppc64-0.24.2.tgz",
"integrity": "sha512-thpVCb/rhxE/BnMLQ7GReQLLN8q9qbHmI55F4489/ByVg2aQaQ6kbcLb6FHkocZzQhxc4gx0sCk0tJkKBFzDhA==",
"version": "0.21.5",
Copy link
Member

Choose a reason for hiding this comment

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

This appears to be a downgrade?

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.

3 participants