From 2b9891da2c2413ede2d0023583878c8cbc5de622 Mon Sep 17 00:00:00 2001 From: Fabio Massaioli Date: Wed, 20 Mar 2024 10:30:14 +0100 Subject: [PATCH] [v3] Update and fix runtime JS API (#3295) * Cleanup bundled runtime entry point * Fix JS representation of Screen struct * Expose IsFocused method in Window interface * Update JS window API * Fix cleanup of WML listeners * Bundle runtime as ES module * Update runtime dependencies * Update runtime types and events * Update bundled runtime * Update changelog --------- Co-authored-by: Lea Anthony --- mkdocs-website/docs/en/changelog.md | 14 +- v3/Taskfile.yaml | 8 +- v3/examples/binding/assets/index.html | 2 +- v3/examples/binding/assets/runtime.js | 1 - v3/examples/binding/go.mod | 53 - v3/examples/binding/go.sum | 191 - v3/examples/contextmenus/assets/index.html | 4 +- v3/examples/drag-n-drop/assets/index.html | 7 +- v3/examples/environment/assets/index.html | 7 +- v3/examples/events/assets/index.html | 7 +- v3/examples/frameless/assets/index.html | 2 +- v3/examples/frameless/go.mod | 51 - v3/examples/frameless/go.sum | 188 - v3/examples/oauth/assets/index.html | 10 +- v3/examples/plain/main.go | 2 +- v3/examples/plugins/assets/index.html | 3 +- v3/examples/screen/assets/index.html | 7 +- v3/examples/video/go.mod | 51 - v3/examples/video/go.sum | 191 - v3/examples/window-api/assets/index.html | 6 +- v3/examples/wml/assets/index.html | 4 +- .../assetserver/assets/runtime.debug.js | 1139 --- v3/internal/assetserver/assets/runtime.js | 1 - .../bundledassets/runtime.debug.js | 2476 +++--- .../assetserver/bundledassets/runtime.js | 2 +- v3/internal/runtime/Taskfile.yaml | 4 +- .../@wailsio/runtime/package-lock.json | 42 +- .../desktop/@wailsio/runtime/src/index.js | 77 +- .../desktop/@wailsio/runtime/src/log.js | 13 - .../desktop/@wailsio/runtime/src/screens.js | 10 +- .../desktop/@wailsio/runtime/src/utils.js | 86 + .../desktop/@wailsio/runtime/src/window.js | 896 +- .../desktop/@wailsio/runtime/src/wml.js | 311 +- .../@wailsio/runtime/types/contextmenu.d.ts | 1 + .../desktop/@wailsio/runtime/types/drag.d.ts | 1 + .../@wailsio/runtime/types/events.d.ts | 5 + .../desktop/@wailsio/runtime/types/index.d.ts | 4 +- .../@wailsio/runtime/types/runtime.d.ts | 1 + .../@wailsio/runtime/types/screens.d.ts | 6 +- .../@wailsio/runtime/types/system.d.ts | 48 +- .../desktop/@wailsio/runtime/types/utils.d.ts | 14 + .../@wailsio/runtime/types/window.d.ts | 534 +- .../desktop/@wailsio/runtime/types/wml.d.ts | 6 + v3/internal/runtime/desktop/compiled/main.js | 90 +- v3/internal/runtime/package-lock.json | 7312 ++++++----------- v3/internal/runtime/package.json | 12 +- v3/pkg/application/application.go | 3 +- v3/pkg/application/assets/alpha/index.html | 6 +- v3/pkg/application/messageprocessor_window.go | 449 +- v3/pkg/application/window.go | 1 + v3/pkg/events/events.go | 673 +- v3/plugins/experimental/server/window.go | 4 + 52 files changed, 5956 insertions(+), 9080 deletions(-) delete mode 100644 v3/examples/binding/assets/runtime.js delete mode 100644 v3/examples/binding/go.mod delete mode 100644 v3/examples/binding/go.sum delete mode 100644 v3/examples/frameless/go.mod delete mode 100644 v3/examples/frameless/go.sum delete mode 100644 v3/examples/video/go.mod delete mode 100644 v3/examples/video/go.sum delete mode 100644 v3/internal/assetserver/assets/runtime.debug.js delete mode 100644 v3/internal/assetserver/assets/runtime.js delete mode 100644 v3/internal/runtime/desktop/@wailsio/runtime/src/log.js create mode 100644 v3/internal/runtime/desktop/@wailsio/runtime/src/utils.js create mode 100644 v3/internal/runtime/desktop/@wailsio/runtime/types/contextmenu.d.ts create mode 100644 v3/internal/runtime/desktop/@wailsio/runtime/types/drag.d.ts create mode 100644 v3/internal/runtime/desktop/@wailsio/runtime/types/utils.d.ts diff --git a/mkdocs-website/docs/en/changelog.md b/mkdocs-website/docs/en/changelog.md index c60ceb0d1..07a30e126 100644 --- a/mkdocs-website/docs/en/changelog.md +++ b/mkdocs-website/docs/en/changelog.md @@ -23,10 +23,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - [darwin] add option for showing the toolbar in fullscreen mode on macOS by [@fbbdev](https://github.com/fbbdev) in [#3282](https://github.com/wailsapp/wails/pull/3282) - [linux] add onKeyPress logic to convert linux keypress into an accelerator @[Atterpac](https://github.com/Atterpac) in[#3022](https://github.com/wailsapp/wails/pull/3022]) - [linux] add task `run:linux` by [@marcus-crane](https://github.com/marcus-crane) in [#3146](https://github.com/wailsapp/wails/pull/3146) -- export `SetIcon` method by @almas1992 in [PR](https://github.com/wailsapp/wails/pull/3147) +- Export `SetIcon` method by @almas1992 in [PR](https://github.com/wailsapp/wails/pull/3147) - Improve `OnShutdown` by @almas1992 in [PR](https://github.com/wailsapp/wails/pull/3189) -- restore `ToggleMaximise` method in `Window` interface by [@fbbdev](https://github.com/fbbdev) in [#3281](https://github.com/wailsapp/wails/pull/3281) +- Restore `ToggleMaximise` method in `Window` interface by [@fbbdev](https://github.com/fbbdev) in [#3281](https://github.com/wailsapp/wails/pull/3281) - Added more information to `Environment()`. By @leaanthony in [aba82cc](https://github.com/wailsapp/wails/commit/aba82cc52787c97fb99afa58b8b63a0004b7ff6c) based on [PR](https://github.com/wailsapp/wails/pull/2044) by @Mai-Lapyst +- Expose the `WebviewWindow.IsFocused` method on the `Window` interface by [@fbbdev](https://github.com/fbbdev) in [#3295](https://github.com/wailsapp/wails/pull/3295) +- Support multiple space-separated trigger events in the WML system by [@fbbdev](https://github.com/fbbdev) in [#3295](https://github.com/wailsapp/wails/pull/3295) +- Add ESM exports from the bundled JS runtime script by [@fbbdev](https://github.com/fbbdev) in [#3295](https://github.com/wailsapp/wails/pull/3295) ### Fixed @@ -46,9 +49,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Fix wrong baseURL when open window twice by @5aaee9 in PR [#3273](https://github.com/wailsapp/wails/pull/3273) - Fix ordering of if branches in `WebviewWindow.Restore` method by [@fbbdev](https://github.com/fbbdev) in [#3279](https://github.com/wailsapp/wails/pull/3279) - Correctly compute `startURL` across multiple `GetStartURL` invocations when `FRONTEND_DEVSERVER_URL` is present. [#3299](https://github.com/wailsapp/wails/pull/3299) +- Fix the JS type of the `Screen` struct to match its Go counterpart by [@fbbdev](https://github.com/fbbdev) in [#3295](https://github.com/wailsapp/wails/pull/3295) +- Fix the `WML.Reload` method to ensure proper cleanup of registered event listeners by [@fbbdev](https://github.com/fbbdev) in [#3295](https://github.com/wailsapp/wails/pull/3295) ### Changed +- The bundled JS runtime script is now an ESM module: script tags importing it must have the `type="module"` attribute. By [@fbbdev](https://github.com/fbbdev) in [#3295](https://github.com/wailsapp/wails/pull/3295) +- The `@wailsio/runtime` package does not publish its API on the `window.wails` object, and does not start the WML system. This has been done to improve encapsulation. The WML system can be started manually if desired by calling the new `WML.Enable` method. The bundled JS runtime script still performs both operations automatically. By [@fbbdev](https://github.com/fbbdev) in [#3295](https://github.com/wailsapp/wails/pull/3295) +- The Window API module `@wailsio/runtime/src/window` now exposes the containing window object as a default export. It is not possible anymore to import individual methods through ESM named or namespace import syntax. +- The JS window API has been updated to match the current Go `WebviewWindow` API. Some methods have changed name or prototype, specifically: `Screen` becomes `GetScreen`; `GetZoomLevel`/`SetZoomLevel` become `GetZoom`/`SetZoom`; `GetZoom`, `Width` and `Height` now return values directly instead of wrapping them within objects. By [@fbbdev](https://github.com/fbbdev) in [#3295](https://github.com/wailsapp/wails/pull/3295) + ### Removed ### Deprecated diff --git a/v3/Taskfile.yaml b/v3/Taskfile.yaml index 9a3075054..92ada83f9 100644 --- a/v3/Taskfile.yaml +++ b/v3/Taskfile.yaml @@ -152,15 +152,21 @@ tasks: drag-n-drop events frameless + hide-window keybindings menu + oauth plain screen + server + show-macos-toolbar systray + video window + window-api wml cmds: - for: { var: EXAMPLEDIRS } task: test:example vars: - DIR: "{{.ITEM}}" \ No newline at end of file + DIR: "{{.ITEM}}" diff --git a/v3/examples/binding/assets/index.html b/v3/examples/binding/assets/index.html index 86ec24e48..7d109b0d3 100644 --- a/v3/examples/binding/assets/index.html +++ b/v3/examples/binding/assets/index.html @@ -80,7 +80,7 @@ - + +

Context Menu Demo

@@ -62,4 +62,4 @@ - \ No newline at end of file + diff --git a/v3/examples/drag-n-drop/assets/index.html b/v3/examples/drag-n-drop/assets/index.html index a1bae6db5..f1e5595ca 100644 --- a/v3/examples/drag-n-drop/assets/index.html +++ b/v3/examples/drag-n-drop/assets/index.html @@ -4,7 +4,6 @@ Title -

Drag-n-drop Demo

@@ -13,7 +12,9 @@ Drop Files onto this window...
- - \ No newline at end of file + diff --git a/v3/examples/environment/assets/index.html b/v3/examples/environment/assets/index.html index 790dd4ff2..2be201ce9 100644 --- a/v3/examples/environment/assets/index.html +++ b/v3/examples/environment/assets/index.html @@ -33,11 +33,12 @@ } - - - \ No newline at end of file + diff --git a/v3/examples/events/assets/index.html b/v3/examples/events/assets/index.html index a1f8f6e24..7514415da 100644 --- a/v3/examples/events/assets/index.html +++ b/v3/examples/events/assets/index.html @@ -3,7 +3,6 @@ Title - @@ -14,11 +13,13 @@ To send an event from this window, click here: