Browse Source

init sqlite connection

master
yggverse 2 months ago
parent
commit
043661282c
  1. 3
      Cargo.toml
  2. 4
      src/browser/mod.rs
  3. 22
      src/main.rs

3
Cargo.toml

@ -9,6 +9,9 @@ keywords = ["gemini", "gemini-protocol", "browser", "client", "1965"]
repository = "https://github.com/YGGverse/Yoda/tree/Rust-GTK4" repository = "https://github.com/YGGverse/Yoda/tree/Rust-GTK4"
homepage = "https://yggverse.github.io" homepage = "https://yggverse.github.io"
[dependencies]
sqlite = "0.36.1"
[dependencies.gtk] [dependencies.gtk]
package = "gtk4" package = "gtk4"
version = "0.9.1" version = "0.9.1"

4
src/browser/mod.rs

@ -7,7 +7,9 @@ use gtk::{
Application, ApplicationWindow, 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 // Init browser window
let browser = ApplicationWindow::builder() let browser = ApplicationWindow::builder()
.default_width(width) .default_width(width)

22
src/main.rs

@ -10,15 +10,25 @@ fn main() -> glib::ExitCode {
// Init meta // Init meta
const APP_ID: &str = "io.github.yggverse.Yoda"; const APP_ID: &str = "io.github.yggverse.Yoda";
// Init config location // Init profile directory
let mut config = gtk::glib::user_config_dir(); 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}") 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 // Init app
let app = Application::builder().application_id(APP_ID).build(); let app = Application::builder().application_id(APP_ID).build();
@ -29,8 +39,8 @@ fn main() -> glib::ExitCode {
app.set_accels_for_action("win.quit", &["<Ctrl>Escape"]); app.set_accels_for_action("win.quit", &["<Ctrl>Escape"]);
// Create new window // Create new window
app.connect_activate(|app| { app.connect_activate(move |app| {
browser::new(app, 640, 480).present(); browser::new(&app, &db, 640, 480).present();
}); });
// Start // Start

Loading…
Cancel
Save