Browse Source

move save method to the application construct event

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

68
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,8 +119,35 @@ impl App {
} }
}); });
// @TODO save session to DB // Save current session to DB
// self.app.connect_window_removed(|_, _| todo!()); // app.connect_window_added()
/*
app.connect_window_removed({
let database = database.clone();
move |_, _| {
// Cleanup previous record
match database.records() {
Ok(_) => {
// Delegate clean action to children components
// self.browser.clean(app_id) @TODO
// ..
// Create new record
match database.add() {
Ok(_) => {
// let app_id = self.database.last_insert_id();
// Delegate save action to children components
// self.browser.save(app_id) @TODO
// ..
}
Err(error) => panic!("{error}"), // @TODO
}
}
Err(error) => panic!("{error}"), // @TODO
}
}
});*/
// Return activated App struct // Return activated App struct
Self { Self {
@ -122,7 +156,7 @@ impl App {
// Components // Components
// browser, // browser,
// Extras // Extras
database, // database,
// GTK // GTK
app, app,
} }
@ -132,28 +166,4 @@ impl App {
pub fn run(&self) -> ExitCode { pub fn run(&self) -> ExitCode {
self.app.run() self.app.run()
} }
pub fn save(&self) {
// Cleanup previous record
match self.database.clean() {
Ok(_) => {
// Delegate clean action to children components
// self.browser.clean(app_id) @TODO
// ..
// Create new record
match self.database.add() {
Ok(_) => {
// let app_id = self.database.last_insert_id();
// Delegate save action to children components
// self.browser.save(app_id) @TODO
// ..
}
Err(error) => panic!("{error}"), // @TODO
}
}
Err(error) => panic!("{error}"), // @TODO
}
}
} }

Loading…
Cancel
Save