From 83fc8893ec59dd0b3169b2038f83deb394286b81 Mon Sep 17 00:00:00 2001 From: Ashley Wulber Date: Wed, 20 Jul 2022 10:21:40 -0400 Subject: [PATCH] fix: use app container created by window & only create dock object from window list if a matching app info is found --- Cargo.lock | 4 ++-- .../cosmic-app-list/src/apps_window/mod.rs | 5 ++++- .../cosmic-app-list/src/dock_object/mod.rs | 19 ++++++++----------- applets/cosmic-app-list/src/main.rs | 9 ++++----- applets/cosmic-app-list/src/wayland.rs | 1 - 5 files changed, 18 insertions(+), 20 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 28482658..54169c86 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2141,7 +2141,7 @@ checksum = "a3f87b73ce11b1619a3c6332f45341e0047173771e8b8b73f87bfeefb7b56244" [[package]] name = "relm4" version = "0.5.0-beta.1" -source = "git+https://github.com/relm4/relm4?branch=next#746d244004e23764294b23519f6f8be1002c1ceb" +source = "git+https://github.com/Relm4/Relm4.git?branch=next#746d244004e23764294b23519f6f8be1002c1ceb" dependencies = [ "async-broadcast", "async-oneshot", @@ -2158,7 +2158,7 @@ dependencies = [ [[package]] name = "relm4-macros" version = "0.5.0-beta.1" -source = "git+https://github.com/relm4/relm4?branch=next#746d244004e23764294b23519f6f8be1002c1ceb" +source = "git+https://github.com/Relm4/Relm4.git?branch=next#746d244004e23764294b23519f6f8be1002c1ceb" dependencies = [ "proc-macro2", "quote", diff --git a/applets/cosmic-app-list/src/apps_window/mod.rs b/applets/cosmic-app-list/src/apps_window/mod.rs index bf72eb94..52f00804 100644 --- a/applets/cosmic-app-list/src/apps_window/mod.rs +++ b/applets/cosmic-app-list/src/apps_window/mod.rs @@ -8,7 +8,6 @@ use gtk4::{ prelude::*, subclass::prelude::*, }; -use tokio::sync::mpsc; mod imp; @@ -43,6 +42,10 @@ impl CosmicAppListWindow { self_ } + pub fn apps_container(&self) -> &AppsContainer { + imp::CosmicAppListWindow::from_instance(&self).inner.get().unwrap() + } + fn setup_shortcuts(&self) { let window = self.clone().upcast::(); let action_quit = gio::SimpleAction::new("quit", None); diff --git a/applets/cosmic-app-list/src/dock_object/mod.rs b/applets/cosmic-app-list/src/dock_object/mod.rs index 33975b51..63ac9400 100644 --- a/applets/cosmic-app-list/src/dock_object/mod.rs +++ b/applets/cosmic-app-list/src/dock_object/mod.rs @@ -78,9 +78,9 @@ impl DockObject { imp.saved.replace(is_saved); } - pub fn from_window_list(results: BoxedWindowList) -> Self { - let appinfo = if let Some(first) = results.0.get(0) { - xdg::BaseDirectories::new() + pub fn from_window_list(results: BoxedWindowList) -> Option { + if let Some(first) = results.0.get(0) { + return xdg::BaseDirectories::new() .expect("could not access XDG Base directory") .get_data_dirs() .iter_mut() @@ -100,7 +100,8 @@ impl DockObject { .file_stem() .and_then(|s| s.to_str().map(|s| s.to_string()))).as_ref() { - return Some(app_info); + return Some(Object::new(&[("appinfo", &app_info), ("active", &results)]) + .expect("Failed to create `DockObject`.")); } } } @@ -108,13 +109,9 @@ impl DockObject { } None }) - .next() - } else { - None - }; - - Object::new(&[("appinfo", &appinfo), ("active", &results)]) - .expect("Failed to create `DockObject`.") + .next(); + } + None } pub fn set_popover(&self, b: bool) { diff --git a/applets/cosmic-app-list/src/main.rs b/applets/cosmic-app-list/src/main.rs index 8dc79a65..a2ea264d 100644 --- a/applets/cosmic-app-list/src/main.rs +++ b/applets/cosmic-app-list/src/main.rs @@ -66,7 +66,6 @@ fn main() { let (tx, rx) = glib::MainContext::channel(glib::Priority::default()); let window = CosmicAppListWindow::new(app); - let apps_container = apps_container::AppsContainer::new(); let wayland_tx = wayland::spawn_toplevels(); WAYLAND_TX.set(wayland_tx).unwrap(); @@ -78,6 +77,7 @@ fn main() { TX.set(tx.clone()).unwrap(); rx.attach(None, glib::clone!(@weak window => @default-return glib::prelude::Continue(true), move |event| { + let apps_container = window.apps_container(); let should_apply_changes = match event { AppListEvent::Favorite((name, should_favorite)) => { let saved_app_model = apps_container.model(DockListType::Saved); @@ -184,7 +184,7 @@ fn main() { let model_len = active_app_model.n_items(); let new_results: Vec = stack_active .into_iter() - .map(|v| DockObject::from_window_list(v).upcast()) + .filter_map(|v| DockObject::from_window_list(v).map(|o| o.upcast())) .collect(); active_app_model.splice(0, model_len, &new_results[..]); true @@ -210,7 +210,7 @@ fn main() { } }; if should_apply_changes { - dbg!(&cached_results); + // dbg!(&cached_results); // build active app stacks for each app let stack_active = cached_results.iter().fold( BTreeMap::new(), @@ -271,9 +271,8 @@ fn main() { let model_len = active_app_model.n_items(); let new_results: Vec = stack_active .into_iter() - .map(|v| DockObject::from_window_list(v).upcast()) + .filter_map(|v| DockObject::from_window_list(v).map(|o| o.upcast())) .collect(); - dbg!(&new_results); active_app_model.splice(0, model_len, &new_results[..]); } diff --git a/applets/cosmic-app-list/src/wayland.rs b/applets/cosmic-app-list/src/wayland.rs index 096e0db1..4171b130 100644 --- a/applets/cosmic-app-list/src/wayland.rs +++ b/applets/cosmic-app-list/src/wayland.rs @@ -238,7 +238,6 @@ impl Dispatch for State { _: &Connection, _: &QueueHandle, ) { - dbg!(&event); match event { zcosmic_toplevel_info_v1::Event::Toplevel { toplevel } => { state.toplevels.push(Toplevel {