tauri/examples/parent-window/main.rs

41 lines
1.2 KiB
Rust
Raw Normal View History

// Copyright 2019-2024 Tauri Programme within The Commons Conservancy
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: MIT
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
use tauri::{webview::PageLoadEvent, WebviewUrl, WebviewWindowBuilder};
use tauri_utils::acl::ExecutionContext;
fn main() {
let mut context = tauri::generate_context!("../../examples/parent-window/tauri.conf.json");
for cmd in [
"plugin:event|listen",
"plugin:webview|create_webview_window",
] {
context
.runtime_authority_mut()
.__allow_command(cmd.to_string(), ExecutionContext::Local);
}
tauri::Builder::default()
2024-01-24 17:05:18 +03:00
.on_page_load(|webview, payload| {
if payload.event() == PageLoadEvent::Finished {
2024-01-24 17:05:18 +03:00
let label = webview.label().to_string();
webview.listen("clicked".to_string(), move |_payload| {
println!("got 'clicked' event on window '{label}'");
});
}
})
.setup(|app| {
2024-01-24 17:05:18 +03:00
let _webview = WebviewWindowBuilder::new(app, "main", WebviewUrl::default())
.title("Main")
.inner_size(600.0, 400.0)
.build()?;
2024-01-24 17:05:18 +03:00
Ok(())
})
.run(context)
.expect("failed to run tauri application");
}