fix some things
This commit is contained in:
parent
397928b8f1
commit
234d9e0471
@ -5,6 +5,12 @@ use crate::state::AppState;
|
||||
use crate::storage;
|
||||
|
||||
|
||||
#[derive(Copy, Clone, Serialize, Deserialize)]
|
||||
pub struct Request {
|
||||
pub id: u64,
|
||||
}
|
||||
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub struct RequestResponse {
|
||||
pub id: u64,
|
||||
@ -29,7 +35,7 @@ pub fn respond(response: RequestResponse, app_state: State<'_, AppState>) -> Res
|
||||
#[tauri::command]
|
||||
pub fn unlock(passphrase: String, app_state: State<'_, AppState>) -> bool {
|
||||
let root_credentials = storage::load(&passphrase);
|
||||
// get new session from AWS and store in app state
|
||||
app_state.set_creds(root_credentials); // for now
|
||||
true
|
||||
}
|
||||
|
||||
|
@ -7,7 +7,7 @@ use tokio::sync::oneshot;
|
||||
use tauri::{AppHandle, Manager};
|
||||
|
||||
use crate::errors::RequestError;
|
||||
use crate::ipc::Approval;
|
||||
use crate::ipc::{Request, Approval};
|
||||
|
||||
|
||||
pub async fn serve(addr: SocketAddrV4, app_handle: AppHandle) -> io::Result<()> {
|
||||
@ -45,6 +45,8 @@ async fn handle(mut stream: TcpStream, app_handle: AppHandle) -> Result<(), Requ
|
||||
let (chan_send, chan_recv) = oneshot::channel();
|
||||
let app_state = app_handle.state::<crate::state::AppState>();
|
||||
let request_id = app_state.register_request(chan_send);
|
||||
// Do we want to panic if this fails? Does that mean the frontend is dead?
|
||||
app_handle.emit_all("credentials-request", Request {id: request_id}).unwrap();
|
||||
|
||||
let mut buf = [0; 8192]; // it's what tokio's BufReader uses
|
||||
let mut n = 0;
|
||||
|
@ -52,12 +52,12 @@ impl AppState {
|
||||
|
||||
pub fn register_request(&self, chan: Sender<ipc::Approval>) -> u64 {
|
||||
let count = {
|
||||
let c = self.request_count.write().unwrap();
|
||||
let mut c = self.request_count.write().unwrap();
|
||||
*c += 1;
|
||||
c
|
||||
};
|
||||
|
||||
let open_requests = self.open_requests.write().unwrap();
|
||||
let mut open_requests = self.open_requests.write().unwrap();
|
||||
open_requests.insert(*count, chan);
|
||||
*count
|
||||
}
|
||||
@ -73,9 +73,17 @@ impl AppState {
|
||||
.map_err(|_e| SendResponseError::Abandoned)
|
||||
}
|
||||
|
||||
pub fn set_creds(&self, new_creds: Credentials) {
|
||||
let mut current_creds = self.credentials.write().unwrap();
|
||||
*current_creds = Some(new_creds);
|
||||
let mut status = self.status.write().unwrap();
|
||||
*status = SessionStatus::Unlocked;
|
||||
}
|
||||
|
||||
pub fn get_creds_serialized(&self) -> String {
|
||||
let creds = self.credentials.read().unwrap();
|
||||
let creds_option = self.credentials.read().unwrap();
|
||||
// fix this at some point
|
||||
serde_json::to_string(&creds.unwrap()).unwrap()
|
||||
let creds = creds_option.as_ref().unwrap();
|
||||
serde_json::to_string(creds).unwrap()
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user