Skip to content

Commit

Permalink
Merge pull request #83 from esomore/master
Browse files Browse the repository at this point in the history
Add calling setup_db function to create database if it doesn't exist
  • Loading branch information
benthecarman authored Jun 2, 2024
2 parents 9717d09 + fddaaac commit c8289dc
Showing 1 changed file with 19 additions and 13 deletions.
32 changes: 19 additions & 13 deletions src/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use iced::{
futures::{channel::mpsc::Sender, SinkExt},
subscription::{self, Subscription},
};
use log::{error, trace, warn};
use log::{error, info, trace, warn};
use tokio::sync::RwLock;
use tokio::task::spawn_blocking;
use uuid::Uuid;
Expand Down Expand Up @@ -393,20 +393,26 @@ pub fn run_core() -> Subscription<Message> {
let db_path = path.join("harbor.sqlite");

let db_path = db_path.to_str().unwrap().to_string();
if let Err(e) = check_password(&db_path, &password) {
// probably invalid password
error!("error using password: {e}");

tx.send(Message::core_msg(
id,
CoreUIMsg::UnlockFailed(e.to_string()),
))
.await
.expect("should send");
continue;
}
// if the db file doesn't exist, dont call check_password
if !std::path::Path::new(&db_path).exists() {
info!("Database does not exist, it will be created");
} else {
if let Err(e) = check_password(&db_path, &password) {
// probably invalid password
error!("error using password: {e}");

tx.send(Message::core_msg(
id,
CoreUIMsg::UnlockFailed(e.to_string()),
))
.await
.expect("should send");
continue;
}

log::info!("Correct password");
log::info!("Correct password");
}

let db = spawn_blocking(move || setup_db(&db_path, password))
.await
Expand Down

0 comments on commit c8289dc

Please sign in to comment.