main.rs 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. // Copyright 2019-2023 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::{
  7. resolved::{CommandKey, ResolvedCommand},
  8. ExecutionContext,
  9. };
  10. fn main() {
  11. let mut context = tauri::generate_context!("../../examples/multiwindow/tauri.conf.json");
  12. for cmd in [
  13. "plugin:event|listen",
  14. "plugin:event|emit",
  15. "plugin:event|emit_to",
  16. ] {
  17. context.resolved_acl().allowed_commands.insert(
  18. CommandKey {
  19. name: cmd.into(),
  20. context: ExecutionContext::Local,
  21. },
  22. ResolvedCommand {
  23. windows: vec!["*".parse().unwrap()],
  24. ..Default::default()
  25. },
  26. );
  27. }
  28. tauri::Builder::default()
  29. .on_page_load(|webview, payload| {
  30. if payload.event() == PageLoadEvent::Finished {
  31. let label = webview.label().to_string();
  32. webview.listen("clicked".to_string(), move |_payload| {
  33. println!("got 'clicked' event on window '{label}'");
  34. });
  35. }
  36. })
  37. .setup(|app| {
  38. #[allow(unused_mut)]
  39. let mut builder =
  40. WebviewWindowBuilder::new(app, "Rust", tauri::WebviewUrl::App("index.html".into()));
  41. #[cfg(target_os = "macos")]
  42. {
  43. builder = builder.tabbing_identifier("Rust");
  44. }
  45. let _webview = builder.title("Tauri - Rust").build()?;
  46. Ok(())
  47. })
  48. .run(context)
  49. .expect("failed to run tauri application");
  50. }