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]] [[package]]
name = "pika-kernel-manager" name = "pika-kernel-manager"
version = "0.1.4" version = "0.1.5"
dependencies = [ dependencies = [
"async-channel", "async-channel",
"duct", "duct",

View File

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

View File

@ -41,3 +41,11 @@
border-bottom-right-radius: 15px; border-bottom-right-radius: 15px;
border-bottom-left-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 pika-kernel-manager (0.1.3-101pika5) pika; urgency=low
* Initial Release * Initial Release

View File

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

View File

@ -1,8 +1,8 @@
use crate::content;
use crate::APP_GITHUB; use crate::APP_GITHUB;
use crate::APP_ICON; use crate::APP_ICON;
use crate::APP_ID; use crate::APP_ID;
use crate::VERSION; use crate::VERSION;
use crate::content;
use adw::prelude::*; use adw::prelude::*;
use adw::*; use adw::*;
use glib::{clone, MainContext}; 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())); gtk::glib::set_prgname(Some(t!("application_name").to_string()));
glib::set_application_name(&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_connected = Rc::new(RefCell::new(false));
let (internet_loop_sender, internet_loop_receiver) = async_channel::unbounded(); 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) .startup_id(APP_ID)
.build(); .build();
content_stack.add_named( let (gsettings_change_sender, gsettings_change_receiver) = async_channel::unbounded();
&content::content( let gsettings_change_sender_clone0 = gsettings_change_sender.clone();
&content_stack,
&window, 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"), Some("content_page"),
); );
@ -127,7 +162,6 @@ fn load_icon_theme(window: &adw::ApplicationWindow) {
let icon_theme = gtk::IconTheme::for_display(&WidgetExt::display(window)); 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/");
icon_theme.add_resource_path( icon_theme
"/com/github/pikaos-linux/pika-kernel-manager/icons/scalable/actions/", .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 std::{fs, time};
use version_compare::Version; use version_compare::Version;
pub fn content( pub fn content(content_stack: &gtk::Stack, window: &adw::ApplicationWindow, theme_changed_action: &gio::SimpleAction) -> gtk::Box {
content_stack: &gtk::Stack,
window: &adw::ApplicationWindow,
) -> gtk::Box {
let content_box = gtk::Box::builder() let content_box = gtk::Box::builder()
.hexpand(true) .hexpand(true)
.vexpand(true) .vexpand(true)
@ -38,10 +35,7 @@ pub fn content(
.orientation(Orientation::Vertical) .orientation(Orientation::Vertical)
.build(); .build();
let sched_ext_badge_box = adw::Bin::builder() let sched_ext_badge_box = adw::Bin::builder().hexpand(true).vexpand(true).build();
.hexpand(true)
.vexpand(true)
.build();
let button_box = gtk::Box::builder() let button_box = gtk::Box::builder()
.orientation(Orientation::Horizontal) .orientation(Orientation::Horizontal)
@ -65,12 +59,10 @@ pub fn content(
.build(); .build();
browse_kernels_button.add_css_class("circular"); browse_kernels_button.add_css_class("circular");
browse_kernels_button.connect_clicked( browse_kernels_button.connect_clicked(clone!(@weak window, @weak content_stack => move |_| {
clone!(@weak window, @weak content_stack => move |_| {
kernel_pkg::kernel_pkg_page(&content_stack, &window); kernel_pkg::kernel_pkg_page(&content_stack, &window);
content_stack.set_visible_child_name("kernel_pkg_page") content_stack.set_visible_child_name("kernel_pkg_page")
}), }));
);
let config_kernel_button = gtk::Button::builder() let config_kernel_button = gtk::Button::builder()
.icon_name("emblem-system-symbolic") .icon_name("emblem-system-symbolic")
@ -86,24 +78,28 @@ pub fn content(
if !is_scx_kernel() { if !is_scx_kernel() {
config_kernel_button.set_sensitive(false); config_kernel_button.set_sensitive(false);
config_kernel_button config_kernel_button.set_tooltip_text(Some(
.set_tooltip_text(Some(&t!("config_kernel_button_tooltip_text_no_scx").to_string())); &t!("config_kernel_button_tooltip_text_no_scx").to_string(),
));
} else if is_scx_kernel() && !is_scx_installed() { } else if is_scx_kernel() && !is_scx_installed() {
config_kernel_button.set_sensitive(false); config_kernel_button.set_sensitive(false);
config_kernel_button config_kernel_button.set_tooltip_text(Some(
.set_tooltip_text(Some(&t!("config_kernel_button_tooltip_text_no_scx_installed").to_string())); &t!("config_kernel_button_tooltip_text_no_scx_installed").to_string(),
));
} }
// DEBUG // DEBUG
//config_kernel_button.set_sensitive(true); //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( content_stack.add_named(
&sched_ext::sched_ext_page(&content_stack, &window, &sched_ext_badge_box), &sched_ext::sched_ext_page(&content_stack, &window, &sched_ext_badge_box),
Some("sched_ext_page"), Some("sched_ext_page"),
); );
content_stack.set_visible_child_name("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_receiver) = async_channel::unbounded();
let load_badge_async_sender = load_badge_async_sender.clone(); let load_badge_async_sender = load_badge_async_sender.clone();
@ -117,13 +113,15 @@ pub fn content(
let load_badge_async_context = MainContext::default(); let load_badge_async_context = MainContext::default();
// The main loop executes the asynchronous block // 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 { while let Ok(_state) = load_badge_async_receiver.recv().await {
let running_kernel_info = get_running_kernel_info(); let running_kernel_info = get_running_kernel_info();
create_kernel_badges(&kernel_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); create_current_sched_badge(&sched_ext_badge_box, &running_kernel_info, &theme_changed_action);
} }
})); }),
);
button_box.append(&browse_kernels_button); button_box.append(&browse_kernels_button);
button_box.append(&config_kernel_button); button_box.append(&config_kernel_button);
@ -139,6 +137,7 @@ pub fn create_kernel_badge(
label0_text: &str, label0_text: &str,
label1_text: &str, label1_text: &str,
css_style: &str, css_style: &str,
theme_changed_action: &gio::SimpleAction,
group_size: &gtk::SizeGroup, group_size: &gtk::SizeGroup,
group_size0: &gtk::SizeGroup, group_size0: &gtk::SizeGroup,
group_size1: &gtk::SizeGroup, group_size1: &gtk::SizeGroup,
@ -175,6 +174,38 @@ pub fn create_kernel_badge(
label1.add_css_class(css_style); 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(&label0);
badge_box.append(&label_seprator); badge_box.append(&label_seprator);
badge_box.append(&label1); badge_box.append(&label1);
@ -263,22 +294,22 @@ fn bore_check() -> bool {
is_bore is_bore
} }
fn create_kernel_badges( fn create_kernel_badges(badge_box: &gtk::Box, running_kernel_info: &RunningKernelInfo, theme_changed_action: &gio::SimpleAction) {
badge_box: &gtk::Box,
running_kernel_info: &RunningKernelInfo,
) {
let kernel_badges_size_group = gtk::SizeGroup::new(SizeGroupMode::Both); let kernel_badges_size_group = gtk::SizeGroup::new(SizeGroupMode::Both);
let kernel_badges_size_group0 = 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 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") .arg("version")
.output() .output()
.unwrap(); .unwrap();
let kernel_version = String::from_utf8(command_get_kernel_pika.stdout).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" "background-green-bg"
} else { } else {
"background-red-bg" "background-red-bg"
@ -292,6 +323,7 @@ fn create_kernel_badges(
&t!("kernel_badge_latest_version_label").to_string(), &t!("kernel_badge_latest_version_label").to_string(),
&kernel_version, &kernel_version,
"background-accent-bg", "background-accent-bg",
&theme_changed_action,
&kernel_badges_size_group, &kernel_badges_size_group,
&kernel_badges_size_group0, &kernel_badges_size_group0,
&kernel_badges_size_group1, &kernel_badges_size_group1,
@ -300,6 +332,7 @@ fn create_kernel_badges(
&t!("kernel_badge_running_version_label").to_string(), &t!("kernel_badge_running_version_label").to_string(),
&running_kernel_info.version, &running_kernel_info.version,
&version_css_style, &version_css_style,
&theme_changed_action,
&kernel_badges_size_group, &kernel_badges_size_group,
&kernel_badges_size_group0, &kernel_badges_size_group0,
&kernel_badges_size_group1, &kernel_badges_size_group1,
@ -308,6 +341,7 @@ fn create_kernel_badges(
&t!("kernel_badge_running_kernel_label").to_string(), &t!("kernel_badge_running_kernel_label").to_string(),
&running_kernel_info.kernel, &running_kernel_info.kernel,
&version_css_style, &version_css_style,
&theme_changed_action,
&kernel_badges_size_group, &kernel_badges_size_group,
&kernel_badges_size_group0, &kernel_badges_size_group0,
&kernel_badges_size_group1, &kernel_badges_size_group1,
@ -316,16 +350,14 @@ fn create_kernel_badges(
&t!("kernel_badge_running_sched_label").to_string(), &t!("kernel_badge_running_sched_label").to_string(),
&running_kernel_info.sched.trim(), &running_kernel_info.sched.trim(),
"background-accent-bg", "background-accent-bg",
&theme_changed_action,
&kernel_badges_size_group, &kernel_badges_size_group,
&kernel_badges_size_group0, &kernel_badges_size_group0,
&kernel_badges_size_group1, &kernel_badges_size_group1,
)); ));
} }
fn create_current_sched_badge( fn create_current_sched_badge(badge_box: &adw::Bin, running_kernel_info: &RunningKernelInfo, theme_changed_action: &gio::SimpleAction) {
badge_box: &adw::Bin,
running_kernel_info: &RunningKernelInfo,
) {
//while let Some(widget) = badge_box.last_child() { //while let Some(widget) = badge_box.last_child() {
// badge_box.remove(&widget); // badge_box.remove(&widget);
//} //}
@ -338,6 +370,7 @@ fn create_current_sched_badge(
&t!("kernel_badge_running_sched_label").to_string(), &t!("kernel_badge_running_sched_label").to_string(),
&running_kernel_info.sched, &running_kernel_info.sched,
"background-accent-bg", "background-accent-bg",
&theme_changed_action,
&kernel_badges_size_group, &kernel_badges_size_group,
&kernel_badges_size_group0, &kernel_badges_size_group0,
&kernel_badges_size_group1, &kernel_badges_size_group1,
@ -345,10 +378,8 @@ fn create_current_sched_badge(
} }
fn is_scx_installed() -> bool { fn is_scx_installed() -> bool {
match Command::new("systemctl") match Command::new("systemctl").args(["status", "scx"]).output() {
.args(["status", "scx"])
.output() {
Ok(t) if t.status.code().unwrap() != 4 => true, 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::*;
use adw::{prelude::*, subclass::prelude::*}; use adw::{prelude::*, subclass::prelude::*};
use glib::{subclass::Signal, Properties}; use glib::{subclass::Signal, Properties};
use gtk::{glib}; use gtk::glib;
// ANCHOR: custom_button // ANCHOR: custom_button
// Object holding the state // Object holding the state

View File

@ -10,20 +10,19 @@ use std::io::BufReader;
use std::process::Command; use std::process::Command;
use std::time::*; use std::time::*;
pub fn kernel_pkg_page( pub fn kernel_pkg_page(content_stack: &gtk::Stack, window: &adw::ApplicationWindow) {
content_stack: &gtk::Stack,
window: &adw::ApplicationWindow,
) {
let parse_loading_dialog = adw::MessageDialog::builder() let parse_loading_dialog = adw::MessageDialog::builder()
.transient_for(window) .transient_for(window)
.extra_child(&gtk::Spinner::builder() .extra_child(
&gtk::Spinner::builder()
.hexpand(true) .hexpand(true)
.valign(Align::Start) .valign(Align::Start)
.halign(Align::Center) .halign(Align::Center)
.spinning(true) .spinning(true)
.height_request(128) .height_request(128)
.width_request(128) .width_request(128)
.build()) .build(),
)
.heading(t!("parse_loading_dialog_heading")) .heading(t!("parse_loading_dialog_heading"))
.body(t!("parse_loading_dialog_body")) .body(t!("parse_loading_dialog_body"))
.build(); .build();
@ -74,10 +73,7 @@ pub fn kernel_pkg_page(
.build(); .build();
searchbar.add_css_class("rounded-all-25"); searchbar.add_css_class("rounded-all-25");
content_stack.add_named( content_stack.add_named(&main_box, Some("kernel_pkg_page"));
&main_box,
Some("kernel_pkg_page"),
);
let packages_boxedlist = gtk::ListBox::builder() let packages_boxedlist = gtk::ListBox::builder()
.selection_mode(SelectionMode::None) .selection_mode(SelectionMode::None)
@ -94,7 +90,7 @@ pub fn kernel_pkg_page(
&window, &window,
&rows_size_group, &rows_size_group,
&searchbar, &searchbar,
&parse_loading_dialog &parse_loading_dialog,
); );
let packages_viewport = gtk::ScrolledWindow::builder() let packages_viewport = gtk::ScrolledWindow::builder()
@ -147,7 +143,7 @@ fn add_package_rows(
window: &adw::ApplicationWindow, window: &adw::ApplicationWindow,
rows_size_group: &gtk::SizeGroup, rows_size_group: &gtk::SizeGroup,
searchbar: &gtk::SearchEntry, 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_receiver) = async_channel::unbounded();
let kernel_package_sender = kernel_package_sender.clone(); 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(); let kernel_package_done_sender = kernel_package_done_sender.clone();
std::thread::spawn(move || { 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") .arg("list")
.output() .output()
.unwrap(); .unwrap();
@ -166,19 +163,20 @@ fn add_package_rows(
let kernel_version = &kernel.trim_end_matches("-pikaos"); let kernel_version = &kernel.trim_end_matches("-pikaos");
let kernel_name = format!("PikaOS Linux Kernel {}", kernel_version); let kernel_name = format!("PikaOS Linux Kernel {}", kernel_version);
let kernel_main_package = format!("linux-image-{}", &kernel); let kernel_main_package = format!("linux-image-{}", &kernel);
let kernel_packages = format!("linux-image-{VERSION} linux-headers-{VERSION}", VERSION=kernel); let kernel_packages = format!(
let kernel_package_version = match Command::new( "linux-image-{VERSION} linux-headers-{VERSION}",
"/usr/lib/pika/kernel-manager/scripts/generate_package_info.sh", VERSION = kernel
) );
let kernel_package_version =
match Command::new("/usr/lib/pika/kernel-manager/scripts/generate_package_info.sh")
.args(["version", &kernel_main_package]) .args(["version", &kernel_main_package])
.output() .output()
{ {
Ok(t) => String::from_utf8(t.stdout).unwrap(), Ok(t) => String::from_utf8(t.stdout).unwrap(),
_ => "Error".to_owned(), _ => "Error".to_owned(),
}; };
let kernel_description = match Command::new( let kernel_description =
"/usr/lib/pika/kernel-manager/scripts/generate_package_info.sh", match Command::new("/usr/lib/pika/kernel-manager/scripts/generate_package_info.sh")
)
.args(["description", &kernel_main_package]) .args(["description", &kernel_main_package])
.output() .output()
{ {
@ -191,11 +189,15 @@ fn add_package_rows(
main_package: kernel_main_package, main_package: kernel_main_package,
packages: kernel_packages, packages: kernel_packages,
package_version: kernel_package_version, 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_sender
}; .send_blocking(kernel_package)
kernel_package_done_sender.send_blocking(true).expect("Kernel Package done sender channel closed") .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(); 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( fn kernel_modify(
log_loop_sender: async_channel::Sender<String>, log_loop_sender: async_channel::Sender<String>,
kernel_pkg: &str, kernel_pkg: &str,
install: bool install: bool,
) -> Result<(), std::boxed::Box<dyn Error + Send + Sync>> { ) -> Result<(), std::boxed::Box<dyn Error + Send + Sync>> {
let kernel_modify_prog = if install { let kernel_modify_prog = if install {
KERNEL_INSTALL_PROG KERNEL_INSTALL_PROG

View File

@ -4,12 +4,12 @@ mod kernel_package_row;
mod kernel_pkg; mod kernel_pkg;
mod sched_ext; mod sched_ext;
use std::fs; use adw::prelude::*;
use gtk::{gdk, gio, CssProvider};
use rust_i18n::Backend; use rust_i18n::Backend;
use std::collections::HashMap; use std::collections::HashMap;
use std::env; use std::env;
use adw::prelude::*; use std::fs;
use gtk::{gio,gdk,CssProvider};
use crate::gdk::Display; use crate::gdk::Display;
@ -19,18 +19,28 @@ pub struct I18nBackend {
impl I18nBackend { impl I18nBackend {
fn new() -> Self { fn new() -> Self {
let mut trs = HashMap::new(); 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 { for locale_file in locales_dir {
let locale_file_path = locale_file.expect("couldn't change dir entry to path").path(); let locale_file_path = locale_file
let locale = String::from(locale_file_path.file_name().unwrap().to_str().unwrap().trim_end_matches(".json")); .expect("couldn't change dir entry to path")
let locale_data = fs::read_to_string(locale_file_path).expect(format!("invalid json for {}", locale).as_str()); .path();
let locale_json = serde_json::from_str::<HashMap<String, String>>(&locale_data).unwrap(); 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); trs.insert(locale.to_string(), locale_json);
} }
return Self { return Self { trs };
trs
};
} }
} }
@ -64,12 +74,15 @@ struct KernelPackage {
main_package: String, main_package: String,
packages: String, packages: String,
package_version: String, package_version: String,
description: String description: String,
} }
fn main() -> glib::ExitCode { fn main() -> glib::ExitCode {
let current_locale = match env::var_os("LANG") { 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 != '.') .take_while(|&ch| ch != '.')
.collect::<String>(), .collect::<String>(),
None => panic!("$LANG is not set"), None => panic!("$LANG is not set"),

View File

@ -8,7 +8,11 @@ use std::rc::Rc;
use std::time::Duration; use std::time::Duration;
use std::{fs, io, thread}; 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() let main_box = gtk::Box::builder()
.hexpand(true) .hexpand(true)
.vexpand(true) .vexpand(true)
@ -258,9 +262,7 @@ SCX_SCHED="$0"
pkexec /usr/lib/pika/kernel-manager/scripts/change_scx.sh "${SCX_SCHED}" pkexec /usr/lib/pika/kernel-manager/scripts/change_scx.sh "${SCX_SCHED}"
"###; "###;
fn change_scx_scheduler( fn change_scx_scheduler(scx_sched: &str) -> Result<(), io::Error> {
scx_sched: &str,
) -> Result<(), io::Error> {
cmd!("bash", "-c", CHANGE_SCX_PROG, scx_sched).run()?; cmd!("bash", "-c", CHANGE_SCX_PROG, scx_sched).run()?;
Ok(()) Ok(())
} }