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; @@ -7,7 +7,6 @@ use browser::Browser;
use database::Database;
use gtk::{
// gio::SimpleAction,
glib::ExitCode,
prelude::{ActionExt, ApplicationExt, ApplicationExtManual, GtkApplicationExt, GtkWindowExt},
Application,
@ -24,7 +23,7 @@ pub struct App { @@ -24,7 +23,7 @@ pub struct App {
// Components
// browser: Arc<Browser>,
// Extras
database: Arc<Database>,
// database: Arc<Database>,
// GTK
app: Application,
}
@ -100,6 +99,14 @@ impl App { @@ -100,6 +99,14 @@ impl App {
let browser = browser.clone();
move |this| {
// @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
browser.widget().set_application(Some(this));
@ -112,37 +119,21 @@ impl App { @@ -112,37 +119,21 @@ impl App {
}
});
// @TODO save session to DB
// self.app.connect_window_removed(|_, _| 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()
}
pub fn save(&self) {
// Save current session to DB
// app.connect_window_added()
/*
app.connect_window_removed({
let database = database.clone();
move |_, _| {
// Cleanup previous record
match self.database.clean() {
match database.records() {
Ok(_) => {
// Delegate clean action to children components
// self.browser.clean(app_id) @TODO
// ..
// Create new record
match self.database.add() {
match database.add() {
Ok(_) => {
// let app_id = self.database.last_insert_id();
@ -156,4 +147,23 @@ impl App { @@ -156,4 +147,23 @@ impl App {
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