cmd.rs 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. // Copyright 2019-2024 Tauri Programme within The Commons Conservancy
  2. // SPDX-License-Identifier: Apache-2.0
  3. // SPDX-License-Identifier: MIT
  4. use serde::{Deserialize, Serialize};
  5. use tauri::{command, ipc::CommandScope};
  6. #[derive(Debug, Deserialize)]
  7. #[allow(unused)]
  8. pub struct RequestBody {
  9. id: i32,
  10. name: String,
  11. }
  12. #[derive(Debug, Deserialize)]
  13. pub struct LogScope {
  14. event: String,
  15. }
  16. #[command]
  17. pub fn log_operation(
  18. event: String,
  19. payload: Option<String>,
  20. command_scope: CommandScope<LogScope>,
  21. ) -> Result<(), &'static str> {
  22. if command_scope.denies().iter().any(|s| s.event == event) {
  23. Err("denied")
  24. } else if !command_scope.allows().iter().any(|s| s.event == event) {
  25. Err("not allowed")
  26. } else {
  27. log::info!("{} {:?}", event, payload);
  28. Ok(())
  29. }
  30. }
  31. #[derive(Clone, Serialize)]
  32. pub struct ApiResponse {
  33. message: String,
  34. }
  35. #[command]
  36. pub fn perform_request(endpoint: String, body: RequestBody) -> ApiResponse {
  37. println!("{} {:?}", endpoint, body);
  38. ApiResponse {
  39. message: "message response".into(),
  40. }
  41. }
  42. #[command]
  43. pub async fn download() -> Vec<u8> {
  44. vec![1, 2, 3]
  45. }