mirror of
https://github.com/YGGverse/Yoda.git
synced 2026-04-02 09:35:28 +00:00
resolve deadlock issue, draft migration features
This commit is contained in:
parent
259ec321be
commit
366c5fad8e
12 changed files with 192 additions and 210 deletions
|
|
@ -3,11 +3,11 @@ mod tab;
|
|||
mod widget;
|
||||
|
||||
use database::Database;
|
||||
use sqlite::{Connection, Transaction};
|
||||
use sqlite::Transaction;
|
||||
use tab::Tab;
|
||||
use widget::Widget;
|
||||
|
||||
use std::sync::{Arc, RwLock};
|
||||
use std::sync::Arc;
|
||||
|
||||
use gtk::{gio::SimpleAction, glib::GString, Box};
|
||||
|
||||
|
|
@ -20,8 +20,6 @@ pub struct Window {
|
|||
impl Window {
|
||||
// Construct
|
||||
pub fn new(
|
||||
// Extras
|
||||
profile_database_connection: Arc<RwLock<Connection>>,
|
||||
// Actions
|
||||
action_tab_page_navigation_base: Arc<SimpleAction>,
|
||||
action_tab_page_navigation_history_back: Arc<SimpleAction>,
|
||||
|
|
@ -30,32 +28,10 @@ impl Window {
|
|||
action_update: Arc<SimpleAction>,
|
||||
) -> Self {
|
||||
// Init database
|
||||
let database = {
|
||||
// Init writable database connection
|
||||
let mut connection = match profile_database_connection.write() {
|
||||
Ok(connection) => connection,
|
||||
Err(e) => todo!("{e}"),
|
||||
};
|
||||
|
||||
// Init new transaction
|
||||
let transaction = match connection.transaction() {
|
||||
Ok(transaction) => transaction,
|
||||
Err(e) => todo!("{e}"),
|
||||
};
|
||||
|
||||
// Init database structure
|
||||
match Database::init(&transaction) {
|
||||
Ok(database) => match transaction.commit() {
|
||||
Ok(_) => Arc::new(database),
|
||||
Err(e) => todo!("{e}"),
|
||||
},
|
||||
Err(e) => todo!("{e}"),
|
||||
}
|
||||
};
|
||||
let database = Arc::new(Database::new());
|
||||
|
||||
// Init components
|
||||
let tab = Arc::new(Tab::new(
|
||||
profile_database_connection,
|
||||
action_tab_page_navigation_base,
|
||||
action_tab_page_navigation_history_back,
|
||||
action_tab_page_navigation_history_forward,
|
||||
|
|
@ -163,4 +139,20 @@ impl Window {
|
|||
pub fn gobject(&self) -> &Box {
|
||||
&self.widget.gobject()
|
||||
}
|
||||
|
||||
// Tools
|
||||
pub fn migrate(tx: &Transaction) -> Result<(), String> {
|
||||
// Migrate self components
|
||||
if let Err(e) = Database::init(&tx) {
|
||||
return Err(e.to_string());
|
||||
}
|
||||
|
||||
// Delegate migration to childs
|
||||
if let Err(e) = Tab::migrate(&tx) {
|
||||
return Err(e.to_string());
|
||||
}
|
||||
|
||||
// Success
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue