minor tweaks

This commit is contained in:
2023-04-29 10:01:45 -07:00
parent e746963052
commit 913148a75a
5 changed files with 29 additions and 45 deletions

View File

@ -90,7 +90,7 @@ pub fn set_auto_launch(is_configured: bool) -> Result<(), SetupError> {
pub fn get_or_create_db_path() -> Result<PathBuf, DataDirError> {
if cfg!(debug_assertions) {
if cfg!(debug_assertions) && std::env::var("HOME").is_ok() {
return Ok(PathBuf::from("./creddy.db"));
}

View File

@ -69,43 +69,17 @@ pub struct AppState {
}
impl AppState {
pub fn new(config: AppConfig, session: Session, server: Server, pool: SqlitePool) -> AppState {
AppState {
config: RwLock::new(config),
session: RwLock::new(session),
request_count: RwLock::new(0),
open_requests: RwLock::new(HashMap::new()),
bans: RwLock::new(HashSet::new()),
server: RwLock::new(server),
pool,
pub fn new(config: AppConfig, session: Session, server: Server, pool: SqlitePool) -> AppState {
AppState {
config: RwLock::new(config),
session: RwLock::new(session),
request_count: RwLock::new(0),
open_requests: RwLock::new(HashMap::new()),
bans: RwLock::new(HashSet::new()),
server: RwLock::new(server),
pool,
}
}
}
// pub async fn load(app_handle: AppHandle) -> Result<Self, SetupError> {
// let conn_opts = SqliteConnectOptions::new()
// .filename(config::get_or_create_db_path())
// .create_if_missing(true);
// let pool_opts = SqlitePoolOptions::new();
// let pool: SqlitePool = pool_opts.connect_with(conn_opts).await?;
// sqlx::migrate!().run(&pool).await?;
// let creds = Self::load_creds(&pool).await?;
// let conf = AppConfig::load(&pool).await?;
// let server = Server::new(conf.listen_addr, conf.listen_port, app_handle)?;
// let state = AppState {
// config: RwLock::new(conf),
// session: RwLock::new(creds),
// request_count: RwLock::new(0),
// open_requests: RwLock::new(HashMap::new()),
// bans: RwLock::new(HashSet::new()),
// server: RwLock::new(server),
// pool,
// };
// Ok(state)
// }
pub async fn load_creds(pool: &SqlitePool) -> Result<Session, SetupError> {
let res = sqlx::query!("SELECT * FROM credentials ORDER BY created_at desc")
@ -313,9 +287,8 @@ pub fn new(config: AppConfig, session: Session, server: Server, pool: SqlitePool
expiration,
};
if cfg!(debug_assertions) {
println!("Got new session:\n{}", serde_json::to_string(&session_creds).unwrap());
}
#[cfg(debug_assertions)]
println!("Got new session:\n{}", serde_json::to_string(&session_creds).unwrap());
*app_session = Session::Unlocked(session_creds);