From 043661282cb531bb1cb04370d8679d3c14e8ec6f Mon Sep 17 00:00:00 2001 From: yggverse Date: Sat, 21 Sep 2024 20:48:12 +0300 Subject: [PATCH] init sqlite connection --- Cargo.toml | 5 ++++- src/browser/mod.rs | 4 +++- src/main.rs | 22 ++++++++++++++++------ 3 files changed, 23 insertions(+), 8 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index a5dba531..7c70caff 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,7 +9,10 @@ keywords = ["gemini", "gemini-protocol", "browser", "client", "1965"] repository = "https://github.com/YGGverse/Yoda/tree/Rust-GTK4" homepage = "https://yggverse.github.io" +[dependencies] +sqlite = "0.36.1" + [dependencies.gtk] package = "gtk4" version = "0.9.1" -features = ["v4_8"] \ No newline at end of file +features = ["v4_8"] diff --git a/src/browser/mod.rs b/src/browser/mod.rs index fa3273b4..cc467eaa 100644 --- a/src/browser/mod.rs +++ b/src/browser/mod.rs @@ -7,7 +7,9 @@ use gtk::{ Application, ApplicationWindow, }; -pub fn new(app: &Application, width: i32, height: i32) -> ApplicationWindow { +use sqlite::Connection; + +pub fn new(app: &Application, db: &Connection, width: i32, height: i32) -> ApplicationWindow { // Init browser window let browser = ApplicationWindow::builder() .default_width(width) diff --git a/src/main.rs b/src/main.rs index 74071eee..02daf146 100644 --- a/src/main.rs +++ b/src/main.rs @@ -10,15 +10,25 @@ fn main() -> glib::ExitCode { // Init meta const APP_ID: &str = "io.github.yggverse.Yoda"; - // Init config location - let mut config = gtk::glib::user_config_dir(); + // Init profile directory + let mut fs = gtk::glib::user_config_dir(); - config.push(APP_ID); + fs.push(APP_ID); - if let Err(e) = fs::create_dir_all(config) { + if let Err(e) = fs::create_dir_all(&fs) { panic!("Failed to create profile directory: {e}") } + // Init profile database + let mut db = fs.clone(); + + db.push("database.sqlite3"); + + let db = match sqlite::open(db) { + Ok(db) => db, + Err(e) => panic!("Failed to connect profile database: {e}"), + }; + // Init app let app = Application::builder().application_id(APP_ID).build(); @@ -29,8 +39,8 @@ fn main() -> glib::ExitCode { app.set_accels_for_action("win.quit", &["Escape"]); // Create new window - app.connect_activate(|app| { - browser::new(app, 640, 480).present(); + app.connect_activate(move |app| { + browser::new(&app, &db, 640, 480).present(); }); // Start