From 0cea668b3c9dcd84806876d2a6fd57d4af0eb4a1 Mon Sep 17 00:00:00 2001 From: Ward from fusion-voyager-3 Date: Sat, 5 Oct 2024 15:45:26 +0300 Subject: [PATCH] Add update intervals + fix window clipping --- .github/release-nest-v3 | 2 +- Cargo.lock | 2 +- Cargo.toml | 2 +- ...kaos-linux.pikmanupdatemanager.gschema.xml | 11 +- debian/changelog | 2 +- main.sh | 2 +- src/bin/gui/apt_manage_page/mod.rs | 16 ++- src/bin/gui/build_ui/mod.rs | 133 +++++++++++++----- 8 files changed, 119 insertions(+), 51 deletions(-) diff --git a/.github/release-nest-v3 b/.github/release-nest-v3 index f11c82a..9a03714 100644 --- a/.github/release-nest-v3 +++ b/.github/release-nest-v3 @@ -1 +1 @@ -9 \ No newline at end of file +10 \ No newline at end of file diff --git a/Cargo.lock b/Cargo.lock index d067452..7de8334 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1736,7 +1736,7 @@ checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" [[package]] name = "pikman-update-manager" -version = "1.0.0" +version = "1.0.1" dependencies = [ "async-channel", "async-trait", diff --git a/Cargo.toml b/Cargo.toml index 32cbdc3..f6de282 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "pikman-update-manager" -version = "1.0.0" +version = "1.0.1" edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/data/com.github.pikaos-linux.pikmanupdatemanager.gschema.xml b/data/com.github.pikaos-linux.pikmanupdatemanager.gschema.xml index 033a9b9..71ad303 100644 --- a/data/com.github.pikaos-linux.pikmanupdatemanager.gschema.xml +++ b/data/com.github.pikaos-linux.pikmanupdatemanager.gschema.xml @@ -13,12 +13,13 @@ false Default window maximized behaviour - + true - Show PikaOS Welcome on startup. - - Show PikaOS Welcome on startup. - + Default window maximized behaviour + + + 22000000 + Update intervals in ms \ No newline at end of file diff --git a/debian/changelog b/debian/changelog index e6848cb..51df7f8 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,4 +1,4 @@ -pikman-update-manager (1.0.0-100pika4) pikauwu; urgency=medium +pikman-update-manager (1.0.1-100pika1) pikauwu; urgency=medium * initial release diff --git a/main.sh b/main.sh index 8f252d3..85e350b 100755 --- a/main.sh +++ b/main.sh @@ -2,7 +2,7 @@ set -e -VERSION="1.0.0" +VERSION="1.0.1" source ./pika-build-config.sh diff --git a/src/bin/gui/apt_manage_page/mod.rs b/src/bin/gui/apt_manage_page/mod.rs index 0713d2e..7fdd619 100644 --- a/src/bin/gui/apt_manage_page/mod.rs +++ b/src/bin/gui/apt_manage_page/mod.rs @@ -457,23 +457,25 @@ pub fn apt_manage_page( let item = selection.downcast_ref::().unwrap(); let apt_src: Ref = item.borrow(); match apt_src.deref() { - AptSourceConfig::DEB822(src) => { - match &src.signed_by { - Some(t) => _command = duct::cmd!( + AptSourceConfig::DEB822(src) => match &src.signed_by { + Some(t) => { + _command = duct::cmd!( "pkexec", "/usr/lib/pika/pikman-update-manager/scripts/modify_repo.sh", "delete_deb822", &src.filepath, t - ), - None => _command = duct::cmd!( + ) + } + None => { + _command = duct::cmd!( "pkexec", "/usr/lib/pika/pikman-update-manager/scripts/modify_repo.sh", "delete_legacy", &src.filepath - ), + ) } - } + }, AptSourceConfig::Legacy(list) => { _command = duct::cmd!( "pkexec", diff --git a/src/bin/gui/build_ui/mod.rs b/src/bin/gui/build_ui/mod.rs index f67ce23..2d2d6de 100644 --- a/src/bin/gui/build_ui/mod.rs +++ b/src/bin/gui/build_ui/mod.rs @@ -11,6 +11,9 @@ use ksni; use std::cell::RefCell; use std::process::Command; use std::rc::Rc; +use std::sync::atomic::AtomicBool; +use std::sync::Arc; +use std::sync::Mutex; use std::thread; #[derive(Debug)] @@ -83,15 +86,30 @@ impl ksni::Tray for PikmanTray { } } +enum ConstantLoopMessage { + InternetStatus(bool), + RefreshRequest, +} + pub fn build_ui(app: &Application) { // setup glib glib::set_prgname(Some(t!("application_name").to_string())); glib::set_application_name(&t!("application_name").to_string()); let glib_settings = gio::Settings::new(APP_ID); + let automatically_check_for_updates_arc = + Arc::new(AtomicBool::new(glib_settings.boolean("check-for-updates"))); + let update_interval_arc = Arc::new(Mutex::new(glib_settings.int("update-interval"))); let internet_connected = Rc::new(RefCell::new(false)); - let (internet_loop_sender, internet_loop_receiver) = async_channel::unbounded(); - let internet_loop_sender = internet_loop_sender.clone(); + + let (constant_loop_sender, constant_loop_receiver) = async_channel::unbounded(); + let constant_loop_sender_clone0 = constant_loop_sender.clone(); + let constant_loop_sender_clone1 = constant_loop_sender.clone(); + + let refresh_button = gtk::Button::builder() + .icon_name("view-refresh-symbolic") + .tooltip_text(t!("refresh_button_tooltip_text")) + .build(); // Systray @@ -116,6 +134,8 @@ pub fn build_ui(app: &Application) { update_sys_tray.connect_activate(clone!( #[strong] tray_handle, + #[strong] + refresh_button, move |_, param| { let array: &[i32] = param.unwrap().fixed_array().unwrap(); let vec = array.to_vec(); @@ -155,43 +175,94 @@ pub fn build_ui(app: &Application) { .unwrap(), ); }); + if apt_update_count == -1 || flatpak_update_count == -1 { + refresh_button.set_sensitive(false); + refresh_button.set_tooltip_text(Some( + &t!("pikman_indicator_flatpak_item_label_calculating").to_string(), + )); + } else { + refresh_button.set_sensitive(true); + refresh_button + .set_tooltip_text(Some(&t!("refresh_button_tooltip_text").to_string())); + } } )); update_sys_tray.activate(Some(&glib::Variant::array_from_fixed_array(&[-1, -1]))); + // internet check loop + thread::spawn(move || { + let mut last_result = false; + loop { + if last_result == true { + std::thread::sleep(std::time::Duration::from_secs(60)); + } + + let check_internet_connection_cli = Command::new("ping") + .arg("iso.pika-os.com") + .arg("-c 1") + .output() + .expect("failed to execute process"); + if check_internet_connection_cli.status.success() { + constant_loop_sender_clone0 + .send_blocking(ConstantLoopMessage::InternetStatus(true)) + .expect("The channel needs to be open."); + last_result = true + } else { + constant_loop_sender_clone0 + .send_blocking(ConstantLoopMessage::InternetStatus(false)) + .expect("The channel needs to be open."); + last_result = false + } + } + }); + + // update interval loop thread::spawn(move || loop { - match Command::new("ping").arg("google.com").arg("-c 1").output() { - Ok(t) if t.status.success() => internet_loop_sender - .send_blocking(true) - .expect("The channel needs to be open"), - _ => internet_loop_sender - .send_blocking(false) - .expect("The channel needs to be open"), - }; - thread::sleep(std::time::Duration::from_secs(5)); + let automatically_check_for_updates = + automatically_check_for_updates_arc.load(std::sync::atomic::Ordering::Relaxed); + if automatically_check_for_updates { + match update_interval_arc.lock() { + Ok(update_interval) => { + std::thread::sleep(std::time::Duration::from_millis(*update_interval as u64)); + constant_loop_sender_clone1 + .send_blocking(ConstantLoopMessage::RefreshRequest) + .expect("The channel needs to be open."); + } + Err(_) => {} + } + } }); let window_banner = Banner::builder().revealed(false).build(); let internet_connected_status = internet_connected.clone(); - let internet_loop_context = MainContext::default(); + let constant_loop_context = MainContext::default(); // The main loop executes the asynchronous block - internet_loop_context.spawn_local(clone!( + constant_loop_context.spawn_local(clone!( #[weak] window_banner, + #[weak] + refresh_button, async move { - while let Ok(state) = internet_loop_receiver.recv().await { + while let Ok(message) = constant_loop_receiver.recv().await { let banner_text = t!("banner_text_no_internet").to_string(); - if state == true { - *internet_connected_status.borrow_mut() = true; - if window_banner.title() == banner_text { - window_banner.set_revealed(false) + match message { + ConstantLoopMessage::InternetStatus(state) => { + if state == true { + *internet_connected_status.borrow_mut() = true; + if window_banner.title() == banner_text { + window_banner.set_revealed(false) + } + } else { + *internet_connected_status.borrow_mut() = false; + window_banner.set_title(&banner_text); + window_banner.set_revealed(true) + } + } + ConstantLoopMessage::RefreshRequest => { + refresh_button.emit_clicked(); } - } else { - *internet_connected_status.borrow_mut() = false; - window_banner.set_title(&banner_text); - window_banner.set_revealed(true) } } } @@ -204,8 +275,8 @@ pub fn build_ui(app: &Application) { let window_breakpoint = adw::Breakpoint::new(BreakpointCondition::new_length( BreakpointConditionLengthType::MaxWidth, - 1100.0, - LengthUnit::Px, + 1140.0, + LengthUnit::Sp, )); let window_adw_stack = gtk::Stack::builder() @@ -298,7 +369,7 @@ pub fn build_ui(app: &Application) { .default_width(glib_settings.int("window-width")) .default_height(glib_settings.int("window-height")) // - .width_request(1000) + .width_request(900) .height_request(700) .content(&window_content_page_split_view) // Startup @@ -326,11 +397,6 @@ pub fn build_ui(app: &Application) { .icon_name("dialog-information-symbolic") .build(); - let refresh_button = gtk::Button::builder() - .icon_name("view-refresh-symbolic") - .tooltip_text(t!("refresh_button_tooltip_text")) - .build(); - let credits_window = AboutWindow::builder() .application_icon(APP_ICON) .application_name(t!("application_name")) @@ -550,12 +616,11 @@ pub fn build_ui(app: &Application) { .position(|r| r == "--flatpak-installer") .unwrap() as i32) + 1) as usize; - if index > gtk_application_args.len() -1 { - flatpak_entry_signal_action - .activate(Some(&glib::Variant::from(""))); + if index > gtk_application_args.len() - 1 { + flatpak_entry_signal_action.activate(Some(&glib::Variant::from(""))); } else { flatpak_entry_signal_action - .activate(Some(&glib::Variant::from(>k_application_args[index]))); + .activate(Some(&glib::Variant::from(>k_application_args[index]))); } }