Skip to content

Commit

Permalink
refactor(core): refactor and fix event system following multiwebview …
Browse files Browse the repository at this point in the history
…support (#8621)

* clippy

* refactor(core): refactor and fix event system following multiwebview support

* update documentation

* update js docs

* lint

* clippy

* update multiwindow example [skip ci]

* enhance event tests

* fix example

* Update .changes/tauri-event-after-multiwebview.md

Co-authored-by: Lucas Nogueira <118899497+lucasfernog-crabnebula@users.noreply.github.com>

* fix tests

* add diagram

* Add `App/AppHandle` even target

* Discard changes to examples/api/src-tauri/tauri-plugin-sample/permissions/schemas/schema.json

* revert accidental changes

* regenerate schemas

* fix doctests

* add helper methods

* update docs

* update api

* update docs [skip ci]

* update docs [skip ci]

---------

Co-authored-by: Lucas Nogueira <lucas@tauri.app>
Co-authored-by: Lucas Nogueira <118899497+lucasfernog-crabnebula@users.noreply.github.com>
  • Loading branch information
3 people authored Feb 1, 2024
1 parent 7fcc0bc commit a093682
Show file tree
Hide file tree
Showing 45 changed files with 2,277 additions and 5,641 deletions.
5 changes: 5 additions & 0 deletions .changes/api-emit-to.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@tauri-apps/api': 'patch:feat'
---

Added `emitTo` api to `event` module which is equivalent to the rust `emit_to` method. Also added `emitTo` method on `Window`, `Webivew` and `WebviewWindow` classes.
4 changes: 2 additions & 2 deletions .changes/api-event-resource-refactor.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
"@tauri-apps/api": patch:breaking
'@tauri-apps/api': patch:breaking
---

Removed event callback's `windowLabel` field and added a `windowSource` object instead.
Removed event callback's `windowLabel`.
5 changes: 5 additions & 0 deletions .changes/tauri-close-requested-another-webview.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'tauri': 'patch:bug'
---

Fix can not prevent closing a window from another webview.
12 changes: 12 additions & 0 deletions .changes/tauri-event-after-multiwebview.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
'tauri': 'patch:breaking'
---

Refactored the event system to better accommodate the new window types:

- Added `EventTarget` enum.
- Added `App/AppHandle::listen`, `App/AppHandle::once` and `App/AppHandle::unlisten` to listen to events targeting `App/AppHandle`
- `App/AppHandle/Window/Webview/WebviewWindow::emit` will now emit to all event listeners.
- `App/AppHandle/Window/Webview/WebviewWindow::emit_to` will emit to event targets that match the given label, see `EventTarget` enum.
- `App/AppHandle/Window/Webview/WebviewWindow::emit_filter` will emit to event targets based on a filter callback which now takes `&EventTarget` instead of `&Window`.
- Renamed `Manager::listen_global` and `Manager::once_global` to `listen_any` and `once_any` respectively to be consistent with `EventTarget::Any`, it will now also listen to any event to any target (aka event sniffer).
5 changes: 5 additions & 0 deletions .changes/tauri-utils-config-error-box.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'tauri-utils': 'patch:breaking'
---

Changed `error` field in `ConfigError::FormatToml` to be boxed `Box<toml::de::Error>` to reduce the enum `ConfigError` size in memory.
2 changes: 1 addition & 1 deletion core/tauri-runtime-wry/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2902,7 +2902,7 @@ fn handle_event_loop<T: UserEvent>(
if window.is_window_transparent {
if let Some(surface) = &mut window.surface {
if let Some(window) = &window.inner {
clear_window_surface(&window, surface)
clear_window_surface(window, surface)
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions core/tauri-utils/src/config/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ pub enum ConfigError {
path: PathBuf,

/// The parsing [`toml::Error`].
error: ::toml::de::Error,
error: Box<::toml::de::Error>,
},

/// Unknown config file name encountered.
Expand Down Expand Up @@ -381,7 +381,7 @@ fn do_parse_json5<D: DeserializeOwned>(raw: &str, path: &Path) -> Result<D, Conf
fn do_parse_toml<D: DeserializeOwned>(raw: &str, path: &Path) -> Result<D, ConfigError> {
::toml::from_str(raw).map_err(|error| ConfigError::FormatToml {
path: path.into(),
error,
error: Box::new(error),
})
}

Expand Down
7 changes: 6 additions & 1 deletion core/tauri/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,12 @@ const PLUGINS: &[(&str, &[(&str, bool)])] = &[
),
(
"event",
&[("listen", true), ("unlisten", true), ("emit", true)],
&[
("listen", true),
("unlisten", true),
("emit", true),
("emit_to", true),
],
),
(
"window",
Expand Down
Loading

0 comments on commit a093682

Please sign in to comment.