From 525183787f542dd8454f889b1ba5570dfb36708d Mon Sep 17 00:00:00 2001 From: Ward from fusion-voyager-3 Date: Fri, 11 Oct 2024 17:35:42 +0300 Subject: [PATCH] Build with speed meter and interval gui --- .github/release-nest-v3 | 2 +- debian/changelog | 2 +- locales/en_US.json | 5 +- src/bin/gui/apt_manage_page/mod.rs | 113 ++++++++++++++++++++++++++++- src/bin/gui/build_ui/mod.rs | 69 ++++++++++++------ src/bin/gui/style.css | 4 + 6 files changed, 169 insertions(+), 26 deletions(-) diff --git a/.github/release-nest-v3 b/.github/release-nest-v3 index ca7bf83..da2d398 100644 --- a/.github/release-nest-v3 +++ b/.github/release-nest-v3 @@ -1 +1 @@ -13 \ No newline at end of file +14 \ No newline at end of file diff --git a/debian/changelog b/debian/changelog index c30531e..1187646 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,4 +1,4 @@ -pikman-update-manager (1.0.1-100pika4) pikauwu; urgency=medium +pikman-update-manager (1.0.1-100pika5) pikauwu; urgency=medium * initial release diff --git a/locales/en_US.json b/locales/en_US.json index e384745..996a078 100644 --- a/locales/en_US.json +++ b/locales/en_US.json @@ -164,5 +164,8 @@ "apt_update_str_hit": "Up-to-date: {DESC} {SHORT_DESC}", "apt_update_str_fetch": "Fetching: {DESC} {SHORT_DESC}", "apt_update_str_done": "Downloading: {DESC} {SHORT_DESC}", - "apt_update_str_fail": "Download Failed: {DESC} {SHORT_DESC}" + "apt_update_str_fail": "Download Failed: {DESC} {SHORT_DESC}", + "retry_interval_labal_label": "Automatically Check for updates", + "retry_interval_spinrow_title": "Automatic Check Interval", + "retry_interval_spinrow_subtitle": "In Hours" } \ No newline at end of file diff --git a/src/bin/gui/apt_manage_page/mod.rs b/src/bin/gui/apt_manage_page/mod.rs index 7fdd619..7d22bf5 100644 --- a/src/bin/gui/apt_manage_page/mod.rs +++ b/src/bin/gui/apt_manage_page/mod.rs @@ -7,6 +7,9 @@ use std::cell::Ref; use std::cell::RefCell; use std::ops::Deref; use std::rc::Rc; +use std::sync::atomic::AtomicBool; +use std::sync::Arc; +use std::sync::Mutex; mod add_dialog; mod deb822_edit_dialog; @@ -19,7 +22,11 @@ enum AptSourceConfig { pub fn apt_manage_page( window: adw::ApplicationWindow, + glib_settings: &gio::Settings, apt_retry_signal_action: &SimpleAction, + thread_sleep_sender: &std::sync::mpsc::Sender<()>, + automatically_check_for_updates_arc: &Arc, + update_interval_arc: &Arc>, ) -> gtk::Box { let retry_signal_action = gio::SimpleAction::new("apt_manage_retry", None); @@ -536,6 +543,103 @@ pub fn apt_manage_page( // + let retry_interval_box = gtk::Box::builder() + .orientation(Orientation::Horizontal) + .halign(Align::Start) + .valign(Align::Center) + .margin_start(10) + .margin_end(10) + .margin_bottom(10) + .build(); + + let retry_interval_labal = gtk::Label::builder() + .label(t!("retry_interval_labal_label")) + .margin_start(2) + .margin_end(5) + .halign(Align::Start) + .valign(Align::Center) + .build(); + + let retry_interval_switch = gtk::Switch::builder() + .active(glib_settings.boolean("check-for-updates")) + .margin_end(5) + .halign(Align::Start) + .valign(Align::Center) + .build(); + + let retry_interval_spinrow= adw::SpinRow::builder() + .title(t!("retry_interval_spinrow_title")) + .subtitle(t!("retry_interval_spinrow_title")) + .activatable(false) + .selectable(false) + .climb_rate(1.0) + .adjustment(>k::Adjustment::new((glib_settings.int("update-interval") as f64) / 3600000.0, 1.0, 24.0, 1.0, 0.0, 0.0)) + .halign(Align::Start) + .valign(Align::Center) + .build(); + + retry_interval_spinrow.connect_value_notify(clone!( + #[strong] + glib_settings, + #[strong] + automatically_check_for_updates_arc, + #[strong] + update_interval_arc, + #[strong] + thread_sleep_sender, + move |spinrow| { + match glib_settings.set_int("update-interval", (spinrow.value() * 3600000.0) as i32) { + Ok(_) => { + { + automatically_check_for_updates_arc.store(glib_settings.boolean("check-for-updates"), std::sync::atomic::Ordering::Relaxed); + let mut update_interval_arc_gaurd = loop{ + if let Ok(guard) = update_interval_arc.lock() { + break guard; + } + }; + *update_interval_arc_gaurd = glib_settings.int("update-interval"); + } + thread_sleep_sender.send(()).unwrap(); + } + Err(_) => { + spinrow.set_value(glib_settings.int("update-interval") as f64 / 3600000.0); + } + } + })); + + retry_interval_switch.connect_state_set(clone!( + #[strong] + glib_settings, + #[strong] + automatically_check_for_updates_arc, + #[strong] + update_interval_arc, + #[strong] + thread_sleep_sender, + move |switch, state| { + match glib_settings.set_boolean("check-for-updates", state) { + Ok(_) => { + { + automatically_check_for_updates_arc.store(glib_settings.boolean("check-for-updates"), std::sync::atomic::Ordering::Relaxed); + let mut update_interval_arc_gaurd = loop{ + if let Ok(guard) = update_interval_arc.lock() { + break guard; + } + }; + *update_interval_arc_gaurd = glib_settings.int("update-interval"); + } + thread_sleep_sender.send(()).unwrap(); + } + Err(_) => { + switch.set_active(!state); + } + } + glib::Propagation::Proceed + } + )); + + retry_interval_spinrow.add_css_class("disable-outline"); + unofficial_sources_edit_box.append(&unofficial_source_add_button); unofficial_sources_edit_box.append(&unofficial_source_edit_button); unofficial_sources_edit_box.append(&unofficial_source_remove_button); @@ -543,6 +647,12 @@ pub fn apt_manage_page( unofficial_sources_box.append(&unofficial_sources_columnview_bin); unofficial_sources_box.append(&unofficial_sources_edit_box); + // + + retry_interval_box.append(&retry_interval_labal); + retry_interval_box.append(&retry_interval_switch); + retry_interval_box.append(&retry_interval_spinrow); + // main_box.append(&system_mirror_label0); @@ -555,6 +665,7 @@ pub fn apt_manage_page( main_box.append(&unofficial_sources_label0); main_box.append(&unofficial_sources_label1); main_box.append(&unofficial_sources_viewport); + main_box.append(&retry_interval_box); main_box -} +} \ No newline at end of file diff --git a/src/bin/gui/build_ui/mod.rs b/src/bin/gui/build_ui/mod.rs index 2b25660..f43fec3 100644 --- a/src/bin/gui/build_ui/mod.rs +++ b/src/bin/gui/build_ui/mod.rs @@ -102,6 +102,8 @@ pub fn build_ui(app: &Application) { let update_interval_arc = Arc::new(Mutex::new(glib_settings.int("update-interval"))); let internet_connected = Rc::new(RefCell::new(false)); + let (thread_sleep_sender, thread_sleep_receiver) = std::sync::mpsc::channel::<()>(); + 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(); @@ -216,22 +218,38 @@ pub fn build_ui(app: &Application) { } }); + { + let automatically_check_for_updates_arc = automatically_check_for_updates_arc.clone(); + let update_interval_arc = update_interval_arc.clone(); + // update interval loop - thread::spawn(move || loop { - let automatically_check_for_updates = + thread::spawn(move || { + loop { + let local_interval: i32; + 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(_) => {} + if automatically_check_for_updates { + let update_interval = match update_interval_arc.lock() { + Ok(t) => t, + Err(_) => { + continue; + } + }; + local_interval = *update_interval; + std::mem::drop(update_interval); + //println!("Sleeping on auto update check: {}", local_interval); + if let Ok(_) = thread_sleep_receiver.recv_timeout (std::time::Duration::from_millis(local_interval as u64)) { + //println!("Sleeping on auto was interrupted was interrupted"); + continue; + } + //println!("Starting Refresh Request"); + constant_loop_sender_clone1 + .send_blocking(ConstantLoopMessage::RefreshRequest) + .expect("The channel needs to be open."); } } }); + } let window_banner = Banner::builder().revealed(false).build(); @@ -325,6 +343,9 @@ pub fn build_ui(app: &Application) { window_toolbar.add_top_bar(&window_headerbar); window_toolbar.add_top_bar(&window_banner); + let window_box = gtk::Box::new(gtk::Orientation::Horizontal, 0); + window_box.append(&window_content_page_split_view); + // create the main Application window let window = ApplicationWindow::builder() // The text on the titlebar @@ -338,9 +359,9 @@ pub fn build_ui(app: &Application) { .default_width(glib_settings.int("window-width")) .default_height(glib_settings.int("window-height")) // - .width_request(1000) - .height_request(700) - .content(&window_content_page_split_view) + .width_request(1140) + .height_request(780) + .content(&window_box) // Startup .startup_id(APP_ID) // build the window @@ -354,13 +375,17 @@ pub fn build_ui(app: &Application) { window.maximize() } - window.connect_close_request(move |window| { - let size = window.default_size(); - let _ = glib_settings.set_int("window-width", size.0); - let _ = glib_settings.set_int("window-height", size.1); - let _ = glib_settings.set_boolean("is-maximized", window.is_maximized()); - glib::Propagation::Proceed - }); + { + let glib_settings = glib_settings.clone(); + + window.connect_close_request(move |window| { + let size = window.default_size(); + let _ = glib_settings.set_int("window-width", size.0); + let _ = glib_settings.set_int("window-height", size.1); + let _ = glib_settings.set_boolean("is-maximized", window.is_maximized()); + glib::Propagation::Proceed + }); + } let credits_button = gtk::Button::builder() .icon_name("dialog-information-symbolic") @@ -497,7 +522,7 @@ pub fn build_ui(app: &Application) { window_adw_view_switcher_sidebar_box.append(&flatpak_update_page_toggle_button); window_adw_stack.add_titled( - &apt_manage_page(window.clone(), &apt_retry_signal_action), + &apt_manage_page(window.clone(), &glib_settings, &apt_retry_signal_action,&thread_sleep_sender, &automatically_check_for_updates_arc, &update_interval_arc), Some("apt_manage_page"), &t!("apt_manage_page_title"), ); diff --git a/src/bin/gui/style.css b/src/bin/gui/style.css index f1fbea2..cb96f95 100644 --- a/src/bin/gui/style.css +++ b/src/bin/gui/style.css @@ -64,4 +64,8 @@ .size-20-bold-text { font-weight: 800; font-size: 20px; +} + +.disable-outline { + outline: none; } \ No newline at end of file