creddy/src-tauri/src/ipc.rs

53 lines
1.1 KiB
Rust
Raw Normal View History

2022-11-29 00:16:33 +00:00
use serde::{Serialize, Deserialize};
use tauri::State;
2022-12-04 05:47:09 +00:00
use crate::state::{AppState, Session};
2022-11-29 00:16:33 +00:00
2022-11-30 00:13:09 +00:00
#[derive(Copy, Clone, Serialize, Deserialize)]
pub struct Request {
pub id: u64,
}
2022-11-29 00:16:33 +00:00
#[derive(Serialize, Deserialize)]
pub struct RequestResponse {
pub id: u64,
pub approval: Approval,
}
#[derive(Serialize, Deserialize)]
pub enum Approval {
Approved,
Denied,
}
2022-11-29 00:16:33 +00:00
#[tauri::command]
pub fn respond(response: RequestResponse, app_state: State<'_, AppState>) -> Result<(), String> {
app_state.send_response(response)
.map_err(|e| format!("Error responding to request: {e}"))
}
#[tauri::command]
2022-12-04 05:47:09 +00:00
pub async fn unlock(passphrase: String, app_state: State<'_, AppState>) -> Result<(), String> {
app_state.decrypt(&passphrase)
.await
.map_err(|e| e.to_string())?;
Ok(())
}
#[tauri::command]
pub fn session_status(app_state: State<'_, AppState>) -> String {
let session = app_state.session.read().unwrap();
match *session {
Session::Locked(_) => "locked".into(),
Session::Unlocked(_) => "unlocked".into(),
Session::Empty => "empty".into()
}
2022-11-29 00:16:33 +00:00
}