2024-03-01 14:29:01 +03:00
|
|
|
// Copyright 2019-2024 Tauri Programme within The Commons Conservancy
|
2021-04-11 01:09:09 +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")]
|
2021-02-12 03:50:39 +03:00
|
|
|
|
2024-07-12 15:01:40 +03:00
|
|
|
use tauri::{webview::PageLoadEvent, Listener, WebviewWindowBuilder};
|
2024-02-19 17:13:36 +03:00
|
|
|
use tauri_utils::acl::ExecutionContext;
|
2021-02-17 17:15:04 +03:00
|
|
|
|
2021-02-12 03:50:39 +03:00
|
|
|
fn main() {
|
2024-02-01 14:06:27 +03:00
|
|
|
let mut context = tauri::generate_context!("../../examples/multiwindow/tauri.conf.json");
|
|
|
|
for cmd in [
|
|
|
|
"plugin:event|listen",
|
|
|
|
"plugin:event|emit",
|
|
|
|
"plugin:event|emit_to",
|
|
|
|
] {
|
2024-02-19 17:13:36 +03:00
|
|
|
context
|
|
|
|
.runtime_authority_mut()
|
|
|
|
.__allow_command(cmd.to_string(), ExecutionContext::Local);
|
2024-02-01 14:06:27 +03:00
|
|
|
}
|
|
|
|
|
2021-04-06 23:50:53 +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}'");
|
|
|
|
});
|
|
|
|
}
|
2021-02-12 03:50:39 +03:00
|
|
|
})
|
2022-03-31 20:50:33 +03:00
|
|
|
.setup(|app| {
|
2022-10-19 15:20:17 +03:00
|
|
|
#[allow(unused_mut)]
|
2024-01-24 17:05:18 +03:00
|
|
|
let mut builder =
|
|
|
|
WebviewWindowBuilder::new(app, "Rust", tauri::WebviewUrl::App("index.html".into()));
|
2022-10-19 15:20:17 +03:00
|
|
|
#[cfg(target_os = "macos")]
|
|
|
|
{
|
|
|
|
builder = builder.tabbing_identifier("Rust");
|
|
|
|
}
|
2024-01-24 17:05:18 +03:00
|
|
|
let _webview = builder.title("Tauri - Rust").build()?;
|
|
|
|
|
2022-03-31 20:50:33 +03:00
|
|
|
Ok(())
|
|
|
|
})
|
2024-02-01 14:06:27 +03:00
|
|
|
.run(context)
|
2021-04-04 03:41:04 +03:00
|
|
|
.expect("failed to run tauri application");
|
2021-02-12 03:50:39 +03:00
|
|
|
}
|