mirror of
https://github.com/YGGverse/Yoda.git
synced 2025-03-10 12:41:34 +00:00
resolve deadlock issue, draft migration features
This commit is contained in:
parent
259ec321be
commit
366c5fad8e
79
src/app.rs
79
src/app.rs
@ -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(())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,11 +13,8 @@ use gtk::{
|
|||||||
prelude::{ActionMapExt, GtkWindowExt},
|
prelude::{ActionMapExt, GtkWindowExt},
|
||||||
ApplicationWindow,
|
ApplicationWindow,
|
||||||
};
|
};
|
||||||
use sqlite::{Connection, Transaction};
|
use sqlite::Transaction;
|
||||||
use std::{
|
use std::{path::PathBuf, sync::Arc};
|
||||||
path::PathBuf,
|
|
||||||
sync::{Arc, RwLock},
|
|
||||||
};
|
|
||||||
|
|
||||||
pub struct Browser {
|
pub struct Browser {
|
||||||
// Extras
|
// Extras
|
||||||
@ -32,7 +29,6 @@ impl Browser {
|
|||||||
// Construct
|
// Construct
|
||||||
pub fn new(
|
pub fn new(
|
||||||
// Extras
|
// Extras
|
||||||
profile_database_connection: Arc<RwLock<Connection>>,
|
|
||||||
profile_path: PathBuf,
|
profile_path: PathBuf,
|
||||||
// Actions
|
// Actions
|
||||||
action_tool_debug: Arc<SimpleAction>,
|
action_tool_debug: Arc<SimpleAction>,
|
||||||
@ -49,28 +45,7 @@ impl Browser {
|
|||||||
action_tab_pin: Arc<SimpleAction>,
|
action_tab_pin: Arc<SimpleAction>,
|
||||||
) -> Browser {
|
) -> Browser {
|
||||||
// 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 components
|
// Init components
|
||||||
let header = Arc::new(Header::new(
|
let header = Arc::new(Header::new(
|
||||||
@ -88,7 +63,6 @@ impl Browser {
|
|||||||
));
|
));
|
||||||
|
|
||||||
let window = Arc::new(Window::new(
|
let window = Arc::new(Window::new(
|
||||||
profile_database_connection.clone(),
|
|
||||||
action_tab_page_navigation_base.clone(),
|
action_tab_page_navigation_base.clone(),
|
||||||
action_tab_page_navigation_history_back.clone(),
|
action_tab_page_navigation_history_back.clone(),
|
||||||
action_tab_page_navigation_history_forward.clone(),
|
action_tab_page_navigation_history_forward.clone(),
|
||||||
@ -97,11 +71,7 @@ impl Browser {
|
|||||||
));
|
));
|
||||||
|
|
||||||
// Init widget
|
// Init widget
|
||||||
let widget = Arc::new(Widget::new(
|
let widget = Arc::new(Widget::new(header.gobject(), window.gobject()));
|
||||||
profile_database_connection.clone(),
|
|
||||||
header.gobject(),
|
|
||||||
window.gobject(),
|
|
||||||
));
|
|
||||||
|
|
||||||
// Assign actions
|
// Assign actions
|
||||||
widget.gobject().add_action(action_tool_debug.as_ref());
|
widget.gobject().add_action(action_tool_debug.as_ref());
|
||||||
@ -281,4 +251,29 @@ impl Browser {
|
|||||||
pub fn gobject(&self) -> &ApplicationWindow {
|
pub fn gobject(&self) -> &ApplicationWindow {
|
||||||
&self.widget.gobject()
|
&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
|
||||||
|
/* @TODO
|
||||||
|
if let Err(e) = Header::migrate(&tx) {
|
||||||
|
return Err(e.to_string());
|
||||||
|
} */
|
||||||
|
|
||||||
|
if let Err(e) = Window::migrate(&tx) {
|
||||||
|
return Err(e.to_string());
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Err(e) = Widget::migrate(&tx) {
|
||||||
|
return Err(e.to_string());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Success
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,11 @@ pub struct Database {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Database {
|
impl Database {
|
||||||
pub fn init(tx: &Transaction) -> Result<Database, Error> {
|
pub fn new() -> Self {
|
||||||
|
Self {}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn init(tx: &Transaction) -> Result<usize, Error> {
|
||||||
tx.execute(
|
tx.execute(
|
||||||
"CREATE TABLE IF NOT EXISTS `app_browser`
|
"CREATE TABLE IF NOT EXISTS `app_browser`
|
||||||
(
|
(
|
||||||
@ -18,9 +22,7 @@ impl Database {
|
|||||||
`app_id` INTEGER NOT NULL
|
`app_id` INTEGER NOT NULL
|
||||||
)",
|
)",
|
||||||
[],
|
[],
|
||||||
)?;
|
)
|
||||||
|
|
||||||
Ok(Self {})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn add(&self, tx: &Transaction, app_id: &i64) -> Result<usize, Error> {
|
pub fn add(&self, tx: &Transaction, app_id: &i64) -> Result<usize, Error> {
|
||||||
|
@ -3,8 +3,8 @@ mod database;
|
|||||||
use database::Database;
|
use database::Database;
|
||||||
|
|
||||||
use gtk::{prelude::GtkWindowExt, ApplicationWindow, Box, HeaderBar};
|
use gtk::{prelude::GtkWindowExt, ApplicationWindow, Box, HeaderBar};
|
||||||
use sqlite::{Connection, Transaction};
|
use sqlite::Transaction;
|
||||||
use std::sync::{Arc, RwLock};
|
use std::sync::Arc;
|
||||||
|
|
||||||
// Default options
|
// Default options
|
||||||
const DEFAULT_HEIGHT: i32 = 480;
|
const DEFAULT_HEIGHT: i32 = 480;
|
||||||
@ -18,34 +18,9 @@ pub struct Widget {
|
|||||||
|
|
||||||
impl Widget {
|
impl Widget {
|
||||||
// Construct
|
// Construct
|
||||||
pub fn new(
|
pub fn new(titlebar: &HeaderBar, child: &Box) -> Self {
|
||||||
profile_database_connection: Arc<RwLock<Connection>>,
|
|
||||||
titlebar: &HeaderBar,
|
|
||||||
child: &Box,
|
|
||||||
) -> 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 GTK
|
// Init GTK
|
||||||
let gobject = ApplicationWindow::builder()
|
let gobject = ApplicationWindow::builder()
|
||||||
@ -116,4 +91,18 @@ impl Widget {
|
|||||||
pub fn gobject(&self) -> &ApplicationWindow {
|
pub fn gobject(&self) -> &ApplicationWindow {
|
||||||
&self.gobject
|
&self.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
|
||||||
|
// nothing yet..
|
||||||
|
|
||||||
|
// Success
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,7 +13,11 @@ pub struct Database {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Database {
|
impl Database {
|
||||||
pub fn init(tx: &Transaction) -> Result<Database, Error> {
|
pub fn new() -> Self {
|
||||||
|
Self {}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn init(tx: &Transaction) -> Result<usize, Error> {
|
||||||
tx.execute(
|
tx.execute(
|
||||||
"CREATE TABLE IF NOT EXISTS `app_browser_widget`
|
"CREATE TABLE IF NOT EXISTS `app_browser_widget`
|
||||||
(
|
(
|
||||||
@ -24,9 +28,7 @@ impl Database {
|
|||||||
`is_maximized` INTEGER NOT NULL
|
`is_maximized` INTEGER NOT NULL
|
||||||
)",
|
)",
|
||||||
[],
|
[],
|
||||||
)?;
|
)
|
||||||
|
|
||||||
Ok(Self {})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn add(
|
pub fn add(
|
||||||
|
@ -3,11 +3,11 @@ mod tab;
|
|||||||
mod widget;
|
mod widget;
|
||||||
|
|
||||||
use database::Database;
|
use database::Database;
|
||||||
use sqlite::{Connection, Transaction};
|
use sqlite::Transaction;
|
||||||
use tab::Tab;
|
use tab::Tab;
|
||||||
use widget::Widget;
|
use widget::Widget;
|
||||||
|
|
||||||
use std::sync::{Arc, RwLock};
|
use std::sync::Arc;
|
||||||
|
|
||||||
use gtk::{gio::SimpleAction, glib::GString, Box};
|
use gtk::{gio::SimpleAction, glib::GString, Box};
|
||||||
|
|
||||||
@ -20,8 +20,6 @@ pub struct Window {
|
|||||||
impl Window {
|
impl Window {
|
||||||
// Construct
|
// Construct
|
||||||
pub fn new(
|
pub fn new(
|
||||||
// Extras
|
|
||||||
profile_database_connection: Arc<RwLock<Connection>>,
|
|
||||||
// Actions
|
// Actions
|
||||||
action_tab_page_navigation_base: Arc<SimpleAction>,
|
action_tab_page_navigation_base: Arc<SimpleAction>,
|
||||||
action_tab_page_navigation_history_back: Arc<SimpleAction>,
|
action_tab_page_navigation_history_back: Arc<SimpleAction>,
|
||||||
@ -30,32 +28,10 @@ impl Window {
|
|||||||
action_update: Arc<SimpleAction>,
|
action_update: Arc<SimpleAction>,
|
||||||
) -> 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 components
|
// Init components
|
||||||
let tab = Arc::new(Tab::new(
|
let tab = Arc::new(Tab::new(
|
||||||
profile_database_connection,
|
|
||||||
action_tab_page_navigation_base,
|
action_tab_page_navigation_base,
|
||||||
action_tab_page_navigation_history_back,
|
action_tab_page_navigation_history_back,
|
||||||
action_tab_page_navigation_history_forward,
|
action_tab_page_navigation_history_forward,
|
||||||
@ -163,4 +139,20 @@ impl Window {
|
|||||||
pub fn gobject(&self) -> &Box {
|
pub fn gobject(&self) -> &Box {
|
||||||
&self.widget.gobject()
|
&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(())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,11 @@ pub struct Database {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Database {
|
impl Database {
|
||||||
pub fn init(tx: &Transaction) -> Result<Database, Error> {
|
pub fn new() -> Self {
|
||||||
|
Self {}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn init(tx: &Transaction) -> Result<usize, Error> {
|
||||||
tx.execute(
|
tx.execute(
|
||||||
"CREATE TABLE IF NOT EXISTS `app_browser_window`
|
"CREATE TABLE IF NOT EXISTS `app_browser_window`
|
||||||
(
|
(
|
||||||
@ -18,9 +22,7 @@ impl Database {
|
|||||||
`app_browser_id` INTEGER NOT NULL
|
`app_browser_id` INTEGER NOT NULL
|
||||||
)",
|
)",
|
||||||
[],
|
[],
|
||||||
)?;
|
)
|
||||||
|
|
||||||
Ok(Self {})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn add(&self, tx: &Transaction, app_browser_id: &i64) -> Result<usize, Error> {
|
pub fn add(&self, tx: &Transaction, app_browser_id: &i64) -> Result<usize, Error> {
|
||||||
|
@ -6,7 +6,7 @@ mod widget;
|
|||||||
use database::Database;
|
use database::Database;
|
||||||
use label::Label;
|
use label::Label;
|
||||||
use page::Page;
|
use page::Page;
|
||||||
use sqlite::{Connection, Transaction};
|
use sqlite::Transaction;
|
||||||
use widget::Widget;
|
use widget::Widget;
|
||||||
|
|
||||||
use gtk::{
|
use gtk::{
|
||||||
@ -16,11 +16,7 @@ use gtk::{
|
|||||||
GestureClick, Notebook,
|
GestureClick, Notebook,
|
||||||
};
|
};
|
||||||
|
|
||||||
use std::{
|
use std::{cell::RefCell, collections::HashMap, sync::Arc};
|
||||||
cell::RefCell,
|
|
||||||
collections::HashMap,
|
|
||||||
sync::{Arc, RwLock},
|
|
||||||
};
|
|
||||||
|
|
||||||
// Common struct for HashMap index
|
// Common struct for HashMap index
|
||||||
pub struct TabItem {
|
pub struct TabItem {
|
||||||
@ -30,7 +26,6 @@ pub struct TabItem {
|
|||||||
|
|
||||||
// Main
|
// Main
|
||||||
pub struct Tab {
|
pub struct Tab {
|
||||||
profile_database_connection: Arc<RwLock<Connection>>,
|
|
||||||
database: Arc<Database>,
|
database: Arc<Database>,
|
||||||
// Actions
|
// Actions
|
||||||
action_tab_page_navigation_base: Arc<SimpleAction>,
|
action_tab_page_navigation_base: Arc<SimpleAction>,
|
||||||
@ -47,7 +42,6 @@ pub struct Tab {
|
|||||||
impl Tab {
|
impl Tab {
|
||||||
// Construct
|
// Construct
|
||||||
pub fn new(
|
pub fn new(
|
||||||
profile_database_connection: Arc<RwLock<Connection>>,
|
|
||||||
// Actions
|
// Actions
|
||||||
action_tab_page_navigation_base: Arc<SimpleAction>,
|
action_tab_page_navigation_base: Arc<SimpleAction>,
|
||||||
action_tab_page_navigation_history_back: Arc<SimpleAction>,
|
action_tab_page_navigation_history_back: Arc<SimpleAction>,
|
||||||
@ -56,28 +50,7 @@ impl Tab {
|
|||||||
action_update: Arc<SimpleAction>,
|
action_update: Arc<SimpleAction>,
|
||||||
) -> 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 empty HashMap index as no tabs appended yet
|
// Init empty HashMap index as no tabs appended yet
|
||||||
let index = RefCell::new(HashMap::new());
|
let index = RefCell::new(HashMap::new());
|
||||||
@ -87,7 +60,6 @@ impl Tab {
|
|||||||
|
|
||||||
// Return non activated struct
|
// Return non activated struct
|
||||||
Self {
|
Self {
|
||||||
profile_database_connection,
|
|
||||||
database,
|
database,
|
||||||
// Define action links
|
// Define action links
|
||||||
action_tab_page_navigation_base,
|
action_tab_page_navigation_base,
|
||||||
@ -135,11 +107,7 @@ impl Tab {
|
|||||||
let id = uuid_string_random();
|
let id = uuid_string_random();
|
||||||
|
|
||||||
// Init new tab components
|
// Init new tab components
|
||||||
let label = Arc::new(Label::new(
|
let label = Arc::new(Label::new(id.clone(), false));
|
||||||
self.profile_database_connection.clone(),
|
|
||||||
id.clone(),
|
|
||||||
false,
|
|
||||||
));
|
|
||||||
|
|
||||||
let page = Arc::new(Page::new(
|
let page = Arc::new(Page::new(
|
||||||
id.clone(),
|
id.clone(),
|
||||||
@ -335,4 +303,25 @@ impl Tab {
|
|||||||
pub fn gobject(&self) -> &Notebook {
|
pub fn gobject(&self) -> &Notebook {
|
||||||
self.widget.gobject()
|
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) = Label::migrate(&tx) {
|
||||||
|
return Err(e.to_string());
|
||||||
|
}
|
||||||
|
|
||||||
|
/* @TODO
|
||||||
|
if let Err(e) = Page::migrate(&tx) {
|
||||||
|
return Err(e.to_string());
|
||||||
|
} */
|
||||||
|
|
||||||
|
// Success
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,7 +11,11 @@ pub struct Database {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Database {
|
impl Database {
|
||||||
pub fn init(tx: &Transaction) -> Result<Database, Error> {
|
pub fn new() -> Self {
|
||||||
|
Self {}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn init(tx: &Transaction) -> Result<usize, Error> {
|
||||||
tx.execute(
|
tx.execute(
|
||||||
"CREATE TABLE IF NOT EXISTS `app_browser_window_tab`
|
"CREATE TABLE IF NOT EXISTS `app_browser_window_tab`
|
||||||
(
|
(
|
||||||
@ -20,9 +24,7 @@ impl Database {
|
|||||||
`is_current` INTEGER NOT NULL
|
`is_current` INTEGER NOT NULL
|
||||||
)",
|
)",
|
||||||
[],
|
[],
|
||||||
)?;
|
)
|
||||||
|
|
||||||
Ok(Self {})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn add(
|
pub fn add(
|
||||||
|
@ -5,12 +5,12 @@ mod widget;
|
|||||||
|
|
||||||
use database::Database;
|
use database::Database;
|
||||||
use pin::Pin;
|
use pin::Pin;
|
||||||
use sqlite::{Connection, Transaction};
|
use sqlite::Transaction;
|
||||||
use title::Title;
|
use title::Title;
|
||||||
use widget::Widget;
|
use widget::Widget;
|
||||||
|
|
||||||
use gtk::{glib::GString, Box};
|
use gtk::{glib::GString, Box};
|
||||||
use std::sync::{Arc, RwLock};
|
use std::sync::Arc;
|
||||||
|
|
||||||
pub struct Label {
|
pub struct Label {
|
||||||
database: Arc<Database>,
|
database: Arc<Database>,
|
||||||
@ -23,37 +23,9 @@ pub struct Label {
|
|||||||
|
|
||||||
impl Label {
|
impl Label {
|
||||||
// Construct
|
// Construct
|
||||||
pub fn new(
|
pub fn new(name: GString, is_pinned: bool) -> Label {
|
||||||
profile_database_connection: Arc<RwLock<Connection>>,
|
|
||||||
name: GString,
|
|
||||||
is_pinned: bool,
|
|
||||||
) -> Label {
|
|
||||||
// Init database
|
// Init database
|
||||||
let database = {
|
let database = Arc::new(Database::new());
|
||||||
/* @TODO init outside
|
|
||||||
// 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}"),
|
|
||||||
} */
|
|
||||||
|
|
||||||
Arc::new(Database::new())
|
|
||||||
};
|
|
||||||
|
|
||||||
// Components
|
// Components
|
||||||
let pin = Arc::new(Pin::new(is_pinned));
|
let pin = Arc::new(Pin::new(is_pinned));
|
||||||
@ -135,4 +107,18 @@ impl Label {
|
|||||||
pub fn gobject(&self) -> &Box {
|
pub fn gobject(&self) -> &Box {
|
||||||
&self.widget.gobject()
|
&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
|
||||||
|
// nothing yet..
|
||||||
|
|
||||||
|
// Success
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -15,7 +15,7 @@ impl Database {
|
|||||||
Self {}
|
Self {}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn init(tx: &Transaction) -> Result<Database, Error> {
|
pub fn init(tx: &Transaction) -> Result<usize, Error> {
|
||||||
tx.execute(
|
tx.execute(
|
||||||
"CREATE TABLE IF NOT EXISTS `app_browser_window_tab_label`
|
"CREATE TABLE IF NOT EXISTS `app_browser_window_tab_label`
|
||||||
(
|
(
|
||||||
@ -24,9 +24,7 @@ impl Database {
|
|||||||
`is_pinned` INTEGER NOT NULL
|
`is_pinned` INTEGER NOT NULL
|
||||||
)",
|
)",
|
||||||
[],
|
[],
|
||||||
)?;
|
)
|
||||||
|
|
||||||
Ok(Self {})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn add(
|
pub fn add(
|
||||||
|
@ -9,16 +9,18 @@ pub struct Database {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Database {
|
impl Database {
|
||||||
pub fn init(tx: &Transaction) -> Result<Database, Error> {
|
pub fn new() -> Self {
|
||||||
|
Self {}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn init(tx: &Transaction) -> Result<usize, Error> {
|
||||||
tx.execute(
|
tx.execute(
|
||||||
"CREATE TABLE IF NOT EXISTS `app`
|
"CREATE TABLE IF NOT EXISTS `app`
|
||||||
(
|
(
|
||||||
`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL
|
`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL
|
||||||
)",
|
)",
|
||||||
[],
|
[],
|
||||||
)?;
|
)
|
||||||
|
|
||||||
Ok(Self {})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn add(&self, tx: &Transaction) -> Result<usize, Error> {
|
pub fn add(&self, tx: &Transaction) -> Result<usize, Error> {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user