|
|
@ -11,7 +11,7 @@ use gtk::{ |
|
|
|
prelude::{ActionExt, ApplicationExt, ApplicationExtManual, GtkApplicationExt, GtkWindowExt}, |
|
|
|
prelude::{ActionExt, ApplicationExt, ApplicationExtManual, GtkApplicationExt, GtkWindowExt}, |
|
|
|
Application, |
|
|
|
Application, |
|
|
|
}; |
|
|
|
}; |
|
|
|
use sqlite::Connection; |
|
|
|
use sqlite::{Connection, Transaction}; |
|
|
|
|
|
|
|
|
|
|
|
use std::{ |
|
|
|
use std::{ |
|
|
|
path::PathBuf, |
|
|
|
path::PathBuf, |
|
|
@ -21,12 +21,12 @@ use std::{ |
|
|
|
const APPLICATION_ID: &str = "io.github.yggverse.Yoda"; |
|
|
|
const APPLICATION_ID: &str = "io.github.yggverse.Yoda"; |
|
|
|
|
|
|
|
|
|
|
|
pub struct App { |
|
|
|
pub struct App { |
|
|
|
|
|
|
|
profile_database_connection: Arc<RwLock<Connection>>, |
|
|
|
|
|
|
|
// database: Arc<Database>,
|
|
|
|
// Actions
|
|
|
|
// Actions
|
|
|
|
// action_update: Arc<SimpleAction>,
|
|
|
|
// action_update: Arc<SimpleAction>,
|
|
|
|
// Components
|
|
|
|
// Components
|
|
|
|
// browser: Arc<Browser>,
|
|
|
|
// browser: Arc<Browser>,
|
|
|
|
// Extras
|
|
|
|
|
|
|
|
// database: Arc<Database>,
|
|
|
|
|
|
|
|
// GTK
|
|
|
|
// GTK
|
|
|
|
gobject: Application, |
|
|
|
gobject: Application, |
|
|
|
} |
|
|
|
} |
|
|
@ -38,28 +38,7 @@ impl App { |
|
|
|
profile_path: PathBuf, |
|
|
|
profile_path: PathBuf, |
|
|
|
) -> Self { |
|
|
|
) -> Self { |
|
|
|
// Init database
|
|
|
|
// Init database
|
|
|
|
let database = { |
|
|
|
let database = Arc::new(Database::new()); |
|
|
|
// 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}"), |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Init actions
|
|
|
|
// Init actions
|
|
|
|
let action_tool_debug = Action::new("win", true); |
|
|
|
let action_tool_debug = Action::new("win", true); |
|
|
@ -106,7 +85,6 @@ impl App { |
|
|
|
|
|
|
|
|
|
|
|
// Init components
|
|
|
|
// Init components
|
|
|
|
let browser = Arc::new(Browser::new( |
|
|
|
let browser = Arc::new(Browser::new( |
|
|
|
profile_database_connection.clone(), |
|
|
|
|
|
|
|
profile_path, |
|
|
|
profile_path, |
|
|
|
action_tool_debug.simple(), |
|
|
|
action_tool_debug.simple(), |
|
|
|
action_tool_profile_directory.simple(), |
|
|
|
action_tool_profile_directory.simple(), |
|
|
@ -170,6 +148,7 @@ impl App { |
|
|
|
// let browser = browser.clone();
|
|
|
|
// let browser = browser.clone();
|
|
|
|
let profile_database_connection = profile_database_connection.clone(); |
|
|
|
let profile_database_connection = profile_database_connection.clone(); |
|
|
|
let database = database.clone(); |
|
|
|
let database = database.clone(); |
|
|
|
|
|
|
|
let browser = browser.clone(); |
|
|
|
move |_| { |
|
|
|
move |_| { |
|
|
|
// Init writable connection
|
|
|
|
// Init writable connection
|
|
|
|
match profile_database_connection.write() { |
|
|
|
match profile_database_connection.write() { |
|
|
@ -220,12 +199,12 @@ impl App { |
|
|
|
|
|
|
|
|
|
|
|
// Return activated App struct
|
|
|
|
// Return activated App struct
|
|
|
|
Self { |
|
|
|
Self { |
|
|
|
|
|
|
|
// database,
|
|
|
|
|
|
|
|
profile_database_connection, |
|
|
|
// Actions (SimpleAction)
|
|
|
|
// Actions (SimpleAction)
|
|
|
|
// action_update: action_update.simple(),
|
|
|
|
// action_update: action_update.simple(),
|
|
|
|
// Components
|
|
|
|
// Components
|
|
|
|
// browser,
|
|
|
|
// browser,
|
|
|
|
// Extras
|
|
|
|
|
|
|
|
// database,
|
|
|
|
|
|
|
|
// GTK
|
|
|
|
// GTK
|
|
|
|
gobject, |
|
|
|
gobject, |
|
|
|
} |
|
|
|
} |
|
|
@ -233,6 +212,50 @@ impl App { |
|
|
|
|
|
|
|
|
|
|
|
// Actions
|
|
|
|
// Actions
|
|
|
|
pub fn run(&self) -> ExitCode { |
|
|
|
pub fn run(&self) -> ExitCode { |
|
|
|
|
|
|
|
// Begin database migration @TODO
|
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
// Init writable connection
|
|
|
|
|
|
|
|
let mut connection = match self.profile_database_connection.try_write() { |
|
|
|
|
|
|
|
Ok(connection) => connection, |
|
|
|
|
|
|
|
Err(e) => todo!("{e}"), |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Init new transaction
|
|
|
|
|
|
|
|
let transaction = match connection.transaction() { |
|
|
|
|
|
|
|
Ok(transaction) => transaction, |
|
|
|
|
|
|
|
Err(e) => todo!("{e}"), |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Begin migration
|
|
|
|
|
|
|
|
match App::migrate(&transaction) { |
|
|
|
|
|
|
|
Ok(_) => { |
|
|
|
|
|
|
|
// Confirm changes
|
|
|
|
|
|
|
|
match transaction.commit() { |
|
|
|
|
|
|
|
Ok(_) => {} // @TODO
|
|
|
|
|
|
|
|
Err(e) => todo!("{e}"), |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
Err(e) => todo!("{e}"), |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} // unlock database
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Start application
|
|
|
|
self.gobject.run() |
|
|
|
self.gobject.run() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 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) = Browser::migrate(&tx) { |
|
|
|
|
|
|
|
return Err(e.to_string()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Success
|
|
|
|
|
|
|
|
Ok(()) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|