[v3 feature] Add support for MacOS Panels (PR ready)
Is your feature request related to a problem? Please describe.
No response
Describe the solution you'd like
The idea is to have a component like WebviewWindow (i called it WebviewPanel) which automatically inherits every functionality of WebviewWindow and behaves like a floating window / overlay (depending on the OS).
Describe alternatives you've considered
I have found a solution which uses Go's struct embedding to extend WebviewWindow so that there is no need to touch the objective-c bindings or care about porting any change made on WebviewWindow to WebviewPanel. This is true also for the WindowOptions.
However my implementation, for now, supports only MacOS NSPanel.
My implementation was first created from version v3.0.0-alpha.6, and after the v3.0.0-alpha.7 new version, I have already made a merge with the new changes. The repo is at https://github.com/nixpare/wails/tree/v3-alpha-feature/mac-panel.
You can test a working example from my repo https://github.com/nixpare/wails-mac-panel, the PR version of wails is already vendored in the code, so just wails3 dev is needed.
Additional context
Important notes on changes i made:
application.Appkey bindings callback function now hasapplication.Windowas the argument and not*application.WebviewWindow- the Objective-C
WebviewWindowinterface, instead of extendingNSWindowdirectly, uses composition and now has a property for the reference to the window, which could be both aNSWindowor aNSPanel, so the keyboard events are now managed byWebviewResponder - the C bindings that bridges the Objective-C code to Go were moved in a separate file
Additional small bugs encountered and fixes:
- Even after a
Windowis closed, some events are sent to the channelwindowEvents, resulting in error logs printed in the console. I just have changed the log function to include the window event ID - When sending the key combination
ctrl+m, the first if statement in the Objective-C functionkeyStringFromEventreturn"enter", now the newWebviewResponderfirst interprets theevent.keyCodeand then as a special case theevent.charactersstring - When sending the key combination
ctrl+l, this combination never reaches the application runtime, both in the "old" and "new" versions
This sounds amazing and the changes seem reasonable. Feel free to open a PR and we can discuss details on that. Amazing work! π
PR opened! Let me know if I can be of any help in any way
This feature is actually very useful. When I was building macOS apps with Tauri, I found that almost every project relied on it. I really hope Wails can support it as well, as that would unlock a lot more possibilities for developers.
Yes, this has taken a backseat in priorities but not forgotten. I'm actually pretty excited about this and what more native UI we can introduce πππ
Sorry @ayangweb - we need to ensure that all the fundamentals are there and as soon as we get to API freeze then I'll look at updating this PR and trying to fix merge conflicts. We WILL get there I promise π
A current implementation of this feature is now in #6008.
It keeps NSWindow as the default and adds an opt-in NSPanel-backed WebviewWindow with panel preferences, non-activating focus behavior, shared lifecycle and keybinding paths, documentation, examples, and manual tests.
Thank you @nixpare for the original proposal and #3763βthe shared-window direction and panel use cases helped establish the design. I am leaving this issue open until #6008 merges; the PR is linked to close it automatically.