display client info and unlock errors to user
This commit is contained in:
@ -26,7 +26,7 @@ fn get_associated_pids(local_port: u16) -> Result<Vec<u32>, netstat2::error::Err
|
||||
};
|
||||
|
||||
if proto_info.local_port == local_port
|
||||
&& proto_info.remote_port == 12345
|
||||
&& proto_info.remote_port == 19_923
|
||||
&& proto_info.local_addr == std::net::Ipv4Addr::LOCALHOST
|
||||
&& proto_info.remote_addr == std::net::Ipv4Addr::LOCALHOST
|
||||
{
|
||||
|
37
src-tauri/src/config.rs
Normal file
37
src-tauri/src/config.rs
Normal file
@ -0,0 +1,37 @@
|
||||
use std::net::Ipv4Addr;
|
||||
use std::path::PathBuf;
|
||||
|
||||
|
||||
pub struct AppConfig {
|
||||
pub db_path: PathBuf,
|
||||
pub listen_addr: Ipv4Addr,
|
||||
pub listen_port: u16,
|
||||
}
|
||||
|
||||
impl Default for AppConfig {
|
||||
fn default() -> Self {
|
||||
AppConfig {
|
||||
db_path: get_or_create_db_path(),
|
||||
listen_addr: Ipv4Addr::LOCALHOST,
|
||||
listen_port: 19_923
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
fn get_or_create_db_path() -> PathBuf {
|
||||
if cfg!(debug_assertions) {
|
||||
return PathBuf::from("./creddy.db");
|
||||
}
|
||||
|
||||
let mut parent = std::env::var("HOME")
|
||||
.map(|h| {
|
||||
let mut p = PathBuf::from(h);
|
||||
p.push(".config");
|
||||
p
|
||||
})
|
||||
.unwrap_or(PathBuf::from("."));
|
||||
parent.push("creddy.db");
|
||||
|
||||
parent
|
||||
}
|
@ -1,8 +1,5 @@
|
||||
use std::fmt::{Display, Formatter};
|
||||
use std::convert::From;
|
||||
use std::str::Utf8Error;
|
||||
|
||||
use thiserror::Error;
|
||||
|
||||
use aws_sdk_sts::{
|
||||
types::SdkError as AwsSdkError,
|
||||
error::GetSessionTokenError,
|
||||
|
@ -3,14 +3,17 @@
|
||||
windows_subsystem = "windows"
|
||||
)]
|
||||
|
||||
use std::str::FromStr;
|
||||
use tauri::Manager;
|
||||
|
||||
mod config;
|
||||
mod errors;
|
||||
mod clientinfo;
|
||||
mod ipc;
|
||||
mod state;
|
||||
mod server;
|
||||
|
||||
use state::AppState;
|
||||
|
||||
|
||||
fn main() {
|
||||
let initial_state = match state::AppState::new() {
|
||||
@ -27,7 +30,9 @@ fn main() {
|
||||
ipc::save_credentials,
|
||||
])
|
||||
.setup(|app| {
|
||||
let addr = std::net::SocketAddrV4::from_str("127.0.0.1:12345").unwrap();
|
||||
let state = app.state::<AppState>();
|
||||
let config = state.config.read().unwrap();
|
||||
let addr = std::net::SocketAddrV4::new(config.listen_addr, config.listen_port);
|
||||
tauri::async_runtime::spawn(server::serve(addr, app.handle()));
|
||||
Ok(())
|
||||
})
|
||||
|
@ -15,6 +15,7 @@ use sodiumoxide::crypto::{
|
||||
use tauri::async_runtime as runtime;
|
||||
use tauri::Manager;
|
||||
|
||||
use crate::config::AppConfig;
|
||||
use crate::ipc;
|
||||
use crate::clientinfo::Client;
|
||||
use crate::errors::*;
|
||||
@ -54,6 +55,7 @@ pub enum Session {
|
||||
|
||||
|
||||
pub struct AppState {
|
||||
pub config: RwLock<AppConfig>,
|
||||
pub session: RwLock<Session>,
|
||||
pub request_count: RwLock<u64>,
|
||||
pub open_requests: RwLock<HashMap<u64, Sender<ipc::Approval>>>,
|
||||
@ -73,6 +75,7 @@ impl AppState {
|
||||
let creds = runtime::block_on(Self::load_creds(&pool))?;
|
||||
|
||||
let state = AppState {
|
||||
config: RwLock::new(AppConfig::default()),
|
||||
session: RwLock::new(creds),
|
||||
request_count: RwLock::new(0),
|
||||
open_requests: RwLock::new(HashMap::new()),
|
||||
|
Reference in New Issue
Block a user