webdriver.rs 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. // Copyright 2019-2024 Tauri Programme within The Commons Conservancy
  2. // SPDX-License-Identifier: Apache-2.0
  3. // SPDX-License-Identifier: MIT
  4. use crate::cli::Args;
  5. use std::{env::current_dir, process::Command};
  6. // the name of the binary to find in $PATH
  7. #[cfg(target_os = "linux")]
  8. const DRIVER_BINARY: &str = "WebKitWebDriver";
  9. #[cfg(target_os = "windows")]
  10. const DRIVER_BINARY: &str = "msedgedriver.exe";
  11. /// Find the native driver binary in the PATH, or exits the process with an error.
  12. pub fn native(args: &Args) -> Command {
  13. let native_binary = match args.native_driver.as_deref() {
  14. Some(custom) => {
  15. if custom.exists() {
  16. custom.to_owned()
  17. } else {
  18. eprintln!(
  19. "can not find the supplied binary path {}. This is currently required.",
  20. custom.display()
  21. );
  22. match current_dir() {
  23. Ok(cwd) => eprintln!("current working directory: {}", cwd.display()),
  24. Err(error) => eprintln!("can not find current working directory: {}", error),
  25. }
  26. std::process::exit(1);
  27. }
  28. }
  29. None => match which::which(DRIVER_BINARY) {
  30. Ok(binary) => binary,
  31. Err(error) => {
  32. eprintln!(
  33. "can not find binary {} in the PATH. This is currently required.\
  34. You can also pass a custom path with --native-driver",
  35. DRIVER_BINARY
  36. );
  37. eprintln!("{:?}", error);
  38. std::process::exit(1);
  39. }
  40. },
  41. };
  42. let mut cmd = Command::new(native_binary);
  43. cmd.env("TAURI_AUTOMATION", "true"); // 1.x
  44. cmd.env("TAURI_WEBVIEW_AUTOMATION", "true"); // 2.x
  45. cmd.arg(format!("--port={}", args.native_port));
  46. cmd.arg(format!("--host={}", args.native_host));
  47. cmd
  48. }