Skip to content

Commit a093682

Browse files
amrbashirlucasfernoglucasfernog-crabnebula
authored
refactor(core): refactor and fix event system following multiwebview 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>
1 parent 7fcc0bc commit a093682

File tree

45 files changed

+2277
-5641
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+2277
-5641
lines changed

.changes/api-emit-to.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@tauri-apps/api': 'patch:feat'
3+
---
4+
5+
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.
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
"@tauri-apps/api": patch:breaking
2+
'@tauri-apps/api': patch:breaking
33
---
44

5-
Removed event callback's `windowLabel` field and added a `windowSource` object instead.
5+
Removed event callback's `windowLabel`.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'tauri': 'patch:bug'
3+
---
4+
5+
Fix can not prevent closing a window from another webview.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
'tauri': 'patch:breaking'
3+
---
4+
5+
Refactored the event system to better accommodate the new window types:
6+
7+
- Added `EventTarget` enum.
8+
- Added `App/AppHandle::listen`, `App/AppHandle::once` and `App/AppHandle::unlisten` to listen to events targeting `App/AppHandle`
9+
- `App/AppHandle/Window/Webview/WebviewWindow::emit` will now emit to all event listeners.
10+
- `App/AppHandle/Window/Webview/WebviewWindow::emit_to` will emit to event targets that match the given label, see `EventTarget` enum.
11+
- `App/AppHandle/Window/Webview/WebviewWindow::emit_filter` will emit to event targets based on a filter callback which now takes `&EventTarget` instead of `&Window`.
12+
- 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).
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'tauri-utils': 'patch:breaking'
3+
---
4+
5+
Changed `error` field in `ConfigError::FormatToml` to be boxed `Box<toml::de::Error>` to reduce the enum `ConfigError` size in memory.

core/tauri-runtime-wry/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2902,7 +2902,7 @@ fn handle_event_loop<T: UserEvent>(
29022902
if window.is_window_transparent {
29032903
if let Some(surface) = &mut window.surface {
29042904
if let Some(window) = &window.inner {
2905-
clear_window_surface(&window, surface)
2905+
clear_window_surface(window, surface)
29062906
}
29072907
}
29082908
}

core/tauri-utils/src/config/parse.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ pub enum ConfigError {
108108
path: PathBuf,
109109

110110
/// The parsing [`toml::Error`].
111-
error: ::toml::de::Error,
111+
error: Box<::toml::de::Error>,
112112
},
113113

114114
/// Unknown config file name encountered.
@@ -381,7 +381,7 @@ fn do_parse_json5<D: DeserializeOwned>(raw: &str, path: &Path) -> Result<D, Conf
381381
fn do_parse_toml<D: DeserializeOwned>(raw: &str, path: &Path) -> Result<D, ConfigError> {
382382
::toml::from_str(raw).map_err(|error| ConfigError::FormatToml {
383383
path: path.into(),
384-
error,
384+
error: Box::new(error),
385385
})
386386
}
387387

core/tauri/build.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,12 @@ const PLUGINS: &[(&str, &[(&str, bool)])] = &[
3232
),
3333
(
3434
"event",
35-
&[("listen", true), ("unlisten", true), ("emit", true)],
35+
&[
36+
("listen", true),
37+
("unlisten", true),
38+
("emit", true),
39+
("emit_to", true),
40+
],
3641
),
3742
(
3843
"window",

0 commit comments

Comments
 (0)