mirror of
https://github.com/YGGverse/Yoda.git
synced 2025-02-04 23:44:13 +00:00
use arc for db connection
This commit is contained in:
parent
db43289e24
commit
998e3170fb
@ -9,13 +9,13 @@ use gtk::{
|
||||
Application, ApplicationWindow,
|
||||
};
|
||||
|
||||
use sqlite::Connection;
|
||||
pub struct Browser {
|
||||
db: Arc<sqlite::Connection>,
|
||||
pub widget: Arc<gtk::ApplicationWindow>,
|
||||
pub main: Arc<main::Main>,
|
||||
}
|
||||
|
||||
pub fn new(app: &Application, db: &Connection, width: i32, height: i32) -> Browser {
|
||||
pub fn new(app: &Application, db: Arc<sqlite::Connection>, width: i32, height: i32) -> Browser {
|
||||
// Init components
|
||||
let main = Arc::new(main::new());
|
||||
|
||||
@ -55,5 +55,5 @@ pub fn new(app: &Application, db: &Connection, width: i32, height: i32) -> Brows
|
||||
widget.add_action_entries([action_tab_append, action_debug, action_quit]);
|
||||
|
||||
// Done
|
||||
Browser { widget, main }
|
||||
Browser { db, widget, main }
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
mod browser;
|
||||
|
||||
use std::fs;
|
||||
use std::sync::Arc;
|
||||
|
||||
use gtk::prelude::{ApplicationExt, ApplicationExtManual, GtkApplicationExt, GtkWindowExt};
|
||||
|
||||
@ -35,12 +36,12 @@ fn main() -> glib::ExitCode {
|
||||
db.push("database.sqlite3");
|
||||
|
||||
let db = match sqlite::open(db) {
|
||||
Ok(db) => db,
|
||||
Ok(db) => Arc::new(db),
|
||||
Err(e) => panic!("Failed to connect profile database: {e}"),
|
||||
};
|
||||
|
||||
move |this| {
|
||||
browser::new(&this, &db, 640, 480).widget.present();
|
||||
browser::new(&this, db.clone(), 640, 480).widget.present();
|
||||
}
|
||||
});
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user