make json versitile

This commit is contained in:
Ward from fusion-voyager-3 2024-06-22 20:58:48 +03:00
parent 9d33a1ea43
commit 9cd9f6dd8f
5 changed files with 40 additions and 45 deletions

View File

@ -13,13 +13,13 @@ install_no_build:
cp -rvf data/scripts $(DESTDIR)/usr/lib/fedora-kernel-manager/
chmod 755 $(DESTDIR)/usr/lib/fedora-kernel-manager/scripts/*.sh
cp -rvf data/locales $(DESTDIR)/usr/lib/fedora-kernel-manager/
cp -vf data/kernel_branches.json $(DESTDIR)/usr/lib/fedora-kernel-manager/
cp -rvf data/kernel_branches $(DESTDIR)/usr/lib/fedora-kernel-manager/
cp -vf data/scx_scheds.json $(DESTDIR)/usr/lib/fedora-kernel-manager/
mkdir -p $(DESTDIR)/usr/share/applications
mkdir -p $(DESTDIR)/usr/share/icons/hicolor/scalable/apps
cp -vf data/com.github.cosmicfusion.fedora-kernel-manager.svg $(DESTDIR)/usr/share/icons/hicolor/scalable/apps/
cp -vf data/com.github.cosmicfusion.fedora-kernel-manager.desktop $(DESTDIR)/usr/share/applications/
cp -vf data/polkit-1 $(DESTDIR)/usr/share/
cp -rvf data/polkit-1 $(DESTDIR)/usr/share/
install:
mkdir -p $(DESTDIR)/usr/bin/
@ -30,10 +30,10 @@ install:
mkdir -p $(DESTDIR)/usr/lib/fedora-kernel-manager/
cp -rvf data/scripts $(DESTDIR)/usr/lib/fedora-kernel-manager/
chmod 755 $(DESTDIR)/usr/lib/fedora-kernel-manager/scripts/*.sh
cp -vf data/kernel_branches.json $(DESTDIR)/usr/lib/fedora-kernel-manager/
cp -rvf data/kernel_branches $(DESTDIR)/usr/lib/fedora-kernel-manager/
cp -vf data/scx_scheds.json $(DESTDIR)/usr/lib/fedora-kernel-manager/
mkdir -p $(DESTDIR)/usr/share/applications
mkdir -p $(DESTDIR)/usr/share/icons/hicolor/scalable/apps
cp -vf data/com.github.cosmicfusion.fedora-kernel-manager.svg $(DESTDIR)/usr/share/icons/hicolor/scalable/apps/
cp -vf data/com.github.cosmicfusion.fedora-kernel-manager.desktop $(DESTDIR)/usr/share/applications/
cp -vf data/polkit-1 $(DESTDIR)/usr/share/
cp -rvf data/polkit-1 $(DESTDIR)/usr/share/

BIN
core

Binary file not shown.

View File

@ -1,9 +0,0 @@
{
"branches": [
{
"name": "kernel-cachyos",
"db_url": "https://raw.githubusercontent.com/CosmicFusion/fedora-kernel-manager/main/data/db_kernel_cachy.json",
"init_script": "pkexec /usr/lib/fedora-kernel-manager/scripts/kernel-cachyos-init.sh"
}
]
}

View File

@ -0,0 +1,5 @@
{
"name": "kernel-cachyos",
"db_url": "https://raw.githubusercontent.com/CosmicFusion/fedora-kernel-manager/main/data/db_kernel_cachy.json",
"init_script": "pkexec /usr/lib/fedora-kernel-manager/scripts/kernel-cachyos-init.sh"
}

View File

@ -149,7 +149,7 @@ pub fn content(
.height_request(50)
.width_request(50)
.tooltip_text(t!("config_kernel_button_tooltip_text"))
.sensitive(!is_scx_kernel())
.sensitive(is_scx_kernel())
.hexpand(true)
.build();
config_kernel_button.add_css_class("circular");
@ -379,11 +379,11 @@ pub fn create_kernel_badge(
fn get_kernel_branches() -> Result<Vec<KernelBranch>, reqwest::Error> {
let mut kernel_branches_array: Vec<KernelBranch> = Vec::new();
let data = fs::read_to_string("/usr/lib/fedora-kernel-manager/kernel_branches.json")
.expect("Unable to read file");
let res: serde_json::Value = serde_json::from_str(&data).expect("Unable to parse");
if let serde_json::Value::Array(branches) = &res["branches"] {
for branch in branches {
let kernel_branch_files_dir = fs::read_dir("/usr/lib/fedora-kernel-manager/kernel_branches").expect("No Kernel json files found");
for kernel_branch_file in kernel_branch_files_dir {
let kernel_branch_file_path = kernel_branch_file.expect("couldn't change dir entry to path").path();
let kernel_branch_data = fs::read_to_string(kernel_branch_file_path).expect("some json is invalid");
let branch: serde_json::Value = serde_json::from_str(&kernel_branch_data).expect("some json is invalid");
let branch_name = branch["name"].as_str().to_owned().unwrap().to_string();
let branch_db_url = branch["db_url"].as_str().to_owned().unwrap().to_string();
let branch_init_script = branch["init_script"]
@ -409,7 +409,6 @@ fn get_kernel_branches() -> Result<Vec<KernelBranch>, reqwest::Error> {
_ => println!("{} {}", &branch.name, t!("db_init_script_failed")),
};
kernel_branches_array.push(branch)
}
};
Ok(kernel_branches_array)