From 97e2ed1dc65ef560ec19c36717fc966b73e31c84 Mon Sep 17 00:00:00 2001 From: Ward from fusion-voyager-3 Date: Mon, 4 Nov 2024 00:43:57 +0300 Subject: [PATCH] Add main page --- .github/release-nest-v3 | 2 +- Cargo.lock | 2 +- Cargo.toml | 2 +- debian/changelog | 7 ++ locales/en_US.json | 8 +- main.sh | 2 +- src/bin/gui/apt_update_page/process.rs | 94 +---------------- src/bin/gui/build_ui/mod.rs | 93 ++++++++++++++++ src/bin/gui/main_update_page/mod.rs | 141 +++++++++++++++++++++++-- src/bin/gui/style.css | 5 + 10 files changed, 247 insertions(+), 109 deletions(-) diff --git a/.github/release-nest-v3 b/.github/release-nest-v3 index b5045cc..8fdd954 100644 --- a/.github/release-nest-v3 +++ b/.github/release-nest-v3 @@ -1 +1 @@ -21 \ No newline at end of file +22 \ No newline at end of file diff --git a/Cargo.lock b/Cargo.lock index bba2080..d1275d8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1793,7 +1793,7 @@ checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" [[package]] name = "pikman-update-manager" -version = "1.1.0" +version = "1.1.1" dependencies = [ "async-channel", "async-trait", diff --git a/Cargo.toml b/Cargo.toml index 9904ab8..aa01559 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "pikman-update-manager" -version = "1.1.0" +version = "1.1.1" edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/debian/changelog b/debian/changelog index d7b44fc..c7c4621 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,10 @@ +pikman-update-manager (1.1.1-100pika1) pika; urgency=medium + + * add main page + + -- Pika Wed, 11 Jan 2023 11:41:38 +0000 + + pikman-update-manager (1.1.0-100pika2) pika; urgency=medium * initial release diff --git a/locales/en_US.json b/locales/en_US.json index 07c0776..0203876 100644 --- a/locales/en_US.json +++ b/locales/en_US.json @@ -169,5 +169,11 @@ "retry_interval_spinrow_title": "Automatic Check Interval", "retry_interval_spinrow_subtitle": "In Hours", "progress_bar_circle_center_text": "Percent %", - "main_update_page_title": "Main Updates Page" + "main_update_page_title": "Main Updates Page", + "update_button_main_label": "Commit APT & Flatpak Upgrades", + "update_badge_box_total_label": "Total Updates", + "update_badge_box_apt_label": "APT Updates", + "update_badge_box_flatpak_label": "Flatpak Updates", + "main_page_header_label_yes_label": "Updates Available!", + "main_page_header_label_no_label": "Up-to-date!" } \ No newline at end of file diff --git a/main.sh b/main.sh index a4a033a..818a390 100755 --- a/main.sh +++ b/main.sh @@ -2,7 +2,7 @@ set -e -VERSION="1.1.0" +VERSION="1.1.1" source ./pika-build-config.sh diff --git a/src/bin/gui/apt_update_page/process.rs b/src/bin/gui/apt_update_page/process.rs index dc8306f..4d604da 100644 --- a/src/bin/gui/apt_update_page/process.rs +++ b/src/bin/gui/apt_update_page/process.rs @@ -17,7 +17,7 @@ use std::rc::Rc; use std::thread; use tokio::runtime::Runtime; -use crate::build_ui::get_current_font; +use crate::build_ui::{create_color_badge, get_current_font}; struct AptChangesInfo { package_count_upgrade: u64, @@ -689,95 +689,3 @@ fn apt_full_upgrade_from_socket( } }); } - -fn create_color_badge( - label0_text: &str, - label1_text: &str, - css_style: &str, - theme_changed_action: &SimpleAction, - group_size: &SizeGroup, - group_size0: &SizeGroup, - group_size1: &SizeGroup, -) -> ListBox { - let badge_box = Box::builder().build(); - - let label0 = Label::builder() - .label(label0_text) - .margin_start(5) - .margin_end(5) - .margin_bottom(1) - .margin_top(1) - .valign(Align::Center) - .halign(Align::Center) - .hexpand(true) - .vexpand(true) - .build(); - group_size0.add_widget(&label0); - - let label_separator = Separator::builder().build(); - - let label1 = Label::builder() - .label(label1_text) - .margin_start(3) - .margin_end(0) - .margin_bottom(1) - .margin_top(1) - .valign(Align::Center) - .halign(Align::Center) - .hexpand(true) - .vexpand(true) - .build(); - group_size1.add_widget(&label1); - - label1.add_css_class(css_style); - - #[allow(deprecated)] - let color = label1 - .style_context() - .lookup_color("accent_bg_color") - .unwrap(); - if (color.red() * 0.299 + color.green() * 0.587 + color.blue() * 0.114) > 170.0 { - label1.remove_css_class("white-color-text"); - label1.add_css_class("black-color-text"); - } else { - label1.remove_css_class("black-color-text"); - label1.add_css_class("white-color-text"); - } - - theme_changed_action.connect_activate(clone!( - #[strong] - label1, - move |_, _| { - #[allow(deprecated)] - let color = label1 - .style_context() - .lookup_color("accent_bg_color") - .unwrap(); - if (color.red() * 0.299 + color.green() * 0.587 + color.blue() * 0.114) > 170.0 { - label1.remove_css_class("white-color-text"); - label1.add_css_class("black-color-text"); - } else { - label1.remove_css_class("black-color-text"); - label1.add_css_class("white-color-text"); - } - } - )); - - badge_box.append(&label0); - badge_box.append(&label_separator); - badge_box.append(&label1); - - let boxedlist = ListBox::builder() - .selection_mode(SelectionMode::None) - .halign(Align::Center) - .margin_start(10) - .margin_end(10) - .margin_bottom(10) - .margin_top(10) - .build(); - - boxedlist.add_css_class("boxed-list"); - boxedlist.append(&badge_box); - group_size.add_widget(&boxedlist); - boxedlist -} diff --git a/src/bin/gui/build_ui/mod.rs b/src/bin/gui/build_ui/mod.rs index 45d30eb..9d96d4a 100644 --- a/src/bin/gui/build_ui/mod.rs +++ b/src/bin/gui/build_ui/mod.rs @@ -584,6 +584,7 @@ pub fn build_ui(app: &Application) { &apt_update_button, &initiated_by_main, &theme_changed_action, + &update_sys_tray, ), Some("main_update_page"), &t!("main_update_page_title"), @@ -849,3 +850,95 @@ fn add_content_button( )); toggle_button } + +pub fn create_color_badge( + label0_text: &str, + label1_text: &str, + css_style: &str, + theme_changed_action: &gio::SimpleAction, + group_size: >k::SizeGroup, + group_size0: >k::SizeGroup, + group_size1: >k::SizeGroup, +) -> gtk::ListBox { + let badge_box = gtk::Box::builder().build(); + + let label0 = gtk::Label::builder() + .label(label0_text) + .margin_start(5) + .margin_end(5) + .margin_bottom(1) + .margin_top(1) + .valign(gtk::Align::Center) + .halign(gtk::Align::Center) + .hexpand(true) + .vexpand(true) + .build(); + group_size0.add_widget(&label0); + + let label_separator = gtk::Separator::builder().build(); + + let label1 = gtk::Label::builder() + .label(label1_text) + .margin_start(3) + .margin_end(0) + .margin_bottom(1) + .margin_top(1) + .valign(gtk::Align::Center) + .halign(gtk::Align::Center) + .hexpand(true) + .vexpand(true) + .build(); + group_size1.add_widget(&label1); + + label1.add_css_class(css_style); + + #[allow(deprecated)] + let color = label1 + .style_context() + .lookup_color("accent_bg_color") + .unwrap(); + if (color.red() * 0.299 + color.green() * 0.587 + color.blue() * 0.114) > 170.0 { + label1.remove_css_class("white-color-text"); + label1.add_css_class("black-color-text"); + } else { + label1.remove_css_class("black-color-text"); + label1.add_css_class("white-color-text"); + } + + theme_changed_action.connect_activate(clone!( + #[strong] + label1, + move |_, _| { + #[allow(deprecated)] + let color = label1 + .style_context() + .lookup_color("accent_bg_color") + .unwrap(); + if (color.red() * 0.299 + color.green() * 0.587 + color.blue() * 0.114) > 170.0 { + label1.remove_css_class("white-color-text"); + label1.add_css_class("black-color-text"); + } else { + label1.remove_css_class("black-color-text"); + label1.add_css_class("white-color-text"); + } + } + )); + + badge_box.append(&label0); + badge_box.append(&label_separator); + badge_box.append(&label1); + + let boxedlist = gtk::ListBox::builder() + .selection_mode(gtk::SelectionMode::None) + .halign(gtk::Align::Center) + .margin_start(10) + .margin_end(10) + .margin_bottom(10) + .margin_top(10) + .build(); + + boxedlist.add_css_class("boxed-list"); + boxedlist.append(&badge_box); + group_size.add_widget(&boxedlist); + boxedlist +} diff --git a/src/bin/gui/main_update_page/mod.rs b/src/bin/gui/main_update_page/mod.rs index 43f0946..3a1f266 100644 --- a/src/bin/gui/main_update_page/mod.rs +++ b/src/bin/gui/main_update_page/mod.rs @@ -1,14 +1,16 @@ -use adw::gio::SimpleAction; use adw::prelude::*; use gtk::glib::*; use gtk::*; use std::cell::RefCell; use std::rc::Rc; +use crate::build_ui::create_color_badge; + pub fn main_update_page( apt_update_button: &Rc>, initiated_by_main: &Rc>, theme_changed_action: &gio::SimpleAction, + update_sys_tray: &gio::SimpleAction, ) -> gtk::Box { let main_box = Box::builder() .hexpand(true) @@ -16,23 +18,137 @@ pub fn main_update_page( .orientation(Orientation::Vertical) .build(); - let bottom_icon = gtk::Image::builder() - .pixel_size(128) - .halign(Align::Center) + let header_box = Box::builder() .hexpand(true) - .icon_name("tux-symbolic") - .margin_start(10) - .margin_end(10) - .margin_bottom(20) - .margin_top(20) + .vexpand(true) + .halign(Align::Center) + .orientation(Orientation::Horizontal) + .build(); + + let header_label = gtk::Label::builder() + .label(t!("main_page_header_label_no_label")) + .build(); + header_label.add_css_class("size-35-bold-text"); + + let updater_icon = gtk::Image::builder() + .pixel_size(128) + .icon_name("update-none") + .margin_start(5) + .margin_end(5) + .margin_bottom(5) + .margin_top(5) .build(); let update_badge_box = gtk::Box::builder() .hexpand(true) .vexpand(true) + .halign(Align::Center) + .valign(Align::Center) .orientation(Orientation::Vertical) .build(); + let update_badge_box_size_group = SizeGroup::new(SizeGroupMode::Both); + let update_badge_box_size_group0 = SizeGroup::new(SizeGroupMode::Both); + let update_badge_box_size_group1 = SizeGroup::new(SizeGroupMode::Both); + + update_badge_box.append(&create_color_badge( + &t!("update_badge_box_total_label"), + &t!("pikman_indicator_flatpak_item_label_calculating"), + "background-accent-bg", + &theme_changed_action, + &update_badge_box_size_group, + &update_badge_box_size_group0, + &update_badge_box_size_group1, + )); + // + update_badge_box.append(&create_color_badge( + &t!("update_badge_box_apt_label"), + &t!("pikman_indicator_flatpak_item_label_calculating"), + "background-accent-bg", + &theme_changed_action, + &update_badge_box_size_group, + &update_badge_box_size_group0, + &update_badge_box_size_group1, + )); + // + update_badge_box.append(&create_color_badge( + &t!("update_badge_box_flatpak_label"), + &t!("pikman_indicator_flatpak_item_label_calculating"), + "background-accent-bg", + &theme_changed_action, + &update_badge_box_size_group, + &update_badge_box_size_group0, + &update_badge_box_size_group1, + )); + + update_sys_tray.connect_activate(clone!( + #[strong] + update_badge_box, + #[strong] + updater_icon, + #[strong] + header_label, + #[strong] + theme_changed_action, + 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 total_count = apt_update_count + flatpak_update_count; + if total_count > 1 { + updater_icon.set_icon_name(Some("update-high".into())); + header_label.set_label(&t!("main_page_header_label_yes_label")); + } else { + updater_icon.set_icon_name(Some("update-none".into())); + header_label.set_label(&t!("main_page_header_label_no_label")); + } + // + while let Some(widget) = update_badge_box.last_child() { + update_badge_box.remove(&widget); + } + // + update_badge_box.append(&create_color_badge( + &t!("update_badge_box_total_label"), + &match total_count { + -2 => t!("pikman_indicator_flatpak_item_label_calculating").into(), + _ => total_count.to_string(), + }, + "background-accent-bg", + &theme_changed_action, + &update_badge_box_size_group, + &update_badge_box_size_group0, + &update_badge_box_size_group1, + )); + // + update_badge_box.append(&create_color_badge( + &t!("update_badge_box_apt_label"), + &match apt_update_count { + -1 => t!("pikman_indicator_flatpak_item_label_calculating").into(), + _ => apt_update_count.to_string(), + }, + "background-accent-bg", + &theme_changed_action, + &update_badge_box_size_group, + &update_badge_box_size_group0, + &update_badge_box_size_group1, + )); + // + update_badge_box.append(&create_color_badge( + &t!("update_badge_box_flatpak_label"), + &match flatpak_update_count { + -1 => t!("pikman_indicator_flatpak_item_label_calculating").into(), + _ => flatpak_update_count.to_string(), + }, + "background-accent-bg", + &theme_changed_action, + &update_badge_box_size_group, + &update_badge_box_size_group0, + &update_badge_box_size_group1, + )); + } + )); + let bottom_bar = Box::builder().valign(Align::End).build(); let update_button = Button::builder() @@ -42,7 +158,7 @@ pub fn main_update_page( .margin_start(10) .margin_end(30) .margin_bottom(15) - .label(t!("update_button_label")) + .label(t!("update_button_main_label")) .build(); update_button.add_css_class("destructive-action"); @@ -59,8 +175,11 @@ pub fn main_update_page( bottom_bar.append(&update_button); + header_box.append(&updater_icon); + header_box.append(&header_label); + + main_box.append(&header_box); main_box.append(&update_badge_box); - main_box.append(&bottom_icon); main_box.append(&bottom_bar); main_box diff --git a/src/bin/gui/style.css b/src/bin/gui/style.css index d068371..846e4c3 100644 --- a/src/bin/gui/style.css +++ b/src/bin/gui/style.css @@ -96,6 +96,11 @@ font-size: 20px; } +.size-35-bold-text { + font-weight: 800; + font-size: 35px; +} + .disable-outline { outline: none; } \ No newline at end of file