Skip to content

window.ToggleFrameless() api #4317

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

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

Conversation

atterpac
Copy link
Member

@atterpac atterpac commented May 29, 2025

Implements the window.ToggleFrameless() api internally it just uses the window.setFrameless toggling it as the opposite of the current value so Developer does not need to card about the current state to swap it

Changes:

  • Runtime will need to be updated on dev machines as I reorganized the message processor values to keep the ToggleXXX in the same range
  • Regenerated new events
  • Updated messageprocessor_window.go
  • Updated runtime window.ts
  • Updated API example in `v3/examples/

Summary by CodeRabbit

  • New Features

    • Added the ability to toggle the window between frameless and normal states via a new API method and UI button in the frameless window example.
  • Documentation

    • Updated the changelog to include the new window toggling feature.
  • Style

    • Improved code readability with consistent multi-line formatting in several function signatures and calls.

Copy link
Contributor

coderabbitai bot commented May 29, 2025

Walkthrough

A new ToggleFrameless() API method has been introduced, allowing windows to toggle between frameless and normal states. This addition required updates across the runtime, event types, changelog, and example assets. Associated event IDs, constants, and exported interfaces were updated, and a new event type and handler were added to support this feature.

Changes

Files/Paths Change Summary
v3/internal/runtime/desktop/@wailsio/runtime/src/window.ts, .../event_types.ts Added ToggleFrameless() method to Window class and associated event type constant.
v3/pkg/application/window.go, .../webview_window.go, .../messageprocessor_window.go Added ToggleFrameless method to Window interface, implementation, and message processor logic.
v3/pkg/events/events.go, .../events.txt, .../events_darwin.h, .../events_linux.h Added new event ID and constant for WindowToggleFrameless; incremented related event IDs.
v3/internal/assetserver/bundledassets/runtime.js Refactored and reordered runtime code; added ToggleFrameless() to exported Window class.
v3/examples/frameless/assets/index.html Added UI button and JS handler to trigger window.wails.Window.ToggleFrameless().
docs/src/content/docs/changelog.mdx Documented new ToggleFrameless() API in the changelog.
v3/internal/runtime/desktop/@wailsio/runtime/package.json Bumped package version from 3.0.0-alpha.67 to 3.0.0-alpha.68.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant UI (HTML/JS)
    participant Runtime JS (window.ts)
    participant Go Backend (window.go/webview_window.go)
    participant OS Window

    User->>UI (HTML/JS): Click "Toggle Frameless" button
    UI (HTML/JS)->>Runtime JS: window.wails.Window.ToggleFrameless()
    Runtime JS->>Go Backend: Invoke ToggleFrameless method
    Go Backend->>OS Window: Toggle frameless state
    OS Window-->>Go Backend: Frameless state toggled
    Go Backend-->>Runtime JS: Success/acknowledgement
    Runtime JS-->>UI (HTML/JS): (Optional) Update UI or state
Loading

Possibly related PRs

Suggested reviewers

  • leaanthony

Poem

A rabbit hopped up to the screen,
Saw windows shift from seen to unseen—
With frameless toggles, click and gleam,
The borders vanish, so pristine!
Code and carrots, side by side,
In alpha sixty-eight we ride.
🐇✨

✨ Finishing Touches
  • 📝 Generate Docstrings

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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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 generate sequence diagram to generate a sequence diagram of the changes in this 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.

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.

@github-actions github-actions bot added Documentation Improvements or additions to documentation v3-alpha runtime labels May 29, 2025
Copy link

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 comments (1)
v3/internal/assetserver/bundledassets/runtime.js (1)

1-2: 💡 Verification agent

🧩 Analysis chain

Consider generating minified files during the build process instead of committing them.

Committing minified/bundled JavaScript files makes code reviews challenging and can lead to merge conflicts. It's generally better to commit only the source files and generate the minified versions as part of the build process.

Run the following script to check if there's a corresponding source file and build process:

Additionally, ensure that:

  1. The source code for this runtime is properly maintained
  2. Source maps are generated for debugging purposes
  3. The build process is documented

🏁 Script executed:

#!/bin/bash
# Description: Look for the source file and build configuration for runtime.js

# Check for source files in the runtime directory
fd -t f -e ts -e js runtime v3/internal/runtime/

# Check for build configuration files
fd -t f "package.json|tsconfig.json|webpack.config|rollup.config|vite.config" v3/

# Check if there's a build script that generates this file
rg -A 5 "runtime.js|bundledassets" --glob "*.json" --glob "*.js" --glob "*.ts"

Length of output: 66113


🏁 Script executed:

#!/bin/bash
# Inspect build scripts in the runtime package
jq '.scripts' v3/internal/runtime/desktop/@wailsio/runtime/package.json

Length of output: 780


Automate bundling of runtime.js and remove it from VCS

We have a maintained TypeScript source and build in v3/internal/runtime/desktop/@wailsio/runtime/:

  • Source: v3/internal/runtime/desktop/@wailsio/runtime/src/runtime.ts
  • Build scripts: "build": "npm run build:code & npm run build:docs & wait" in its package.json

But the minified result at
v3/internal/assetserver/bundledassets/runtime.js
is still checked into Git. Committing generated assets makes reviews brittle and invites merge conflicts.

Action items:

  • Move bundledassets/runtime.js out of version control (add to .gitignore).
  • Add a Go //go:generate or CI step that:
    1. Runs npm ci && npm run build in the TS runtime package.
    2. Invokes your assetserver bundler to copy/minify into bundledassets/runtime.js.
  • Document these steps (e.g. in CONTRIBUTING.md), so that regenerating the asset is automatic.
🧰 Tools
🪛 Biome (1.9.4)

[error] 1-1: This array contains an empty slot.

Unsafe fix: Replace hole with undefined

(lint/suspicious/noSparseArray)


[error] 1-1: Shouldn't redeclare 'i'. Consider to delete it or rename it.

'i' is defined here:

(lint/suspicious/noRedeclare)


[error] 1-1: This variable is used before its declaration.

The variable is declared here:

(lint/correctness/noInvalidUseBeforeDeclaration)


[error] 1-1: This variable is used before its declaration.

The variable is declared here:

(lint/correctness/noInvalidUseBeforeDeclaration)


[error] 1-1: Do not add then to a class.

(lint/suspicious/noThenProperty)

🧹 Nitpick comments (1)
v3/examples/frameless/assets/index.html (1)

49-49: Fix invalid CSS color value.

The lightred color value is not a valid CSS color. Consider using a valid CSS color instead.

-    <div class="quarter" style="background-color: lightred;"><div>Not Draggable</div><button id="toggle-frameless">Toggle Frameless</button></div>
+    <div class="quarter" style="background-color: lightcoral;"><div>Not Draggable</div><button id="toggle-frameless">Toggle Frameless</button></div>

Alternative valid options: lightcoral, lightpink, #ffcccb, or rgb(255, 182, 193).

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 83005be and 9925803.

📒 Files selected for processing (13)
  • docs/src/content/docs/changelog.mdx (1 hunks)
  • v3/examples/frameless/assets/index.html (2 hunks)
  • v3/internal/assetserver/bundledassets/runtime.js (1 hunks)
  • v3/internal/runtime/desktop/@wailsio/runtime/package.json (1 hunks)
  • v3/internal/runtime/desktop/@wailsio/runtime/src/event_types.ts (1 hunks)
  • v3/internal/runtime/desktop/@wailsio/runtime/src/window.ts (2 hunks)
  • v3/pkg/application/messageprocessor_window.go (8 hunks)
  • v3/pkg/application/webview_window.go (6 hunks)
  • v3/pkg/application/window.go (1 hunks)
  • v3/pkg/events/events.go (6 hunks)
  • v3/pkg/events/events.txt (2 hunks)
  • v3/pkg/events/events_darwin.h (1 hunks)
  • v3/pkg/events/events_linux.h (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (3)
v3/pkg/application/window.go (1)
v3/internal/runtime/desktop/@wailsio/runtime/src/window.ts (1)
  • ToggleFrameless (460-462)
v3/pkg/events/events.go (1)
v3/pkg/application/messageprocessor_window.go (14)
  • WindowToggleFrameless (50-50)
  • WindowRestore (33-33)
  • WindowShow (46-46)
  • WindowUnFullscreen (51-51)
  • WindowUnMaximise (52-52)
  • WindowUnMinimise (53-53)
  • WindowZoom (55-55)
  • WindowZoomIn (56-56)
  • WindowZoomOut (57-57)
  • WindowZoomReset (58-58)
  • WindowHide (21-21)
  • WindowMaximise (26-26)
  • WindowMinimise (27-27)
  • WindowFullscreen (17-17)
v3/pkg/application/webview_window.go (5)
v3/pkg/events/events.go (2)
  • ApplicationEventType (3-3)
  • WindowEventType (4-4)
v3/pkg/application/events.go (1)
  • ApplicationEvent (11-16)
v3/pkg/application/messageprocessor_dialog.go (1)
  • DialogError (14-14)
v3/internal/runtime/desktop/@wailsio/runtime/src/window.ts (2)
  • ToggleFrameless (460-462)
  • SetFrameless (347-349)
v3/pkg/application/mainthread.go (1)
  • InvokeSync (23-32)
🪛 Biome (1.9.4)
v3/internal/assetserver/bundledassets/runtime.js

[error] 1-1: This array contains an empty slot.

Unsafe fix: Replace hole with undefined

(lint/suspicious/noSparseArray)


[error] 1-1: Shouldn't redeclare 'i'. Consider to delete it or rename it.

'i' is defined here:

(lint/suspicious/noRedeclare)


[error] 1-1: This variable is used before its declaration.

The variable is declared here:

(lint/correctness/noInvalidUseBeforeDeclaration)


[error] 1-1: This variable is used before its declaration.

The variable is declared here:

(lint/correctness/noInvalidUseBeforeDeclaration)


[error] 1-1: Do not add then to a class.

(lint/suspicious/noThenProperty)

🔇 Additional comments (22)
v3/internal/runtime/desktop/@wailsio/runtime/package.json (1)

4-4: LGTM! Appropriate version bump for new feature.

The version increment from 3.0.0-alpha.67 to 3.0.0-alpha.68 correctly follows semantic versioning conventions for alpha releases when adding new functionality.

v3/pkg/events/events.txt (1)

15-15: LGTM! Correctly placed and named event.

The new common:WindowToggleFrameless event follows the established naming convention and is properly positioned in alphabetical order within the common window events section.

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

79-79: LGTM! Well-positioned interface method addition.

The ToggleFrameless() method follows Go interface conventions and is logically grouped with other toggle methods. The signature is consistent with the existing toggle methods pattern.

docs/src/content/docs/changelog.mdx (1)

36-36: LGTM! Well-formatted changelog entry.

The changelog entry follows the project's established format with proper attribution, PR reference, and code formatting. It's correctly placed in the "Added" section under "Unreleased".

v3/internal/runtime/desktop/@wailsio/runtime/src/event_types.ts (1)

220-220: LGTM! Correctly implemented event type.

The new WindowToggleFrameless event type follows the established naming conventions and is properly placed in alphabetical order within the Common events section. The event string uses the appropriate "common:" namespace prefix for cross-platform functionality.

v3/examples/frameless/assets/index.html (1)

37-40: LGTM! Correct event handler implementation.

The event listener for the toggle frameless button follows the same pattern as the existing minimize and close button handlers, properly calling window.wails.Window.ToggleFrameless().

v3/internal/runtime/desktop/@wailsio/runtime/src/window.ts (3)

54-54: LGTM! Correct method constant addition.

The new ToggleFramelessMethod constant is properly assigned the next sequential value (40) and follows the established naming convention.


55-62: LGTM! Proper constant value adjustments.

All subsequent method constants have been correctly incremented by 1 to maintain the sequential numbering after the insertion of ToggleFramelessMethod. This ensures no conflicts in method identifiers.


457-462: LGTM! Correct method implementation.

The ToggleFrameless method implementation follows the exact same pattern as other toggle methods (ToggleFullscreen, ToggleMaximise):

  • Proper JSDoc documentation
  • Correct return type (Promise<void>)
  • Uses the appropriate method constant
  • Consistent formatting and style
v3/pkg/events/events_darwin.h (1)

9-142: LGTM! Correct event ID adjustments for new event insertion.

All macOS event ID constants have been systematically incremented by 1, which is necessary to accommodate the new WindowToggleFrameless event (ID 1038) while maintaining sequential, non-overlapping event IDs. The MAX_EVENTS value has been properly updated from 1188 to 1189.

This change aligns with the cross-platform event system requirements and ensures consistency across all platform-specific event headers.

v3/pkg/application/messageprocessor_window.go (4)

50-58: LGTM: Consistent event ID reorganization for new toggle functionality.

The addition of WindowToggleFrameless = 40 and the systematic increment of subsequent constant values maintains the proper sequence and prevents ID conflicts. This aligns with the coordinated event system updates across other files.


102-102: LGTM: Proper method name mapping added.

The mapping entry correctly associates the constant with the method name for debugging and logging purposes.


113-119: LGTM: Improved code readability with multi-line formatting.

The function signature formatting enhances readability without changing functionality. This follows good Go formatting practices for functions with multiple parameters.


397-399: LGTM: Consistent implementation pattern for toggle functionality.

The new case handler follows the established pattern:

  1. Calls the appropriate window method (window.ToggleFrameless())
  2. Responds with success using m.ok(rw)

This is consistent with other toggle methods like WindowToggleFullscreen and WindowToggleMaximise.

v3/pkg/events/events_linux.h (1)

9-18: LGTM: Coordinated event ID shift maintains proper sequence.

The systematic increment of all Linux-specific event IDs by 1 is necessary to accommodate the new WindowToggleFrameless event inserted at ID 1038 in the common events. The MAX_EVENTS update to 1057 is also correct. This maintains non-overlapping event ID ranges across platforms.

v3/pkg/events/events.go (4)

23-23: LGTM: New window event type properly declared.

The WindowToggleFrameless field is correctly added to the commonEvents struct, maintaining consistency with other window event types.


52-62: LGTM: Systematic event ID assignment maintains sequence integrity.

The new WindowToggleFrameless event is assigned ID 1038, properly positioned between WindowMinimise (1037) and WindowRestore (1039). All subsequent event IDs are correctly incremented by 1 to maintain the sequence without conflicts.


81-88: LGTM: Platform-specific event IDs properly coordinated.

All platform-specific event IDs (Linux, Mac, Windows) have been systematically incremented by 1 to maintain non-overlapping ranges after the insertion of the new common event. This ensures consistent event ID management across all platforms.

Also applies to: 231-362, 417-460


483-493: LGTM: JavaScript event mapping properly updated.

The new event mapping 1038: "common:WindowToggleFrameless" is correctly added, and all subsequent mappings are properly incremented to reflect the new event ID sequence. This ensures proper event handling in the JavaScript runtime.

v3/pkg/application/webview_window.go (2)

210-213: LGTM: Improved code readability with consistent multi-line formatting.

The function signature and call formatting changes enhance code readability without altering functionality. This follows Go best practices for functions with multiple parameters.

Also applies to: 293-295, 318-325, 331-337, 343-349, 355-362, 774-778, 799-802


1011-1019: LGTM: Well-implemented toggle method following established patterns.

The ToggleFrameless method implementation is excellent:

  1. Thread Safety: Properly uses InvokeSync for main thread execution
  2. State Validation: Correctly checks for nil impl and destroyed window state
  3. Logic: Toggles frameless state by calling SetFrameless(!w.options.Frameless)
  4. Consistency: Follows the exact same pattern as ToggleFullscreen() and ToggleMaximise()

The implementation provides the expected functionality of toggling the frameless state without requiring developers to manually track the current state.

v3/internal/assetserver/bundledassets/runtime.js (1)

1-1: The ToggleFrameless() method is correctly integrated.

I can confirm that the new ToggleFrameless() method has been properly added to the Window class in the minified runtime, implementing the PR's main objective.

🧰 Tools
🪛 Biome (1.9.4)

[error] 1-1: This array contains an empty slot.

Unsafe fix: Replace hole with undefined

(lint/suspicious/noSparseArray)


[error] 1-1: Shouldn't redeclare 'i'. Consider to delete it or rename it.

'i' is defined here:

(lint/suspicious/noRedeclare)


[error] 1-1: This variable is used before its declaration.

The variable is declared here:

(lint/correctness/noInvalidUseBeforeDeclaration)


[error] 1-1: This variable is used before its declaration.

The variable is declared here:

(lint/correctness/noInvalidUseBeforeDeclaration)


[error] 1-1: Do not add then to a class.

(lint/suspicious/noThenProperty)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Documentation Improvements or additions to documentation runtime v3-alpha
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant