UI Refine
All checks were successful
PikaOS Package Build & Release (amd64-v3) / build (push) Successful in 1m55s

This commit is contained in:
Ward from fusion-voyager-3 2024-10-26 22:58:27 +03:00
parent 9916e48906
commit 97fb639b68
12 changed files with 222 additions and 126 deletions

View File

@ -1 +1 @@
6
7

2
Cargo.lock generated
View File

@ -1428,7 +1428,7 @@ checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e"
[[package]]
name = "pika-kernel-manager"
version = "0.1.4"
version = "0.1.5"
dependencies = [
"async-channel",
"duct",

View File

@ -1,6 +1,6 @@
[package]
name = "pika-kernel-manager"
version = "0.1.4"
version = "0.1.5"
edition = "2021"

View File

@ -41,3 +41,11 @@
border-bottom-right-radius: 15px;
border-bottom-left-radius: 15px;
}
.black-color-text {
color: black;
}
.white-color-text {
color: white;
}

6
debian/changelog vendored
View File

@ -1,3 +1,9 @@
pika-kernel-manager (0.1.5-101pika1) pika; urgency=low
* UI Refine
-- Ward Nakchbandi <hotrod.master@hotmail.com> Sat, 01 Oct 2022 14:50:00 +0200
pika-kernel-manager (0.1.3-101pika5) pika; urgency=low
* Initial Release

View File

@ -2,7 +2,7 @@
set -e
VERSION="0.1.3"
VERSION="0.1.5"
source ./pika-build-config.sh

View File

@ -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();
content_stack.add_named(
&content::content(
&content_stack,
&window,
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, &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/");
}

View File

@ -8,10 +8,7 @@ use std::process::{Command, Stdio};
use std::{fs, time};
use version_compare::Version;
pub fn content(
content_stack: &gtk::Stack,
window: &adw::ApplicationWindow,
) -> gtk::Box {
pub fn content(content_stack: &gtk::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 |_| {
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 |_| {
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,13 +113,15 @@ 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 {
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);
create_current_sched_badge(&sched_ext_badge_box, &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);
@ -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: &gtk::SizeGroup,
group_size0: &gtk::SizeGroup,
group_size1: &gtk::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: &gtk::Box,
running_kernel_info: &RunningKernelInfo,
) {
fn create_kernel_badges(badge_box: &gtk::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")
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,
}
}

View File

@ -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

View File

@ -10,20 +10,19 @@ use std::io::BufReader;
use std::process::Command;
use std::time::*;
pub fn kernel_pkg_page(
content_stack: &gtk::Stack,
window: &adw::ApplicationWindow,
) {
pub fn kernel_pkg_page(content_stack: &gtk::Stack, window: &adw::ApplicationWindow) {
let parse_loading_dialog = adw::MessageDialog::builder()
.transient_for(window)
.extra_child(&gtk::Spinner::builder()
.extra_child(
&gtk::Spinner::builder()
.hexpand(true)
.valign(Align::Start)
.halign(Align::Center)
.spinning(true)
.height_request(128)
.width_request(128)
.build())
.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: &gtk::SizeGroup,
searchbar: &gtk::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,7 +152,8 @@ 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")
let command_get_kernel_pika =
Command::new("/usr/lib/pika/kernel-manager/scripts/get_kernel_pika.sh")
.arg("list")
.output()
.unwrap();
@ -166,19 +163,20 @@ fn add_package_rows(
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",
)
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{
let kernel_package = KernelPackage {
name: kernel_name,
main_package: kernel_main_package,
packages: kernel_packages,
package_version: kernel_package_version,
description: kernel_description
description: kernel_description,
};
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")
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<String>,
kernel_pkg: &str,
install: bool
install: bool,
) -> Result<(), std::boxed::Box<dyn Error + Send + Sync>> {
let kernel_modify_prog = if install {
KERNEL_INSTALL_PROG

View File

@ -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::<HashMap<String, String>>(&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::<HashMap<String, String>>(&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::<String>(),
None => panic!("$LANG is not set"),

View File

@ -8,7 +8,11 @@ use std::rc::Rc;
use std::time::Duration;
use std::{fs, io, thread};
pub fn sched_ext_page(content_stack: &gtk::Stack, window: &adw::ApplicationWindow, badge_box: &adw::Bin) -> gtk::Box {
pub fn sched_ext_page(
content_stack: &gtk::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(())
}