app.rs 985 B

123456789101112131415161718192021222324252627282930313233343536
  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::InvokeContext;
  5. use crate::Runtime;
  6. use serde::Deserialize;
  7. use tauri_macros::{command_enum, CommandModule};
  8. /// The API descriptor.
  9. #[command_enum]
  10. #[derive(Deserialize, CommandModule)]
  11. #[serde(tag = "cmd", rename_all = "camelCase")]
  12. #[allow(clippy::enum_variant_names)]
  13. pub enum Cmd {
  14. /// Get Application Version
  15. GetAppVersion,
  16. /// Get Application Name
  17. GetAppName,
  18. /// Get Tauri Version
  19. GetTauriVersion,
  20. }
  21. impl Cmd {
  22. fn get_app_version<R: Runtime>(context: InvokeContext<R>) -> super::Result<String> {
  23. Ok(context.package_info.version.to_string())
  24. }
  25. fn get_app_name<R: Runtime>(context: InvokeContext<R>) -> super::Result<String> {
  26. Ok(context.package_info.name)
  27. }
  28. fn get_tauri_version<R: Runtime>(_context: InvokeContext<R>) -> super::Result<&'static str> {
  29. Ok(env!("CARGO_PKG_VERSION"))
  30. }
  31. }