wails icon indicating copy to clipboard operation
wails copied to clipboard

[v3 feature] support for MacOS Panel

Open nixpare opened this issue 2 years ago • 8 comments

Description

Implementation of WebviewPanel, a new component which extends the functionalities of WebviewWindow adding the capability of creating windows able to behave like panels / overlays. This PR implements the new component for MacOS.

Proposed on Issue https://github.com/wailsapp/wails/issues/3760.

Type of change

  • [x] Bug fix (non-breaking change which fixes an issue)
  • [x] Breaking change (fix or feature that would cause existing functionality to not work as expected)

How Has This Been Tested?

Created an example program to test if both WebviewWindow and WebviewPanel are working as expected (https://github.com/nixpare/wails-mac-panel).

  • [x] Windows: no compilation error, nothing changed on WebviewWindow, panics (as expected) only when trying to use WebviewPanel
  • [x] macOS: working as expected
  • [ ] Linux: not tested but should not differ from Windows

Test Configuration

# System
┌──────────────────────────────┐
| Name          | MacOS        |
| Version       | 14.6.1       |
| ID            | 23G93        |
| Branding      | Sonoma       |
| Platform      | darwin       |
| Architecture  | arm64        |
| Apple Silicon | true         |
| CPU           | Apple M1 Pro |
| CPU           | Unknown      |
| GPU           | Unknown      |
| Memory        | Unknown      |
└──────────────────────────────┘

# Build Environment
┌────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
| Wails CLI      | v3.0.0-alpha.7                                                                                                            |
| Go Version     | go1.23.1                                                                                                                  |
| -buildmode     | exe                                                                                                                       |
| -compiler      | gc                                                                                                                        |
| CGO_CFLAGS     |                                                                                                                           |
| CGO_CPPFLAGS   |                                                                                                                           |
| CGO_CXXFLAGS   |                                                                                                                           |
| CGO_ENABLED    | 1                                                                                                                         |
| CGO_LDFLAGS    |                                                                                                                           |
| DefaultGODEBUG | asynctimerchan=1,gotypesalias=0,httpservecontentkeepheaders=1,tls3des=1,tlskyber=0,x509keypairleaf=0,x509negativeserial=1 |
| GOARCH         | arm64                                                                                                                     |
| GOARM64        | v8.0                                                                                                                      |
| GOOS           | darwin                                                                                                                    |
└────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘

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

# Diagnosis
 SUCCESS  Your system is ready for Wails development!

Checklist:

  • [ ] I have updated website/src/pages/changelog.mdx with details of this PR
  • [x] My code follows the general coding style of this project
  • [x] 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
  • [x] 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

Release Notes

  • New Features

    • Introduced a new WebviewPanel struct for managing webview panels with customizable options.
    • Added methods for opening and enabling developer tools in macOS webview panels.
    • Enhanced Window interface with new methods for flashing, printing, and enabling/disabling windows.
    • Added a new function to retrieve screens for webview panels on macOS.
  • Improvements

    • Refactored window management to utilize a more generalized application.Window type, improving flexibility and future extensibility.
    • Consolidated window setup logic to streamline initialization and enhance maintainability.
    • Enhanced key binding management by processing key binding options for panels and windows.
  • Bug Fixes

    • Improved type safety in key event handling by ensuring methods are invoked on appropriate window types.

nixpare avatar Sep 20 '24 12:09 nixpare

Walkthrough

The changes in this pull request involve a significant refactor of the window management system in the application, transitioning from the application.WebviewWindow type to a more generalized application.Window type. This refactor affects various functionalities related to window properties, key bindings, and event handling across multiple files, including the introduction of new methods and structures to support the management of webview panels and enhance the application's overall window handling capabilities.

Changes

Files Change Summary
v3/examples/build/main.go Updated currentWindow function parameter type from *application.WebviewWindow to application.Window.
v3/examples/events-bug/main.go Changed window parameter type in key binding function from *application.WebviewWindow to application.Window.
v3/examples/keybindings/main.go Modified KeyBindings map to accept application.Window instead of *application.WebviewWindow.
v3/examples/window/main.go Refactored to use application.Window for various window management functionalities, including hiddenWindows and ShouldClose.
v3/internal/commands/appimage_testfiles/main.go Updated window parameter types and modified logic to accommodate application.Window.
v3/pkg/application/application.go Added processKeyBindingOptions function and updated key binding methods to use application.Window.
v3/pkg/application/application_options.go Changed KeyBindings field type in Options struct from map[string]func(window *WebviewWindow) to map[string]func(window Window).
v3/pkg/application/menu_windows.go Updated parameter type in processMenu method from *WebviewWindow to Window.
v3/pkg/application/menuitem_roles.go Introduced type assertion for currentWindow in NewCutMenuItem function to ensure appropriate method calls.
v3/pkg/application/popupmenu_windows.go Modified parameter type in buildMenu method from *WebviewWindow to Window.
v3/pkg/application/screen_darwin.go Added getScreenForPanel function to retrieve screens for macOS panels.
v3/pkg/application/webview_panel.go Introduced WebviewPanel struct and associated methods for managing webview panels.
v3/pkg/application/webview_panel_darwin.go Added macOS-specific functionality for managing webview panels.
v3/pkg/application/webview_window.go Renamed processKeyBindingOptions to windowProcessKeyBindingOptions.
v3/pkg/application/webview_window_darwin.go Added initialization methods for NSWindow and NSPanel, streamlining window setup.

Possibly related issues

  • wailsapp/wails#3760: The changes introduce a WebviewPanel that inherits functionality from WebviewWindow, aligning with the request for support for macOS panels.

Possibly related PRs

  • #3841: This PR addresses the AlwaysOnTop feature during window creation, which is directly related to the changes in the main PR that involve updating the currentWindow function to use the application.Window type, affecting how window properties are managed.
  • #3901: This PR includes fixes for the AlwaysOnTop feature on macOS, which aligns with the changes in the main PR that modify window management functionalities, including setting window properties.

🐇 In the garden, windows bloom,
With panels bright, dispelling gloom.
The keys now dance, the bindings sing,
A joyful hop, a wondrous spring!
With every click, the magic flows,
In rabbit's realm, where progress grows! 🌼


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.

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[bot] avatar Sep 20 '24 12:09 coderabbitai[bot]

Thanks for taking the time to open this. The rabbit has picked up on a few points to address. Would it be possible to also add an example as that really helps testing

leaanthony avatar Sep 20 '24 21:09 leaanthony

Thanks for taking the time to open this. The rabbit has picked up on a few points to address. Would it be possible to also add an example as that really helps testing

At this repo (https://github.com/nixpare/wails-mac-panel) you will find the "hello world" of the project modified to use the WebviewPanel, which is created/focused/hidden with a global hotkey (using an external library). I know its not a lot, but that's what I have for know, if you want me to help you fix some of the problems pointed out by rabbit or write some test, just let me know

nixpare avatar Sep 20 '24 23:09 nixpare

Yeah I think some of the points raised are worth addressing 👍

leaanthony avatar Sep 21 '24 02:09 leaanthony

I will fix all the problems i can, but on those related to memory safety of the objective-c bindings (inherited by v3.0.0-alpha.7) i don't feel confident, considering i'm also completely new to this language

nixpare avatar Sep 21 '24 08:09 nixpare

Quality Gate Failed Quality Gate failed

Failed conditions
14.3% Duplication on New Code (required ≤ 3%)

See analysis details on SonarCloud

sonarqubecloud[bot] avatar Sep 21 '24 13:09 sonarqubecloud[bot]

@leaanthony I think I have addressed every issue I could do alone, now the majority of the remaining points are all linked to code that I have neither added nor modified. I hope to have been helpful!

nixpare avatar Sep 21 '24 13:09 nixpare

Regarding the free() comments by rabbit, it's desirable to free the memory in the same function as the allocation. Could we move those free's to the calling method that creates the C String?

leaanthony avatar Oct 10 '24 08:10 leaanthony

Hi @nixpare - Sorry to ask this: could you please fix the current merge conflict with this PR? Thank you 🙏

leaanthony avatar Oct 20 '24 02:10 leaanthony

@nixpare - do you still want this PR merged?

leaanthony avatar Nov 17 '24 09:11 leaanthony

@nixpare - I had a little dig in to this today as there's been a few other things that have been merged in and I found a number of issues which I'm wondering if they were part of a bad merge. The Bounds and SetBounds were not part of Window and the Panel appears to operate just like a normal WebView window.

If you could possibly have a little look over and see anything that appears out of the ordinary, then hopefully we can resolve it and get it merged. I've added a new menu option in the window example but I think a dedicated window panel example would be pretty cool.

leaanthony avatar Nov 30 '24 05:11 leaanthony

@nixpare - we may need to bump this to v3.1 if that's easier?

leaanthony avatar Dec 07 '24 10:12 leaanthony

Closing due to lack of feedback. This is something I'm keen to look at later on though, but we may need to take a different approach.

leaanthony avatar Aug 02 '25 03:08 leaanthony