define startup/shutdown events

This commit is contained in:
yggverse 2024-10-04 20:12:52 +03:00
parent 00e916dc7c
commit 11f2f1eae7

View File

@ -101,6 +101,13 @@ impl App {
// Init events // Init events
app.connect_activate({ app.connect_activate({
let action_update = action_update.simple(); let action_update = action_update.simple();
move |_| {
// Make initial update
action_update.activate(None);
}
});
app.connect_startup({
let browser = browser.clone(); let browser = browser.clone();
let database = database.clone(); let database = database.clone();
move |this| { move |this| {
@ -119,23 +126,20 @@ impl App {
// Show main widget // Show main widget
browser.widget().present(); browser.widget().present();
// Make initial update
action_update.activate(None);
} }
}); });
// Save current session to DB app.connect_shutdown({
app.connect_window_removed({
// let browser = browser.clone(); // let browser = browser.clone();
let database = database.clone(); let database = database.clone();
move |_, _| { move |_| {
match database.records() { match database.records() {
Ok(records) => { Ok(records) => {
// Cleanup previous records // Cleanup previous session records
for record in records { for record in records {
match database.delete(record.id) { match database.delete(record.id) {
Ok(_) => { Ok(_) => {
// Delegate clean action to children components // Delegate clean action to children components
// browser.clean(app_id); @TODO // browser.clean(app_id); @TODO
} }
@ -143,7 +147,7 @@ impl App {
} }
} }
// Create new record // Save current session to DB
match database.add() { match database.add() {
Ok(_) => { Ok(_) => {
// let app_id = database.last_insert_id(); // let app_id = database.last_insert_id();