Separate config state (#118)

* change internal api
* frontend now keeps and more correctly reflects backend state
This commit is contained in:
Ferdinand Schober
2024-05-03 11:27:06 +02:00
committed by GitHub
parent 1e4312b3ce
commit 5318f5a02d
15 changed files with 809 additions and 507 deletions

View File

@@ -8,7 +8,7 @@ use std::{
process, str,
};
use crate::frontend::gtk::window::Window;
use crate::frontend::{gtk::window::Window, FrontendRequest};
use adw::Application;
use gtk::{
@@ -113,34 +113,35 @@ fn build_ui(app: &Application) {
}
});
let window = Window::new(app);
window.imp().stream.borrow_mut().replace(tx);
let window = Window::new(app, tx);
window.request(FrontendRequest::Enumerate());
glib::spawn_future_local(clone!(@weak window => async move {
loop {
let notify = receiver.recv().await.unwrap_or_else(|_| process::exit(1));
match notify {
FrontendEvent::Activated(handle, active) => {
window.activate_client(handle, active);
}
FrontendEvent::Created(handle, client) => {
window.new_client(handle, client, false);
},
FrontendEvent::Updated(handle, client) => {
window.update_client(handle, client);
}
FrontendEvent::Error(e) => {
window.show_toast(e.as_str());
FrontendEvent::Created(handle, client, state) => {
window.new_client(handle, client, state);
},
FrontendEvent::Deleted(client) => {
window.delete_client(client);
}
FrontendEvent::Updated(handle, client) => {
window.update_client_config(handle, client);
}
FrontendEvent::StateChange(handle, state) => {
window.update_client_state(handle, state);
}
FrontendEvent::Error(e) => {
window.show_toast(e.as_str());
},
FrontendEvent::Enumerate(clients) => {
for (handle, client, active) in clients {
for (handle, client, state) in clients {
if window.client_idx(handle).is_some() {
window.activate_client(handle, active);
window.update_client(handle, client);
window.update_client_config(handle, client);
window.update_client_state(handle, state);
} else {
window.new_client(handle, client, active);
window.new_client(handle, client, state);
}
}
},