mirror of
https://github.com/YGGverse/Yoda.git
synced 2026-04-02 17:45:28 +00:00
use arc for db connection
This commit is contained in:
parent
db43289e24
commit
998e3170fb
2 changed files with 6 additions and 5 deletions
|
|
@ -9,13 +9,13 @@ use gtk::{
|
||||||
Application, ApplicationWindow,
|
Application, ApplicationWindow,
|
||||||
};
|
};
|
||||||
|
|
||||||
use sqlite::Connection;
|
|
||||||
pub struct Browser {
|
pub struct Browser {
|
||||||
|
db: Arc<sqlite::Connection>,
|
||||||
pub widget: Arc<gtk::ApplicationWindow>,
|
pub widget: Arc<gtk::ApplicationWindow>,
|
||||||
pub main: Arc<main::Main>,
|
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
|
// Init components
|
||||||
let main = Arc::new(main::new());
|
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]);
|
widget.add_action_entries([action_tab_append, action_debug, action_quit]);
|
||||||
|
|
||||||
// Done
|
// Done
|
||||||
Browser { widget, main }
|
Browser { db, widget, main }
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
mod browser;
|
mod browser;
|
||||||
|
|
||||||
use std::fs;
|
use std::fs;
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
use gtk::prelude::{ApplicationExt, ApplicationExtManual, GtkApplicationExt, GtkWindowExt};
|
use gtk::prelude::{ApplicationExt, ApplicationExtManual, GtkApplicationExt, GtkWindowExt};
|
||||||
|
|
||||||
|
|
@ -35,12 +36,12 @@ fn main() -> glib::ExitCode {
|
||||||
db.push("database.sqlite3");
|
db.push("database.sqlite3");
|
||||||
|
|
||||||
let db = match sqlite::open(db) {
|
let db = match sqlite::open(db) {
|
||||||
Ok(db) => db,
|
Ok(db) => Arc::new(db),
|
||||||
Err(e) => panic!("Failed to connect profile database: {e}"),
|
Err(e) => panic!("Failed to connect profile database: {e}"),
|
||||||
};
|
};
|
||||||
|
|
||||||
move |this| {
|
move |this| {
|
||||||
browser::new(&this, &db, 640, 480).widget.present();
|
browser::new(&this, db.clone(), 640, 480).widget.present();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue