12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- // Copyright 2019-2024 Tauri Programme within The Commons Conservancy
- // SPDX-License-Identifier: Apache-2.0
- // SPDX-License-Identifier: MIT
- use serde::{Deserialize, Serialize};
- use tauri::{command, ipc::CommandScope};
- #[derive(Debug, Deserialize)]
- #[allow(unused)]
- pub struct RequestBody {
- id: i32,
- name: String,
- }
- #[derive(Debug, Deserialize)]
- pub struct LogScope {
- event: String,
- }
- #[command]
- pub fn log_operation(
- event: String,
- payload: Option<String>,
- command_scope: CommandScope<LogScope>,
- ) -> Result<(), &'static str> {
- if command_scope.denies().iter().any(|s| s.event == event) {
- Err("denied")
- } else if !command_scope.allows().iter().any(|s| s.event == event) {
- Err("not allowed")
- } else {
- log::info!("{} {:?}", event, payload);
- Ok(())
- }
- }
- #[derive(Clone, Serialize)]
- pub struct ApiResponse {
- message: String,
- }
- #[command]
- pub fn perform_request(endpoint: String, body: RequestBody) -> ApiResponse {
- println!("{} {:?}", endpoint, body);
- ApiResponse {
- message: "message response".into(),
- }
- }
- #[command]
- pub async fn download() -> Vec<u8> {
- vec![1, 2, 3]
- }
|