fix: use app container created by window & only create dock object from window list if a matching app info is found

This commit is contained in:
Ashley Wulber 2022-07-20 10:21:40 -04:00
parent adc02df64f
commit 83fc8893ec
No known key found for this signature in database
GPG key ID: 5216D4F46A90A820
5 changed files with 18 additions and 20 deletions

4
Cargo.lock generated
View file

@ -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",

View file

@ -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::<gtk4::Window>();
let action_quit = gio::SimpleAction::new("quit", None);

View file

@ -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<Self> {
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) {

View file

@ -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<glib::Object> = 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<glib::Object> = 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[..]);
}

View file

@ -238,7 +238,6 @@ impl Dispatch<ZcosmicToplevelInfoV1, ()> for State {
_: &Connection,
_: &QueueHandle<Self>,
) {
dbg!(&event);
match event {
zcosmic_toplevel_info_v1::Event::Toplevel { toplevel } => {
state.toplevels.push(Toplevel {