fully implement sys tray
This commit is contained in:
parent
712a2d1e70
commit
f5dcfc455a
@ -157,6 +157,7 @@
|
||||
"flatpak_ref_install_dialog_cancel_label": "Cancel",
|
||||
"pikman_indicator_apt_count_item_label": "APT Updates: {NUM}",
|
||||
"pikman_indicator_flatpak_count_item_label": "Flatpak Updates: {NUM}",
|
||||
"pikman_indicator_flatpak_item_label_calculating": "calculating",
|
||||
"pikman_indicator_open_item_label": "Open",
|
||||
"pikman_indicator_exit_item_label": "Exit"
|
||||
}
|
@ -32,7 +32,10 @@ pub fn apt_update_page(
|
||||
window: adw::ApplicationWindow,
|
||||
retry_signal_action: &SimpleAction,
|
||||
flatpak_retry_signal_action: &SimpleAction,
|
||||
flatpak_ran_once: Rc<RefCell<bool>>
|
||||
flatpak_ran_once: Rc<RefCell<bool>>,
|
||||
update_sys_tray: &SimpleAction,
|
||||
apt_update_count: &Rc<RefCell<i32>>,
|
||||
flatpak_update_count: &Rc<RefCell<i32>>,
|
||||
) -> gtk::Box {
|
||||
let (update_percent_sender, update_percent_receiver) = async_channel::unbounded::<String>();
|
||||
let update_percent_sender = update_percent_sender.clone();
|
||||
@ -42,6 +45,8 @@ pub fn apt_update_page(
|
||||
let (get_upgradable_sender, get_upgradable_receiver) = async_channel::unbounded();
|
||||
let get_upgradable_sender = get_upgradable_sender.clone();
|
||||
|
||||
(*apt_update_count.borrow_mut() = 0);
|
||||
|
||||
let excluded_updates_vec: Rc<RefCell<Vec<String>>> = Rc::new(RefCell::new(Vec::new()));
|
||||
|
||||
thread::spawn(move || {
|
||||
@ -385,6 +390,12 @@ pub fn apt_update_page(
|
||||
viewport_bin,
|
||||
#[strong]
|
||||
excluded_updates_vec,
|
||||
#[strong]
|
||||
update_sys_tray,
|
||||
#[strong]
|
||||
apt_update_count,
|
||||
#[strong]
|
||||
flatpak_update_count,
|
||||
async move {
|
||||
while let Ok(state) = get_upgradable_receiver.recv().await {
|
||||
viewport_bin.set_child(Some(&packages_viewport));
|
||||
@ -441,8 +452,10 @@ pub fn apt_update_page(
|
||||
),
|
||||
);
|
||||
packages_boxedlist.append(&apt_row);
|
||||
(*apt_update_count.borrow_mut() += 1);
|
||||
if state.is_last {
|
||||
packages_boxedlist.set_sensitive(true);
|
||||
update_sys_tray.activate(Some(&glib::Variant::array_from_fixed_array(&[*apt_update_count.borrow(),*flatpak_update_count.borrow()])));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -96,6 +96,9 @@ pub fn build_ui(app: &Application) {
|
||||
|
||||
// Systray
|
||||
|
||||
let apt_update_count = Rc::new(RefCell::new(0));
|
||||
let flatpak_update_count = Rc::new(RefCell::new(0));
|
||||
|
||||
let update_sys_tray = gio::SimpleAction::new("sys_tray", Some(glib::VariantTy::ARRAY));
|
||||
|
||||
let (tray_service_sender, tray_service_receiver) = async_channel::unbounded();
|
||||
@ -111,6 +114,51 @@ pub fn build_ui(app: &Application) {
|
||||
|
||||
tray_service.spawn();
|
||||
|
||||
update_sys_tray.connect_activate(clone!(
|
||||
#[strong]
|
||||
tray_handle,
|
||||
move |_,param| {
|
||||
let array: &[i32] = param.unwrap().fixed_array().unwrap();
|
||||
let vec = array.to_vec();
|
||||
let apt_update_count = vec[0];
|
||||
let flatpak_update_count = vec[1];
|
||||
let tray_icon = if apt_update_count + flatpak_update_count > 1 {
|
||||
Some("update-high".into())
|
||||
} else {
|
||||
Some("update-none".into())
|
||||
};
|
||||
tray_handle.update(|tray: &mut PikmanTray| {
|
||||
tray.icon_name = tray_icon;
|
||||
tray.apt_item_label = Some(strfmt::strfmt(
|
||||
&t!("pikman_indicator_apt_count_item_label").to_string(),
|
||||
&std::collections::HashMap::from([
|
||||
(
|
||||
"NUM".to_string(),
|
||||
match apt_update_count {
|
||||
-1 => t!("pikman_indicator_flatpak_item_label_calculating").into(),
|
||||
_ => apt_update_count.to_string(),
|
||||
},
|
||||
),
|
||||
]),
|
||||
)
|
||||
.unwrap());
|
||||
tray.flatpak_item_label = Some(strfmt::strfmt(
|
||||
&t!("pikman_indicator_flatpak_count_item_label").to_string(),
|
||||
&std::collections::HashMap::from([
|
||||
(
|
||||
"NUM".to_string(),
|
||||
match flatpak_update_count {
|
||||
-1 => t!("pikman_indicator_flatpak_item_label_calculating").into(),
|
||||
_ => flatpak_update_count.to_string(),
|
||||
},
|
||||
),
|
||||
]),
|
||||
)
|
||||
.unwrap());
|
||||
});
|
||||
}));
|
||||
update_sys_tray.activate(Some(&glib::Variant::array_from_fixed_array(&[-1,-1])));
|
||||
|
||||
thread::spawn(move || loop {
|
||||
match Command::new("ping").arg("google.com").arg("-c 1").output() {
|
||||
Ok(t) if t.status.success() => internet_loop_sender
|
||||
@ -315,10 +363,19 @@ pub fn build_ui(app: &Application) {
|
||||
flatpak_retry_signal_action,
|
||||
#[strong]
|
||||
flatpak_update_view_stack_bin,
|
||||
#[strong]
|
||||
update_sys_tray,
|
||||
#[strong]
|
||||
apt_update_count,
|
||||
#[strong]
|
||||
flatpak_update_count,
|
||||
move |_, _| {
|
||||
flatpak_update_view_stack_bin.set_child(Some(&flatpak_update_page::flatpak_update_page(
|
||||
window,
|
||||
&flatpak_retry_signal_action,
|
||||
&update_sys_tray,
|
||||
&apt_update_count,
|
||||
&flatpak_update_count,
|
||||
)));
|
||||
}
|
||||
));
|
||||
@ -341,12 +398,21 @@ pub fn build_ui(app: &Application) {
|
||||
apt_update_view_stack_bin,
|
||||
#[weak]
|
||||
flatpak_ran_once,
|
||||
#[strong]
|
||||
update_sys_tray,
|
||||
#[strong]
|
||||
apt_update_count,
|
||||
#[strong]
|
||||
flatpak_update_count,
|
||||
move |_, _| {
|
||||
apt_update_view_stack_bin.set_child(Some(&apt_update_page::apt_update_page(
|
||||
window,
|
||||
&apt_retry_signal_action,
|
||||
&flatpak_retry_signal_action,
|
||||
flatpak_ran_once,
|
||||
&update_sys_tray,
|
||||
&apt_update_count,
|
||||
&flatpak_update_count,
|
||||
)));
|
||||
}
|
||||
));
|
||||
@ -356,6 +422,9 @@ pub fn build_ui(app: &Application) {
|
||||
&apt_retry_signal_action,
|
||||
&flatpak_retry_signal_action,
|
||||
flatpak_ran_once,
|
||||
&update_sys_tray,
|
||||
&apt_update_count,
|
||||
&flatpak_update_count,
|
||||
)));
|
||||
|
||||
// Add to stack switcher
|
||||
@ -405,44 +474,6 @@ pub fn build_ui(app: &Application) {
|
||||
let flatpak_manage_page_toggle_button = add_content_button(&window_adw_stack, false, "flatpak_manage_page".to_string(), t!("flatpak_manage_page_title").to_string(), &null_toggle_button);
|
||||
window_adw_view_switcher_sidebar_box.append(&flatpak_manage_page_toggle_button);
|
||||
|
||||
update_sys_tray.connect_activate(clone!(
|
||||
#[strong]
|
||||
tray_handle,
|
||||
move |_,param| {
|
||||
let array: &[i32] = param.unwrap().fixed_array().unwrap();
|
||||
let vec = array.to_vec();
|
||||
let apt_update_count = vec[0];
|
||||
let flatpak_update_count = vec[1];
|
||||
let tray_icon = if apt_update_count + flatpak_update_count > 1 {
|
||||
Some("update-high".into())
|
||||
} else {
|
||||
Some("update-none".into())
|
||||
};
|
||||
tray_handle.update(|tray: &mut PikmanTray| {
|
||||
tray.icon_name = tray_icon;
|
||||
tray.apt_item_label = Some(strfmt::strfmt(
|
||||
&t!("pikman_indicator_apt_count_item_label").to_string(),
|
||||
&std::collections::HashMap::from([
|
||||
(
|
||||
"NUM".to_string(),
|
||||
apt_update_count.to_string(),
|
||||
),
|
||||
]),
|
||||
)
|
||||
.unwrap());
|
||||
tray.flatpak_item_label = Some(strfmt::strfmt(
|
||||
&t!("pikman_indicator_flatpak_count_item_label").to_string(),
|
||||
&std::collections::HashMap::from([
|
||||
(
|
||||
"NUM".to_string(),
|
||||
flatpak_update_count.to_string(),
|
||||
),
|
||||
]),
|
||||
)
|
||||
.unwrap());
|
||||
});
|
||||
}));
|
||||
|
||||
app.connect_command_line(clone!(
|
||||
#[strong]
|
||||
apt_manage_page_toggle_button,
|
||||
@ -506,6 +537,26 @@ pub fn build_ui(app: &Application) {
|
||||
}
|
||||
}
|
||||
));
|
||||
|
||||
let tray_service_context = MainContext::default();
|
||||
// The main loop executes the asynchronous block
|
||||
tray_service_context.spawn_local(clone!(
|
||||
#[strong]
|
||||
window,
|
||||
async move {
|
||||
while let Ok(state) = tray_service_receiver.recv().await {
|
||||
match state.as_str() {
|
||||
"open" => {
|
||||
if !window.is_visible() {
|
||||
window.present();
|
||||
}
|
||||
}
|
||||
_ => todo!()
|
||||
}
|
||||
}
|
||||
}
|
||||
));
|
||||
|
||||
}
|
||||
|
||||
fn add_content_button(window_adw_stack: >k::Stack, active: bool, name: String, title: String, null_toggle_button: >k::ToggleButton) -> gtk::ToggleButton {
|
||||
|
@ -30,7 +30,12 @@ pub struct FlatpakRefStruct {
|
||||
pub fn flatpak_update_page(
|
||||
window: adw::ApplicationWindow,
|
||||
retry_signal_action: &SimpleAction,
|
||||
update_sys_tray: &SimpleAction,
|
||||
apt_update_count: &Rc<RefCell<i32>>,
|
||||
flatpak_update_count: &Rc<RefCell<i32>>,
|
||||
) -> gtk::Box {
|
||||
(*flatpak_update_count.borrow_mut() = 0);
|
||||
|
||||
let (appstream_sync_percent_sender, appstream_sync_percent_receiver) =
|
||||
async_channel::unbounded::<u32>();
|
||||
let appstream_sync_percent_sender = appstream_sync_percent_sender.clone();
|
||||
@ -369,6 +374,12 @@ pub fn flatpak_update_page(
|
||||
viewport_bin,
|
||||
#[strong]
|
||||
packages_viewport,
|
||||
#[strong]
|
||||
update_sys_tray,
|
||||
#[strong]
|
||||
apt_update_count,
|
||||
#[strong]
|
||||
flatpak_update_count,
|
||||
async move {
|
||||
while let Ok(state) = appstream_sync_status_receiver.recv().await {
|
||||
match state.as_ref() {
|
||||
@ -539,6 +550,7 @@ pub fn flatpak_update_page(
|
||||
);
|
||||
|
||||
packages_boxedlist.append(&flatpak_row);
|
||||
(*flatpak_update_count.borrow_mut() += 1);
|
||||
if flatref_struct.is_system && flatref_struct.is_last
|
||||
{
|
||||
system_last_triggered = true
|
||||
@ -692,6 +704,7 @@ pub fn flatpak_update_page(
|
||||
),
|
||||
);
|
||||
packages_boxedlist.append(&flatpak_row);
|
||||
(*flatpak_update_count.borrow_mut() += 1);
|
||||
if !flatref_struct.is_system && flatref_struct.is_last
|
||||
{
|
||||
user_last_triggered = true
|
||||
@ -702,6 +715,7 @@ pub fn flatpak_update_page(
|
||||
}
|
||||
if user_last_triggered && system_last_triggered {
|
||||
packages_boxedlist.set_sensitive(true);
|
||||
update_sys_tray.activate(Some(&glib::Variant::array_from_fixed_array(&[*apt_update_count.borrow(),*flatpak_update_count.borrow()])));
|
||||
}
|
||||
flatpak_update_dialog.close();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user