tauri/examples/multiwindow/main.rs

46 lines
1.3 KiB
Rust
Raw Normal View History

// Copyright 2019-2024 Tauri Programme within The Commons Conservancy
feat(license): SPDX Headers (#1449) * chore(licenses): api Signed-off-by: Daniel Thompson-Yvetot <denjell@mailscript.com> * chore(licenses): scripts Signed-off-by: Daniel Thompson-Yvetot <denjell@mailscript.com> * chore(license): cli/core Signed-off-by: Daniel Thompson-Yvetot <denjell@mailscript.com> * chore(license): cli/tauri-bundler Signed-off-by: Daniel Thompson-Yvetot <denjell@mailscript.com> * chore(license): workflows Signed-off-by: Daniel Thompson-Yvetot <denjell@mailscript.com> * chore(license): require license_template in rust Signed-off-by: Daniel Thompson-Yvetot <denjell@mailscript.com> * chore(license): core/tauri Signed-off-by: Daniel Thompson-Yvetot <denjell@mailscript.com> * chore(license): core/tauri-api Signed-off-by: Daniel Thompson-Yvetot <denjell@mailscript.com> * chore(license): core/tauri-build Signed-off-by: Daniel Thompson-Yvetot <denjell@mailscript.com> * chore(license): core/tauri-codegen Signed-off-by: Daniel Thompson-Yvetot <denjell@mailscript.com> * chore(license): core/tauri-macros Signed-off-by: Daniel Thompson-Yvetot <denjell@mailscript.com> * chore(license): core/tauri-updater Signed-off-by: Daniel Thompson-Yvetot <denjell@mailscript.com> * chore(license): core/tauri-utils Signed-off-by: Daniel Thompson-Yvetot <denjell@mailscript.com> * chore(license): examples Signed-off-by: Daniel Thompson-Yvetot <denjell@mailscript.com> * chore(license): cli/tauri.js Signed-off-by: Daniel Thompson-Yvetot <denjell@mailscript.com> * chore(license): changefile Signed-off-by: Daniel Thompson-Yvetot <denjell@mailscript.com> * chore(license): place both licenses in root Signed-off-by: Daniel Thompson-Yvetot <denjell@mailscript.com> * chore(license): package.json SPDX Signed-off-by: Daniel Thompson-Yvetot <denjell@mailscript.com> * chore(license): SPDX everywhere Signed-off-by: Daniel Thompson-Yvetot <denjell@mailscript.com> * fix(tauri.js): tests more time for ubuntu Signed-off-by: Daniel Thompson-Yvetot <denjell@mailscript.com> * chore(license): commons conservancy language Signed-off-by: Daniel Thompson-Yvetot <denjell@mailscript.com> * chore(license): add spdx file Signed-off-by: Daniel Thompson-Yvetot <denjell@mailscript.com> * fix(license): clippy Signed-off-by: Daniel Thompson-Yvetot <denjell@mailscript.com> * chore(license): language Signed-off-by: Daniel Thompson-Yvetot <denjell@mailscript.com>
2021-04-11 01:09:09 +03:00
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: MIT
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
use tauri::{webview::PageLoadEvent, Listener, WebviewWindowBuilder};
use tauri_utils::acl::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
.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| {
#[allow(unused_mut)]
2024-01-24 17:05:18 +03:00
let mut builder =
WebviewWindowBuilder::new(app, "Rust", tauri::WebviewUrl::App("index.html".into()));
#[cfg(target_os = "macos")]
{
builder = builder.tabbing_identifier("Rust");
}
2024-01-24 17:05:18 +03:00
let _webview = builder.title("Tauri - Rust").build()?;
Ok(())
})
.run(context)
.expect("failed to run tauri application");
}