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-12-14 00:50:44 +00:00
|
|
|
#[derive(Clone, Serialize, Deserialize)]
|
|
|
|
pub struct Client {
|
|
|
|
pub pid: u32,
|
|
|
|
pub exe: String,
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[derive(Clone, Serialize, Deserialize)]
|
2022-11-30 00:13:09 +00:00
|
|
|
pub struct Request {
|
|
|
|
pub id: u64,
|
2022-12-14 00:50:44 +00:00
|
|
|
pub clients: Vec<Client>,
|
2022-11-30 00:13:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
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 {
|
2022-11-28 06:03:15 +00:00
|
|
|
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]
|
2022-12-14 00:50:44 +00:00
|
|
|
pub fn get_session_status(app_state: State<'_, AppState>) -> String {
|
2022-12-04 05:47:09 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|