diff --git a/.github/release-nest-v3 b/.github/release-nest-v3 index 62f9457..c793025 100644 --- a/.github/release-nest-v3 +++ b/.github/release-nest-v3 @@ -1 +1 @@ -6 \ No newline at end of file +7 \ No newline at end of file diff --git a/Cargo.lock b/Cargo.lock index 826c617..7b95c90 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1428,7 +1428,7 @@ checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" [[package]] name = "pika-kernel-manager" -version = "0.1.4" +version = "0.1.5" dependencies = [ "async-channel", "duct", diff --git a/Cargo.toml b/Cargo.toml index b763f5a..6dcfaff 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "pika-kernel-manager" -version = "0.1.4" +version = "0.1.5" edition = "2021" diff --git a/data/style.css b/data/style.css index 50f7d8b..7c0302d 100644 --- a/data/style.css +++ b/data/style.css @@ -40,4 +40,12 @@ border-top-left-radius: 0px; border-bottom-right-radius: 15px; border-bottom-left-radius: 15px; -} \ No newline at end of file +} + +.black-color-text { + color: black; +} + +.white-color-text { + color: white; +} diff --git a/debian/changelog b/debian/changelog index f3f3157..6737aa0 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,9 @@ +pika-kernel-manager (0.1.5-101pika1) pika; urgency=low + + * UI Refine + + -- Ward Nakchbandi Sat, 01 Oct 2022 14:50:00 +0200 + pika-kernel-manager (0.1.3-101pika5) pika; urgency=low * Initial Release diff --git a/main.sh b/main.sh index 9638fee..17d29eb 100755 --- a/main.sh +++ b/main.sh @@ -2,7 +2,7 @@ set -e -VERSION="0.1.3" +VERSION="0.1.5" source ./pika-build-config.sh diff --git a/src/build_ui/mod.rs b/src/build_ui/mod.rs index a56cd84..2479447 100644 --- a/src/build_ui/mod.rs +++ b/src/build_ui/mod.rs @@ -1,8 +1,8 @@ +use crate::content; use crate::APP_GITHUB; use crate::APP_ICON; use crate::APP_ID; use crate::VERSION; -use crate::content; use adw::prelude::*; use adw::*; use glib::{clone, MainContext}; @@ -16,6 +16,8 @@ pub fn build_ui(app: &adw::Application) { gtk::glib::set_prgname(Some(t!("application_name").to_string())); glib::set_application_name(&t!("application_name").to_string()); + let theme_changed_action = gio::SimpleAction::new("theme_changed", None); + let internet_connected = Rc::new(RefCell::new(false)); let (internet_loop_sender, internet_loop_receiver) = async_channel::unbounded(); @@ -81,11 +83,44 @@ pub fn build_ui(app: &adw::Application) { .startup_id(APP_ID) .build(); + let (gsettings_change_sender, gsettings_change_receiver) = async_channel::unbounded(); + let gsettings_change_sender_clone0 = gsettings_change_sender.clone(); + + thread::spawn(move || { + let context = glib::MainContext::default(); + let main_loop = glib::MainLoop::new(Some(&context), false); + let gsettings = gtk::gio::Settings::new("org.gnome.desktop.interface"); + gsettings.connect_changed( + Some("accent-color"), + clone!( + @strong + gsettings_change_sender_clone0 => + move |_, _| { + let gsettings_change_sender_clone0 = gsettings_change_sender_clone0.clone(); + glib::timeout_add_seconds_local(5, move || { + gsettings_change_sender_clone0.send_blocking(()).unwrap(); + glib::ControlFlow::Break + }); + } + ), + ); + main_loop.run() + }); + + let gsettings_changed_context = MainContext::default(); + // The main loop executes the asynchronous block + gsettings_changed_context.spawn_local(clone!( + @strong + theme_changed_action => + async move { + while let Ok(()) = gsettings_change_receiver.recv().await { + theme_changed_action.activate(None); + } + } + )); + content_stack.add_named( - &content::content( - &content_stack, - &window, - ), + &content::content(&content_stack, &window, &theme_changed_action), Some("content_page"), ); @@ -127,7 +162,6 @@ fn load_icon_theme(window: &adw::ApplicationWindow) { let icon_theme = gtk::IconTheme::for_display(&WidgetExt::display(window)); icon_theme.add_resource_path("/com/github/pikaos-linux/pika-kernel-manager/icons/"); - icon_theme.add_resource_path( - "/com/github/pikaos-linux/pika-kernel-manager/icons/scalable/actions/", - ); + icon_theme + .add_resource_path("/com/github/pikaos-linux/pika-kernel-manager/icons/scalable/actions/"); } diff --git a/src/content/mod.rs b/src/content/mod.rs index 062b982..0044c4c 100644 --- a/src/content/mod.rs +++ b/src/content/mod.rs @@ -8,10 +8,7 @@ use std::process::{Command, Stdio}; use std::{fs, time}; use version_compare::Version; -pub fn content( - content_stack: >k::Stack, - window: &adw::ApplicationWindow, -) -> gtk::Box { +pub fn content(content_stack: >k::Stack, window: &adw::ApplicationWindow, theme_changed_action: &gio::SimpleAction) -> gtk::Box { let content_box = gtk::Box::builder() .hexpand(true) .vexpand(true) @@ -38,10 +35,7 @@ pub fn content( .orientation(Orientation::Vertical) .build(); - let sched_ext_badge_box = adw::Bin::builder() - .hexpand(true) - .vexpand(true) - .build(); + let sched_ext_badge_box = adw::Bin::builder().hexpand(true).vexpand(true).build(); let button_box = gtk::Box::builder() .orientation(Orientation::Horizontal) @@ -65,12 +59,10 @@ pub fn content( .build(); browse_kernels_button.add_css_class("circular"); - browse_kernels_button.connect_clicked( - clone!(@weak window, @weak content_stack => move |_| { - kernel_pkg::kernel_pkg_page(&content_stack, &window); - content_stack.set_visible_child_name("kernel_pkg_page") - }), - ); + browse_kernels_button.connect_clicked(clone!(@weak window, @weak content_stack => move |_| { + kernel_pkg::kernel_pkg_page(&content_stack, &window); + content_stack.set_visible_child_name("kernel_pkg_page") + })); let config_kernel_button = gtk::Button::builder() .icon_name("emblem-system-symbolic") @@ -86,24 +78,28 @@ pub fn content( if !is_scx_kernel() { config_kernel_button.set_sensitive(false); - config_kernel_button - .set_tooltip_text(Some(&t!("config_kernel_button_tooltip_text_no_scx").to_string())); + config_kernel_button.set_tooltip_text(Some( + &t!("config_kernel_button_tooltip_text_no_scx").to_string(), + )); } else if is_scx_kernel() && !is_scx_installed() { config_kernel_button.set_sensitive(false); - config_kernel_button - .set_tooltip_text(Some(&t!("config_kernel_button_tooltip_text_no_scx_installed").to_string())); + config_kernel_button.set_tooltip_text(Some( + &t!("config_kernel_button_tooltip_text_no_scx_installed").to_string(), + )); } // DEBUG //config_kernel_button.set_sensitive(true); - config_kernel_button.connect_clicked(clone!(@weak content_stack, @weak window, @weak sched_ext_badge_box => move |_| { - content_stack.add_named( - &sched_ext::sched_ext_page(&content_stack, &window, &sched_ext_badge_box), - Some("sched_ext_page"), - ); - content_stack.set_visible_child_name("sched_ext_page") - })); + config_kernel_button.connect_clicked( + clone!(@weak content_stack, @weak window, @weak sched_ext_badge_box => move |_| { + content_stack.add_named( + &sched_ext::sched_ext_page(&content_stack, &window, &sched_ext_badge_box), + Some("sched_ext_page"), + ); + content_stack.set_visible_child_name("sched_ext_page") + }), + ); let (load_badge_async_sender, load_badge_async_receiver) = async_channel::unbounded(); let load_badge_async_sender = load_badge_async_sender.clone(); @@ -117,17 +113,19 @@ pub fn content( let load_badge_async_context = MainContext::default(); // The main loop executes the asynchronous block - load_badge_async_context.spawn_local(clone!(@weak content_box, @weak kernel_badge_box => async move { - while let Ok(_state) = load_badge_async_receiver.recv().await { - let running_kernel_info = get_running_kernel_info(); - create_kernel_badges(&kernel_badge_box, &running_kernel_info); - create_current_sched_badge(&sched_ext_badge_box, &running_kernel_info); - } - })); + load_badge_async_context.spawn_local( + clone!(@weak content_box, @weak kernel_badge_box, @strong theme_changed_action => async move { + while let Ok(_state) = load_badge_async_receiver.recv().await { + let running_kernel_info = get_running_kernel_info(); + create_kernel_badges(&kernel_badge_box, &running_kernel_info, &theme_changed_action); + create_current_sched_badge(&sched_ext_badge_box, &running_kernel_info, &theme_changed_action); + } + }), + ); button_box.append(&browse_kernels_button); button_box.append(&config_kernel_button); - + content_box.append(&kernel_badge_box); content_box.append(&tux_icon); content_box.append(&button_box); @@ -139,6 +137,7 @@ pub fn create_kernel_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, @@ -175,6 +174,38 @@ pub fn create_kernel_badge( 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_seprator); badge_box.append(&label1); @@ -263,22 +294,22 @@ fn bore_check() -> bool { is_bore } -fn create_kernel_badges( - badge_box: >k::Box, - running_kernel_info: &RunningKernelInfo, -) { +fn create_kernel_badges(badge_box: >k::Box, running_kernel_info: &RunningKernelInfo, theme_changed_action: &gio::SimpleAction) { let kernel_badges_size_group = gtk::SizeGroup::new(SizeGroupMode::Both); let kernel_badges_size_group0 = gtk::SizeGroup::new(SizeGroupMode::Both); let kernel_badges_size_group1 = gtk::SizeGroup::new(SizeGroupMode::Both); - let command_get_kernel_pika = Command::new("/usr/lib/pika/kernel-manager/scripts/get_kernel_pika.sh") - .arg("version") - .output() - .unwrap(); + let command_get_kernel_pika = + Command::new("/usr/lib/pika/kernel-manager/scripts/get_kernel_pika.sh") + .arg("version") + .output() + .unwrap(); let kernel_version = String::from_utf8(command_get_kernel_pika.stdout).unwrap(); - let version_css_style = if Version::from(&running_kernel_info.version).unwrap() >= Version::from(kernel_version.trim()).unwrap() { + let version_css_style = if Version::from(&running_kernel_info.version).unwrap() + >= Version::from(kernel_version.trim()).unwrap() + { "background-green-bg" } else { "background-red-bg" @@ -292,6 +323,7 @@ fn create_kernel_badges( &t!("kernel_badge_latest_version_label").to_string(), &kernel_version, "background-accent-bg", + &theme_changed_action, &kernel_badges_size_group, &kernel_badges_size_group0, &kernel_badges_size_group1, @@ -300,6 +332,7 @@ fn create_kernel_badges( &t!("kernel_badge_running_version_label").to_string(), &running_kernel_info.version, &version_css_style, + &theme_changed_action, &kernel_badges_size_group, &kernel_badges_size_group0, &kernel_badges_size_group1, @@ -308,6 +341,7 @@ fn create_kernel_badges( &t!("kernel_badge_running_kernel_label").to_string(), &running_kernel_info.kernel, &version_css_style, + &theme_changed_action, &kernel_badges_size_group, &kernel_badges_size_group0, &kernel_badges_size_group1, @@ -316,16 +350,14 @@ fn create_kernel_badges( &t!("kernel_badge_running_sched_label").to_string(), &running_kernel_info.sched.trim(), "background-accent-bg", + &theme_changed_action, &kernel_badges_size_group, &kernel_badges_size_group0, &kernel_badges_size_group1, )); } -fn create_current_sched_badge( - badge_box: &adw::Bin, - running_kernel_info: &RunningKernelInfo, -) { +fn create_current_sched_badge(badge_box: &adw::Bin, running_kernel_info: &RunningKernelInfo, theme_changed_action: &gio::SimpleAction) { //while let Some(widget) = badge_box.last_child() { // badge_box.remove(&widget); //} @@ -338,6 +370,7 @@ fn create_current_sched_badge( &t!("kernel_badge_running_sched_label").to_string(), &running_kernel_info.sched, "background-accent-bg", + &theme_changed_action, &kernel_badges_size_group, &kernel_badges_size_group0, &kernel_badges_size_group1, @@ -345,10 +378,8 @@ fn create_current_sched_badge( } fn is_scx_installed() -> bool { - match Command::new("systemctl") - .args(["status", "scx"]) - .output() { + match Command::new("systemctl").args(["status", "scx"]).output() { Ok(t) if t.status.code().unwrap() != 4 => true, - _ => false + _ => false, } -} \ No newline at end of file +} diff --git a/src/kernel_package_row/imp.rs b/src/kernel_package_row/imp.rs index fc5bc49..1e18a0c 100644 --- a/src/kernel_package_row/imp.rs +++ b/src/kernel_package_row/imp.rs @@ -3,7 +3,7 @@ use std::{cell::RefCell, sync::OnceLock}; use adw::*; use adw::{prelude::*, subclass::prelude::*}; use glib::{subclass::Signal, Properties}; -use gtk::{glib}; +use gtk::glib; // ANCHOR: custom_button // Object holding the state diff --git a/src/kernel_pkg/mod.rs b/src/kernel_pkg/mod.rs index 7fb72fb..369e69a 100644 --- a/src/kernel_pkg/mod.rs +++ b/src/kernel_pkg/mod.rs @@ -10,20 +10,19 @@ use std::io::BufReader; use std::process::Command; use std::time::*; -pub fn kernel_pkg_page( - content_stack: >k::Stack, - window: &adw::ApplicationWindow, -) { +pub fn kernel_pkg_page(content_stack: >k::Stack, window: &adw::ApplicationWindow) { let parse_loading_dialog = adw::MessageDialog::builder() .transient_for(window) - .extra_child(>k::Spinner::builder() - .hexpand(true) - .valign(Align::Start) - .halign(Align::Center) - .spinning(true) - .height_request(128) - .width_request(128) - .build()) + .extra_child( + >k::Spinner::builder() + .hexpand(true) + .valign(Align::Start) + .halign(Align::Center) + .spinning(true) + .height_request(128) + .width_request(128) + .build(), + ) .heading(t!("parse_loading_dialog_heading")) .body(t!("parse_loading_dialog_body")) .build(); @@ -74,10 +73,7 @@ pub fn kernel_pkg_page( .build(); searchbar.add_css_class("rounded-all-25"); - content_stack.add_named( - &main_box, - Some("kernel_pkg_page"), - ); + content_stack.add_named(&main_box, Some("kernel_pkg_page")); let packages_boxedlist = gtk::ListBox::builder() .selection_mode(SelectionMode::None) @@ -94,7 +90,7 @@ pub fn kernel_pkg_page( &window, &rows_size_group, &searchbar, - &parse_loading_dialog + &parse_loading_dialog, ); let packages_viewport = gtk::ScrolledWindow::builder() @@ -147,7 +143,7 @@ fn add_package_rows( window: &adw::ApplicationWindow, rows_size_group: >k::SizeGroup, searchbar: >k::SearchEntry, - parse_loading_dialog: &adw::MessageDialog + parse_loading_dialog: &adw::MessageDialog, ) { let (kernel_package_sender, kernel_package_receiver) = async_channel::unbounded(); let kernel_package_sender = kernel_package_sender.clone(); @@ -156,29 +152,31 @@ fn add_package_rows( let kernel_package_done_sender = kernel_package_done_sender.clone(); std::thread::spawn(move || { - let command_get_kernel_pika = Command::new("/usr/lib/pika/kernel-manager/scripts/get_kernel_pika.sh") - .arg("list") - .output() - .unwrap(); + let command_get_kernel_pika = + Command::new("/usr/lib/pika/kernel-manager/scripts/get_kernel_pika.sh") + .arg("list") + .output() + .unwrap(); let kernel_string = String::from_utf8(command_get_kernel_pika.stdout).unwrap(); let kernels = kernel_string.trim().lines(); - for kernel in kernels { - let kernel_version = &kernel.trim_end_matches("-pikaos"); - let kernel_name = format!("PikaOS Linux Kernel {}", kernel_version); - let kernel_main_package = format!("linux-image-{}", &kernel); - let kernel_packages = format!("linux-image-{VERSION} linux-headers-{VERSION}", VERSION=kernel); - let kernel_package_version = match Command::new( - "/usr/lib/pika/kernel-manager/scripts/generate_package_info.sh", - ) + for kernel in kernels { + let kernel_version = &kernel.trim_end_matches("-pikaos"); + let kernel_name = format!("PikaOS Linux Kernel {}", kernel_version); + let kernel_main_package = format!("linux-image-{}", &kernel); + let kernel_packages = format!( + "linux-image-{VERSION} linux-headers-{VERSION}", + VERSION = kernel + ); + let kernel_package_version = + match Command::new("/usr/lib/pika/kernel-manager/scripts/generate_package_info.sh") .args(["version", &kernel_main_package]) .output() { Ok(t) => String::from_utf8(t.stdout).unwrap(), _ => "Error".to_owned(), }; - let kernel_description = match Command::new( - "/usr/lib/pika/kernel-manager/scripts/generate_package_info.sh", - ) + let kernel_description = + match Command::new("/usr/lib/pika/kernel-manager/scripts/generate_package_info.sh") .args(["description", &kernel_main_package]) .output() { @@ -186,16 +184,20 @@ fn add_package_rows( _ => "Error".to_owned(), }; - let kernel_package = KernelPackage{ - name: kernel_name, - main_package: kernel_main_package, - packages: kernel_packages, - package_version: kernel_package_version, - description: kernel_description - }; - kernel_package_sender.send_blocking(kernel_package).expect("Kernel Package sender channel closed") + let kernel_package = KernelPackage { + name: kernel_name, + main_package: kernel_main_package, + packages: kernel_packages, + package_version: kernel_package_version, + description: kernel_description, }; - kernel_package_done_sender.send_blocking(true).expect("Kernel Package done sender channel closed") + kernel_package_sender + .send_blocking(kernel_package) + .expect("Kernel Package sender channel closed") + } + kernel_package_done_sender + .send_blocking(true) + .expect("Kernel Package done sender channel closed") }); let kernel_package_context = MainContext::default(); @@ -492,7 +494,7 @@ pkexec /usr/lib/pika/kernel-manager/scripts/modify_package.sh remove "${PACKAGE} fn kernel_modify( log_loop_sender: async_channel::Sender, kernel_pkg: &str, - install: bool + install: bool, ) -> Result<(), std::boxed::Box> { let kernel_modify_prog = if install { KERNEL_INSTALL_PROG @@ -512,4 +514,4 @@ fn kernel_modify( child.wait()?; Ok(()) -} \ No newline at end of file +} diff --git a/src/main.rs b/src/main.rs index 4b381d9..ebaf085 100644 --- a/src/main.rs +++ b/src/main.rs @@ -4,12 +4,12 @@ mod kernel_package_row; mod kernel_pkg; mod sched_ext; -use std::fs; +use adw::prelude::*; +use gtk::{gdk, gio, CssProvider}; use rust_i18n::Backend; use std::collections::HashMap; use std::env; -use adw::prelude::*; -use gtk::{gio,gdk,CssProvider}; +use std::fs; use crate::gdk::Display; @@ -19,18 +19,28 @@ pub struct I18nBackend { impl I18nBackend { fn new() -> Self { let mut trs = HashMap::new(); - let locales_dir = fs::read_dir("/usr/lib/pika/kernel-manager/locales").expect("No translation files found"); + let locales_dir = fs::read_dir("/usr/lib/pika/kernel-manager/locales") + .expect("No translation files found"); for locale_file in locales_dir { - let locale_file_path = locale_file.expect("couldn't change dir entry to path").path(); - let locale = String::from(locale_file_path.file_name().unwrap().to_str().unwrap().trim_end_matches(".json")); - let locale_data = fs::read_to_string(locale_file_path).expect(format!("invalid json for {}", locale).as_str()); - let locale_json = serde_json::from_str::>(&locale_data).unwrap(); + let locale_file_path = locale_file + .expect("couldn't change dir entry to path") + .path(); + let locale = String::from( + locale_file_path + .file_name() + .unwrap() + .to_str() + .unwrap() + .trim_end_matches(".json"), + ); + let locale_data = fs::read_to_string(locale_file_path) + .expect(format!("invalid json for {}", locale).as_str()); + let locale_json = + serde_json::from_str::>(&locale_data).unwrap(); trs.insert(locale.to_string(), locale_json); } - return Self { - trs - }; + return Self { trs }; } } @@ -64,12 +74,15 @@ struct KernelPackage { main_package: String, packages: String, package_version: String, - description: String + description: String, } fn main() -> glib::ExitCode { let current_locale = match env::var_os("LANG") { - Some(v) => v.into_string().unwrap().chars() + Some(v) => v + .into_string() + .unwrap() + .chars() .take_while(|&ch| ch != '.') .collect::(), None => panic!("$LANG is not set"), diff --git a/src/sched_ext/mod.rs b/src/sched_ext/mod.rs index 2555a58..74e0a42 100644 --- a/src/sched_ext/mod.rs +++ b/src/sched_ext/mod.rs @@ -8,7 +8,11 @@ use std::rc::Rc; use std::time::Duration; use std::{fs, io, thread}; -pub fn sched_ext_page(content_stack: >k::Stack, window: &adw::ApplicationWindow, badge_box: &adw::Bin) -> gtk::Box { +pub fn sched_ext_page( + content_stack: >k::Stack, + window: &adw::ApplicationWindow, + badge_box: &adw::Bin, +) -> gtk::Box { let main_box = gtk::Box::builder() .hexpand(true) .vexpand(true) @@ -258,9 +262,7 @@ SCX_SCHED="$0" pkexec /usr/lib/pika/kernel-manager/scripts/change_scx.sh "${SCX_SCHED}" "###; -fn change_scx_scheduler( - scx_sched: &str, -) -> Result<(), io::Error> { +fn change_scx_scheduler(scx_sched: &str) -> Result<(), io::Error> { cmd!("bash", "-c", CHANGE_SCX_PROG, scx_sched).run()?; Ok(()) }