main.rs 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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, WebviewUrl, WebviewWindowBuilder};
  6. use tauri_utils::acl::{
  7. resolved::{CommandKey, ResolvedCommand},
  8. ExecutionContext,
  9. };
  10. fn main() {
  11. let mut context = tauri::generate_context!("../../examples/parent-window/tauri.conf.json");
  12. for cmd in [
  13. "plugin:event|listen",
  14. "plugin:webview|create_webview_window",
  15. "plugin:window|internal_on_mousemove",
  16. "plugin:window|internal_on_mousedown",
  17. ] {
  18. context.resolved_acl().allowed_commands.insert(
  19. CommandKey {
  20. name: cmd.into(),
  21. context: ExecutionContext::Local,
  22. },
  23. ResolvedCommand {
  24. windows: vec!["*".parse().unwrap()],
  25. ..Default::default()
  26. },
  27. );
  28. }
  29. tauri::Builder::default()
  30. .on_page_load(|webview, payload| {
  31. if payload.event() == PageLoadEvent::Finished {
  32. let label = webview.label().to_string();
  33. webview.listen("clicked".to_string(), move |_payload| {
  34. println!("got 'clicked' event on window '{label}'");
  35. });
  36. }
  37. })
  38. .setup(|app| {
  39. let _webview = WebviewWindowBuilder::new(app, "main", WebviewUrl::default())
  40. .title("Main")
  41. .inner_size(600.0, 400.0)
  42. .build()?;
  43. Ok(())
  44. })
  45. .run(context)
  46. .expect("failed to run tauri application");
  47. }