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>
This commit is contained in:
Amr Bashir
2024-02-01 13:06:27 +02:00
committed by GitHub
parent 7fcc0bcd34
commit a093682d2d
45 changed files with 2472 additions and 5836 deletions

View File

@@ -24,11 +24,10 @@
const container = document.getElementById('container')
function createWindowMessageBtn(label) {
const webview = WebviewWindow.getByLabel(label)
const button = document.createElement('button')
button.innerText = 'Send message to ' + label
button.addEventListener('click', function () {
webview.emit('clicked', 'message from ' + windowLabel)
appWindow.emitTo(label, 'clicked', 'message from ' + windowLabel)
})
container.appendChild(button)
}
@@ -67,7 +66,7 @@
globalMessageButton.innerHTML = 'Send global message'
globalMessageButton.addEventListener('click', function () {
// emit to all windows
window.__TAURI__.event.emit('clicked', 'message from ' + windowLabel)
appWindow.emit('clicked', 'message from ' + windowLabel)
})
container.appendChild(globalMessageButton)
@@ -82,4 +81,4 @@
</script>
</body>
</html>
</html>

View File

@@ -5,8 +5,30 @@
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
use tauri::{webview::PageLoadEvent, WebviewWindowBuilder};
use tauri_utils::acl::{
resolved::{CommandKey, ResolvedCommand},
ExecutionContext,
};
fn main() {
let mut context = tauri::generate_context!("../../examples/multiwindow/tauri.conf.json");
for cmd in [
"plugin:event|listen",
"plugin:event|emit",
"plugin:event|emit_to",
] {
context.resolved_acl().allowed_commands.insert(
CommandKey {
name: cmd.into(),
context: ExecutionContext::Local,
},
ResolvedCommand {
windows: vec!["*".parse().unwrap()],
..Default::default()
},
);
}
tauri::Builder::default()
.on_page_load(|webview, payload| {
if payload.event() == PageLoadEvent::Finished {
@@ -28,8 +50,6 @@ fn main() {
Ok(())
})
.run(tauri::generate_context!(
"../../examples/multiwindow/tauri.conf.json"
))
.run(context)
.expect("failed to run tauri application");
}