Browse Source

move save method to the application construct event

master
yggverse 2 months ago
parent
commit
caee762103
  1. 62
      src/app.rs

62
src/app.rs

@ -7,7 +7,6 @@ use browser::Browser;
use database::Database; use database::Database;
use gtk::{ use gtk::{
// gio::SimpleAction,
glib::ExitCode, glib::ExitCode,
prelude::{ActionExt, ApplicationExt, ApplicationExtManual, GtkApplicationExt, GtkWindowExt}, prelude::{ActionExt, ApplicationExt, ApplicationExtManual, GtkApplicationExt, GtkWindowExt},
Application, Application,
@ -24,7 +23,7 @@ pub struct App {
// Components // Components
// browser: Arc<Browser>, // browser: Arc<Browser>,
// Extras // Extras
database: Arc<Database>, // database: Arc<Database>,
// GTK // GTK
app: Application, app: Application,
} }
@ -100,6 +99,14 @@ impl App {
let browser = browser.clone(); let browser = browser.clone();
move |this| { move |this| {
// @TODO restore previous session from DB // @TODO restore previous session from DB
match database.records() {
Ok(records) => {
for record in records {
println!("{:?}", record.id) // @TODO
}
}
Err(e) => panic!("{e}"),
}
// Activate events // Activate events
browser.widget().set_application(Some(this)); browser.widget().set_application(Some(this));
@ -112,37 +119,21 @@ impl App {
} }
}); });
// @TODO save session to DB // Save current session to DB
// self.app.connect_window_removed(|_, _| todo!()); // app.connect_window_added()
/*
// Return activated App struct app.connect_window_removed({
Self { let database = database.clone();
// Actions (SimpleAction) move |_, _| {
// action_update: action_update.simple(),
// Components
// browser,
// Extras
database,
// GTK
app,
}
}
// Actions
pub fn run(&self) -> ExitCode {
self.app.run()
}
pub fn save(&self) {
// Cleanup previous record // Cleanup previous record
match self.database.clean() { match database.records() {
Ok(_) => { Ok(_) => {
// Delegate clean action to children components // Delegate clean action to children components
// self.browser.clean(app_id) @TODO // self.browser.clean(app_id) @TODO
// .. // ..
// Create new record // Create new record
match self.database.add() { match database.add() {
Ok(_) => { Ok(_) => {
// let app_id = self.database.last_insert_id(); // let app_id = self.database.last_insert_id();
@ -156,4 +147,23 @@ impl App {
Err(error) => panic!("{error}"), // @TODO Err(error) => panic!("{error}"), // @TODO
} }
} }
});*/
// Return activated App struct
Self {
// Actions (SimpleAction)
// action_update: action_update.simple(),
// Components
// browser,
// Extras
// database,
// GTK
app,
}
}
// Actions
pub fn run(&self) -> ExitCode {
self.app.run()
}
} }

Loading…
Cancel
Save