all is change; in change is all again made new
This commit is contained in:
@ -3,15 +3,25 @@
|
||||
windows_subsystem = "windows"
|
||||
)]
|
||||
|
||||
use std::collections::HashMap;
|
||||
use std::str::FromStr;
|
||||
use std::sync::Mutex;
|
||||
// use tokio::runtime::Runtime;
|
||||
|
||||
use serde::{Serialize, Deserialize};
|
||||
use tauri::{Manager, State};
|
||||
use tokio::sync::oneshot;
|
||||
|
||||
mod storage;
|
||||
mod http;
|
||||
|
||||
|
||||
fn main() {
|
||||
tauri::Builder::default()
|
||||
.manage(CurrentSession)
|
||||
.manage(RequestCount)
|
||||
.manage(OpenRequests)
|
||||
.invoke_handler(tauri::generate_handler![unlock])
|
||||
.setup(|app| {
|
||||
let addr = std::net::SocketAddrV4::from_str("127.0.0.1:12345").unwrap();
|
||||
tauri::async_runtime::spawn(http::serve(addr, app.handle()));
|
||||
@ -28,3 +38,35 @@ fn main() {
|
||||
// let creds = std::fs::read_to_string("credentials.json").unwrap();
|
||||
// storage::save(&creds, "correct horse battery staple");
|
||||
}
|
||||
|
||||
#[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
|
||||
}
|
||||
|
Reference in New Issue
Block a user