main.rs 956 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. // Copyright 2019-2021 Tauri Programme within The Commons Conservancy
  2. // SPDX-License-Identifier: Apache-2.0
  3. // SPDX-License-Identifier: MIT
  4. #![cfg_attr(
  5. all(not(debug_assertions), target_os = "windows"),
  6. windows_subsystem = "windows"
  7. )]
  8. mod cmd;
  9. use serde::Serialize;
  10. #[derive(Serialize)]
  11. struct Reply {
  12. data: String,
  13. }
  14. fn main() {
  15. tauri::Builder::default()
  16. .on_page_load(|window, _| {
  17. let window_ = window.clone();
  18. window.listen("js-event", move |event| {
  19. println!("got js-event with message '{:?}'", event.payload());
  20. let reply = Reply {
  21. data: "something else".to_string(),
  22. };
  23. window_
  24. .emit("rust-event", Some(reply))
  25. .expect("failed to emit");
  26. });
  27. })
  28. .invoke_handler(tauri::generate_handler![
  29. cmd::log_operation,
  30. cmd::perform_request
  31. ])
  32. .run(tauri::generate_context!())
  33. .expect("error while running tauri application");
  34. }