2022-08-14 20:27:41 +00:00
|
|
|
#![cfg_attr(
|
|
|
|
all(not(debug_assertions), target_os = "windows"),
|
|
|
|
windows_subsystem = "windows"
|
|
|
|
)]
|
|
|
|
|
2022-11-28 06:03:15 +00:00
|
|
|
use std::collections::HashMap;
|
2022-08-14 20:27:41 +00:00
|
|
|
use std::str::FromStr;
|
2022-11-28 06:03:15 +00:00
|
|
|
use std::sync::Mutex;
|
2022-08-14 20:27:41 +00:00
|
|
|
// use tokio::runtime::Runtime;
|
|
|
|
|
2022-11-28 06:03:15 +00:00
|
|
|
use serde::{Serialize, Deserialize};
|
|
|
|
use tauri::{Manager, State};
|
|
|
|
use tokio::sync::oneshot;
|
|
|
|
|
2022-08-14 20:27:41 +00:00
|
|
|
mod storage;
|
|
|
|
mod http;
|
|
|
|
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
tauri::Builder::default()
|
2022-11-28 06:03:15 +00:00
|
|
|
.manage(CurrentSession)
|
|
|
|
.manage(RequestCount)
|
|
|
|
.manage(OpenRequests)
|
|
|
|
.invoke_handler(tauri::generate_handler![unlock])
|
2022-08-14 20:27:41 +00:00
|
|
|
.setup(|app| {
|
|
|
|
let addr = std::net::SocketAddrV4::from_str("127.0.0.1:12345").unwrap();
|
|
|
|
tauri::async_runtime::spawn(http::serve(addr, app.handle()));
|
|
|
|
Ok(())
|
|
|
|
})
|
|
|
|
.run(tauri::generate_context!())
|
|
|
|
.expect("error while running tauri application");
|
|
|
|
|
|
|
|
// let addr = std::net::SocketAddrV4::from_str("127.0.0.1:12345").unwrap();
|
|
|
|
// let rt = Runtime::new().unwrap();
|
|
|
|
|
|
|
|
// rt.block_on(http::serve(addr)).unwrap();
|
|
|
|
|
|
|
|
// let creds = std::fs::read_to_string("credentials.json").unwrap();
|
|
|
|
// storage::save(&creds, "correct horse battery staple");
|
|
|
|
}
|
2022-11-28 06:03:15 +00:00
|
|
|
|
|
|
|
#[derive(Serialize, Deserialize)]
|
|
|
|
pub enum Session {
|
|
|
|
Unlocked(String),
|
|
|
|
Locked,
|
|
|
|
Empty,
|
|
|
|
}
|
|
|
|
|
|
|
|
type CurrentSession = Mutex<Session>;
|
|
|
|
type RequestCount = Mutex<u64>;
|
|
|
|
type OpenRequests = Mutex<HashMap<u64, oneshot::Sender>>;
|
|
|
|
|
|
|
|
#[derive(Clone, Serialize, Deserialize)]
|
|
|
|
pub struct CredentialsRequest {
|
|
|
|
pub request_id: u64,
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// struct Session {
|
|
|
|
// key_id: String,
|
|
|
|
// secret_key: String,
|
|
|
|
// token: String,
|
|
|
|
// expires: u64,
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
#[tauri::command]
|
|
|
|
fn unlock(passphrase: String, current_session: State<'_, CurrentSession>) -> bool {
|
|
|
|
let credentials = storage::load(&passphrase);
|
|
|
|
*current_session.lock().unwrap() = CredentialStatus::Unlocked(credentials);
|
|
|
|
true
|
|
|
|
}
|