main.rs 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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. fn main() {
  6. use tauri::{
  7. api::process::{Command, CommandEvent},
  8. Manager,
  9. };
  10. tauri::Builder::default()
  11. .setup(move |app| {
  12. let window = app.get_window("main").unwrap();
  13. let script_path = app
  14. .path_resolver()
  15. .resolve_resource("assets/index.js")
  16. .unwrap()
  17. .to_string_lossy()
  18. .to_string();
  19. tauri::async_runtime::spawn(async move {
  20. let (mut rx, _child) = Command::new("node")
  21. .args(&[script_path])
  22. .spawn()
  23. .expect("Failed to spawn node");
  24. #[allow(clippy::collapsible_match)]
  25. while let Some(event) = rx.recv().await {
  26. if let CommandEvent::Stdout(line) = event {
  27. window
  28. .emit("message", Some(format!("'{}'", line)))
  29. .expect("failed to emit event");
  30. }
  31. }
  32. });
  33. Ok(())
  34. })
  35. .run(tauri::tauri_build_context!())
  36. .expect("error while running tauri application");
  37. }