move migration api out of struct implementation

This commit is contained in:
yggverse 2024-11-03 17:05:32 +02:00
parent 06f43f34f3
commit 39ee50c4ba
12 changed files with 173 additions and 177 deletions

View File

@ -233,7 +233,7 @@ impl App {
}; };
// Begin migration // Begin migration
match App::migrate(&transaction) { match migrate(&transaction) {
Ok(_) => { Ok(_) => {
// Confirm changes // Confirm changes
match transaction.commit() { match transaction.commit() {
@ -248,18 +248,18 @@ impl App {
// Start application // Start application
self.gobject.run() self.gobject.run()
} }
}
// Tools
fn migrate(tx: &Transaction) -> Result<(), String> { // Tools
// Migrate self components fn migrate(tx: &Transaction) -> Result<(), String> {
if let Err(e) = Database::init(&tx) { // Migrate self components
return Err(e.to_string()); if let Err(e) = Database::init(&tx) {
} return Err(e.to_string());
}
// Delegate migration to childs
Browser::migrate(&tx)?; // Delegate migration to childs
browser::migrate(&tx)?;
// Success
Ok(()) // Success
} Ok(())
} }

View File

@ -250,21 +250,21 @@ 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> { // Tools
// Migrate self components pub fn migrate(tx: &Transaction) -> Result<(), String> {
if let Err(e) = Database::init(&tx) { // Migrate self components
return Err(e.to_string()); if let Err(e) = Database::init(&tx) {
} return Err(e.to_string());
}
// Delegate migration to childs
/* @TODO // Delegate migration to childs
Header::migrate(&tx)?; */ /* @TODO
Window::migrate(&tx)?; header::migrate(&tx)?; */
Widget::migrate(&tx)?; window::migrate(&tx)?;
widget::migrate(&tx)?;
// Success
Ok(()) // Success
} Ok(())
} }

View File

@ -100,18 +100,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> { // Tools
// Migrate self components pub fn migrate(tx: &Transaction) -> Result<(), String> {
if let Err(e) = Database::init(&tx) { // Migrate self components
return Err(e.to_string()); if let Err(e) = Database::init(&tx) {
} return Err(e.to_string());
}
// Delegate migration to childs
// nothing yet.. // Delegate migration to childs
// nothing yet..
// Success
Ok(()) // Success
} Ok(())
} }

View File

@ -168,18 +168,18 @@ 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> { // Tools
// Migrate self components pub fn migrate(tx: &Transaction) -> Result<(), String> {
if let Err(e) = Database::init(&tx) { // Migrate self components
return Err(e.to_string()); if let Err(e) = Database::init(&tx) {
} return Err(e.to_string());
}
// Delegate migration to childs
Tab::migrate(&tx)?; // Delegate migration to childs
tab::migrate(&tx)?;
// Success
Ok(()) // Success
} Ok(())
} }

View File

@ -335,21 +335,18 @@ impl Tab {
pub fn gobject(&self) -> &TabView { pub fn gobject(&self) -> &TabView {
self.widget.gobject() self.widget.gobject()
} }
}
// Tools
pub fn migrate(tx: &Transaction) -> Result<(), String> { // Tools
// Migrate self components pub fn migrate(tx: &Transaction) -> Result<(), String> {
if let Err(e) = Database::init(&tx) { // Migrate self components
return Err(e.to_string()); if let Err(e) = Database::init(&tx) {
} return Err(e.to_string());
}
// Delegate migration to childs
Item::migrate(&tx)?; // Delegate migration to childs
item::migrate(&tx)?;
/* @TODO
Page::migrate(&tx)?; */ // Success
Ok(())
// Success
Ok(())
}
} }

View File

@ -219,19 +219,19 @@ impl Item {
pub fn gobject(&self) -> &TabPage { pub fn gobject(&self) -> &TabPage {
&self.widget.gobject() &self.widget.gobject()
} }
}
// Tools
pub fn migrate(tx: &Transaction) -> Result<(), String> { // Tools
// Migrate self components pub fn migrate(tx: &Transaction) -> Result<(), String> {
if let Err(e) = Database::init(&tx) { // Migrate self components
return Err(e.to_string()); if let Err(e) = Database::init(&tx) {
} return Err(e.to_string());
}
// Delegate migration to childs
Page::migrate(&tx)?; // Delegate migration to childs
Widget::migrate(&tx)?; page::migrate(&tx)?;
widget::migrate(&tx)?;
// Success
Ok(()) // Success
} Ok(())
} }

View File

@ -391,21 +391,6 @@ impl Page {
&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
Meta::migrate(tx)?;
Navigation::migrate(tx)?;
// Success
Ok(())
}
// Private helpers @TODO move outside // Private helpers @TODO move outside
fn load_gemini(&self, uri: Uri) { fn load_gemini(&self, uri: Uri) {
// Use local namespaces @TODO // Use local namespaces @TODO
@ -938,6 +923,20 @@ impl Page {
// Tools // 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
meta::migrate(tx)?;
navigation::migrate(tx)?;
// Success
Ok(())
}
/// Helper function, extract readable title from [Uri](https://docs.gtk.org/glib/struct.Uri.html) /// Helper function, extract readable title from [Uri](https://docs.gtk.org/glib/struct.Uri.html)
/// ///
/// Useful as common placeholder when page title could not be detected /// Useful as common placeholder when page title could not be detected

View File

@ -178,18 +178,18 @@ impl Meta {
Ok(()) Ok(())
} }
}
// Tools
pub fn migrate(tx: &Transaction) -> Result<(), String> { // Tools
// Migrate self components pub fn migrate(tx: &Transaction) -> Result<(), String> {
if let Err(e) = Database::init(&tx) { // Migrate self components
return Err(e.to_string()); if let Err(e) = Database::init(&tx) {
} return Err(e.to_string());
}
// Delegate migration to childs
// nothing yet.. // Delegate migration to childs
// nothing yet..
// Success
Ok(()) // Success
} Ok(())
} }

View File

@ -168,18 +168,18 @@ impl Navigation {
pub fn request_text(&self) -> GString { pub fn request_text(&self) -> GString {
self.request.text() self.request.text()
} }
}
// Tools
pub fn migrate(tx: &Transaction) -> Result<(), String> { // Tools
// Migrate self components pub fn migrate(tx: &Transaction) -> Result<(), String> {
if let Err(e) = Database::init(&tx) { // Migrate self components
return Err(e.to_string()); if let Err(e) = Database::init(&tx) {
} return Err(e.to_string());
}
// Delegate migration to childs
Request::migrate(tx)?; // Delegate migration to childs
request::migrate(tx)?;
// Success
Ok(()) // Success
} Ok(())
} }

View File

@ -117,18 +117,18 @@ impl Request {
_ => None, _ => None,
} }
} }
}
// Tools
pub fn migrate(tx: &Transaction) -> Result<(), String> { // Tools
// Migrate self components pub fn migrate(tx: &Transaction) -> Result<(), String> {
if let Err(e) = Database::init(tx) { // Migrate self components
return Err(e.to_string()); if let Err(e) = Database::init(tx) {
} return Err(e.to_string());
}
// Delegate migration to childs
Widget::migrate(tx)?; // Delegate migration to childs
widget::migrate(tx)?;
// Success
Ok(()) // Success
} Ok(())
} }

View File

@ -221,18 +221,18 @@ impl Widget {
pub fn text(&self) -> GString { pub fn text(&self) -> GString {
self.gobject.text() self.gobject.text()
} }
}
// Tools
pub fn migrate(tx: &Transaction) -> Result<(), String> { // Tools
// Migrate self components pub fn migrate(tx: &Transaction) -> Result<(), String> {
if let Err(e) = Database::init(&tx) { // Migrate self components
return Err(e.to_string()); if let Err(e) = Database::init(&tx) {
} return Err(e.to_string());
}
// Delegate migration to childs
// nothing yet.. // Delegate migration to childs
// nothing yet..
// Success
Ok(()) // Success
} Ok(())
} }

View File

@ -124,18 +124,18 @@ impl Widget {
pub fn gobject(&self) -> &TabPage { pub fn gobject(&self) -> &TabPage {
&self.gobject &self.gobject
} }
}
// Tools
pub fn migrate(tx: &Transaction) -> Result<(), String> { // Tools
// Migrate self components pub fn migrate(tx: &Transaction) -> Result<(), String> {
if let Err(e) = Database::init(&tx) { // Migrate self components
return Err(e.to_string()); if let Err(e) = Database::init(&tx) {
} return Err(e.to_string());
}
// Delegate migration to childs
// nothing yet.. // Delegate migration to childs
// nothing yet..
// Success
Ok(()) // Success
} Ok(())
} }