show active apps

This commit is contained in:
Ashley Wulber 2021-12-21 13:01:32 -05:00
parent ad6f147546
commit 03300c788a
9 changed files with 113 additions and 339 deletions

View file

@ -5,6 +5,7 @@ use gtk4::glib;
use gtk4::prelude::*;
use gtk4::subclass::prelude::*;
use once_cell::sync::Lazy;
use std::cell::Cell;
use std::cell::RefCell;
// Object holding the state
@ -12,6 +13,7 @@ use std::cell::RefCell;
pub struct DockObject {
appinfo: RefCell<Option<DesktopAppInfo>>,
active: RefCell<BoxedSearchResults>,
saved: Cell<bool>,
}
// The central trait for subclassing a GObject
@ -49,6 +51,13 @@ impl ObjectImpl for DockObject {
// The property can be read and written to
ParamFlags::READWRITE,
),
ParamSpec::new_boolean(
"saved",
"saved",
"Indicates whether app is saved to the dock",
false,
ParamFlags::READWRITE,
),
]
});
PROPERTIES.as_ref()
@ -66,6 +75,10 @@ impl ObjectImpl for DockObject {
let active = value.get().expect("Value needs to be BoxedSearchResults");
self.active.replace(active);
}
"saved" => {
self.saved
.replace(value.get().expect("Value needs to be a boolean"));
}
_ => unimplemented!(),
}
}
@ -73,6 +86,8 @@ impl ObjectImpl for DockObject {
fn property(&self, _obj: &Self::Type, _id: usize, pspec: &ParamSpec) -> Value {
match pspec.name() {
"appinfo" => self.appinfo.borrow().to_value(),
"active" => self.active.borrow().to_value(),
"saved" => self.saved.get().to_value(),
_ => unimplemented!(),
}
}

View file

@ -12,7 +12,8 @@ glib::wrapper! {
impl DockObject {
pub fn new(appinfo: DesktopAppInfo) -> Self {
Object::new(&[("appinfo", &Some(appinfo))]).expect("Failed to create `DockObject`.")
Object::new(&[("appinfo", &Some(appinfo)), ("saved", &true)])
.expect("Failed to create `DockObject`.")
}
pub fn from_search_results(results: BoxedSearchResults) -> Self {
@ -23,7 +24,6 @@ impl DockObject {
.iter_mut()
.filter_map(|xdg_data_path| {
xdg_data_path.push("applications");
dbg!(&xdg_data_path);
std::fs::read_dir(xdg_data_path).ok()
})
.flatten()
@ -35,7 +35,7 @@ impl DockObject {
if app_info.should_show()
&& first.description.as_str() == app_info.name().as_str()
{
return Some(DockObject::new(app_info));
return Some(app_info);
}
}
}
@ -47,6 +47,7 @@ impl DockObject {
} else {
None
};
dbg!(&appinfo);
Object::new(&[("appinfo", &appinfo), ("active", &results)])
.expect("Failed to create `DockObject`.")
}