main.rs 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. // Copyright 2019-2024 Tauri Programme within The Commons Conservancy
  2. // SPDX-License-Identifier: Apache-2.0
  3. // SPDX-License-Identifier: MIT
  4. #![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
  5. use tauri::{webview::PageLoadEvent, WebviewWindowBuilder};
  6. use tauri_utils::acl::ExecutionContext;
  7. fn main() {
  8. let mut context = tauri::generate_context!("../../examples/multiwindow/tauri.conf.json");
  9. for cmd in [
  10. "plugin:event|listen",
  11. "plugin:event|emit",
  12. "plugin:event|emit_to",
  13. ] {
  14. context
  15. .runtime_authority_mut()
  16. .__allow_command(cmd.to_string(), ExecutionContext::Local);
  17. }
  18. tauri::Builder::default()
  19. .on_page_load(|webview, payload| {
  20. if payload.event() == PageLoadEvent::Finished {
  21. let label = webview.label().to_string();
  22. webview.listen("clicked".to_string(), move |_payload| {
  23. println!("got 'clicked' event on window '{label}'");
  24. });
  25. }
  26. })
  27. .setup(|app| {
  28. #[allow(unused_mut)]
  29. let mut builder =
  30. WebviewWindowBuilder::new(app, "Rust", tauri::WebviewUrl::App("index.html".into()));
  31. #[cfg(target_os = "macos")]
  32. {
  33. builder = builder.tabbing_identifier("Rust");
  34. }
  35. let _webview = builder.title("Tauri - Rust").build()?;
  36. Ok(())
  37. })
  38. .run(context)
  39. .expect("failed to run tauri application");
  40. }