operating_system.rs 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. // Copyright 2019-2021 Tauri Programme within The Commons Conservancy
  2. // SPDX-License-Identifier: Apache-2.0
  3. // SPDX-License-Identifier: MIT
  4. use super::InvokeResponse;
  5. use serde::Deserialize;
  6. /// The API descriptor.
  7. #[derive(Deserialize)]
  8. #[serde(tag = "cmd", rename_all = "camelCase")]
  9. pub enum Cmd {
  10. Platform,
  11. Version,
  12. Type,
  13. Arch,
  14. Tempdir,
  15. }
  16. impl Cmd {
  17. #[allow(unused_variables)]
  18. pub fn run(self) -> crate::Result<InvokeResponse> {
  19. #[cfg(os_all)]
  20. return match self {
  21. Self::Platform => Ok(std::env::consts::OS.into()),
  22. Self::Version => Ok(os_info::get().version().to_string().into()),
  23. Self::Type => {
  24. #[cfg(target_os = "linux")]
  25. return Ok("Linux".into());
  26. #[cfg(target_os = "windows")]
  27. return Ok("Windows_NT".into());
  28. #[cfg(target_os = "macos")]
  29. return Ok("Darwing".into());
  30. }
  31. Self::Arch => Ok(std::env::consts::ARCH.into()),
  32. Self::Tempdir => Ok(std::env::temp_dir().into()),
  33. };
  34. #[cfg(not(os_all))]
  35. Err(crate::Error::ApiNotAllowlisted("os".into()))
  36. }
  37. }