2024-03-01 14:29:01 +03:00
|
|
|
// Copyright 2019-2024 Tauri Programme within The Commons Conservancy
|
2022-03-23 19:30:44 +03:00
|
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
|
2023-02-18 22:23:09 +03:00
|
|
|
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
|
2022-03-23 19:30:44 +03:00
|
|
|
|
2024-01-31 19:59:14 +03:00
|
|
|
use tauri::{webview::PageLoadEvent, WebviewUrl, WebviewWindowBuilder};
|
2024-02-19 17:13:36 +03:00
|
|
|
use tauri_utils::acl::ExecutionContext;
|
2022-03-23 19:30:44 +03:00
|
|
|
|
|
|
|
fn main() {
|
2024-01-31 19:59:14 +03:00
|
|
|
let mut context = tauri::generate_context!("../../examples/parent-window/tauri.conf.json");
|
|
|
|
for cmd in [
|
|
|
|
"plugin:event|listen",
|
|
|
|
"plugin:webview|create_webview_window",
|
|
|
|
] {
|
2024-02-19 17:13:36 +03:00
|
|
|
context
|
|
|
|
.runtime_authority_mut()
|
|
|
|
.__allow_command(cmd.to_string(), ExecutionContext::Local);
|
2024-01-31 19:59:14 +03:00
|
|
|
}
|
|
|
|
|
2022-03-23 19:30:44 +03:00
|
|
|
tauri::Builder::default()
|
2024-01-24 17:05:18 +03:00
|
|
|
.on_page_load(|webview, payload| {
|
2023-10-27 16:00:59 +03:00
|
|
|
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| {
|
2023-10-27 16:00:59 +03:00
|
|
|
println!("got 'clicked' event on window '{label}'");
|
|
|
|
});
|
|
|
|
}
|
2022-03-23 19:30:44 +03:00
|
|
|
})
|
2022-03-31 20:50:33 +03:00
|
|
|
.setup(|app| {
|
2024-01-24 17:05:18 +03:00
|
|
|
let _webview = WebviewWindowBuilder::new(app, "main", WebviewUrl::default())
|
2022-03-31 20:50:33 +03:00
|
|
|
.title("Main")
|
|
|
|
.inner_size(600.0, 400.0)
|
|
|
|
.build()?;
|
2024-01-24 17:05:18 +03:00
|
|
|
|
2022-03-31 20:50:33 +03:00
|
|
|
Ok(())
|
2022-05-06 02:57:32 +03:00
|
|
|
})
|
2024-01-31 19:59:14 +03:00
|
|
|
.run(context)
|
2022-03-23 19:30:44 +03:00
|
|
|
.expect("failed to run tauri application");
|
|
|
|
}
|