main.rs 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  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, WebviewUrl, WebviewWindowBuilder};
  6. use tauri_utils::acl::ExecutionContext;
  7. fn main() {
  8. let mut context = tauri::generate_context!("../../examples/parent-window/tauri.conf.json");
  9. for cmd in [
  10. "plugin:event|listen",
  11. "plugin:webview|create_webview_window",
  12. ] {
  13. context
  14. .runtime_authority_mut()
  15. .__allow_command(cmd.to_string(), ExecutionContext::Local);
  16. }
  17. tauri::Builder::default()
  18. .on_page_load(|webview, payload| {
  19. if payload.event() == PageLoadEvent::Finished {
  20. let label = webview.label().to_string();
  21. webview.listen("clicked".to_string(), move |_payload| {
  22. println!("got 'clicked' event on window '{label}'");
  23. });
  24. }
  25. })
  26. .setup(|app| {
  27. let _webview = WebviewWindowBuilder::new(app, "main", WebviewUrl::default())
  28. .title("Main")
  29. .inner_size(600.0, 400.0)
  30. .build()?;
  31. Ok(())
  32. })
  33. .run(context)
  34. .expect("failed to run tauri application");
  35. }