add db data to kernel branch struct

This commit is contained in:
Ward from fusion-voyager-3 2024-06-18 21:13:04 +03:00
parent b219774cb7
commit 373a34434a
6 changed files with 886 additions and 4 deletions

877
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -14,6 +14,7 @@ glib = "0.19.7"
gtk = { version = "0.8.2", package = "gtk4", features = ["v4_14"] } gtk = { version = "0.8.2", package = "gtk4", features = ["v4_14"] }
homedir = "0.2.1" homedir = "0.2.1"
linux-version = "0.1.1" linux-version = "0.1.1"
reqwest = { version = "0.11", features = ["blocking"] }
serde_json = "1.0.117" serde_json = "1.0.117"
version-compare = "0.2.0" version-compare = "0.2.0"

View File

@ -2,7 +2,7 @@
"branches": [ "branches": [
{ {
"name": "kernel-cachyos", "name": "kernel-cachyos",
"db": "https://raw.githubusercontent.com/CosmicFusion/fedora-kernel-manager/main/data/db_kernel_cachy.json" "db_url": "https://raw.githubusercontent.com/CosmicFusion/fedora-kernel-manager/main/data/db_kernel_cachy.json"
} }
] ]
} }

View File

@ -12,7 +12,7 @@ use glib::property::PropertyGet;
pub fn build_ui(app: &adw::Application) { pub fn build_ui(app: &adw::Application) {
let internet_connected = Rc::new(RefCell::new(false)); let internet_connected = Rc::new(RefCell::new(false));
let selected_kernel_branch: Rc<RefCell<KernelBranch>> = Rc::new(RefCell::new(KernelBranch{name: "?".to_owned(), db:"?".to_owned()})); let selected_kernel_branch: Rc<RefCell<KernelBranch>> = Rc::new(RefCell::new(KernelBranch{name: "?".to_owned(), db_url:"?".to_owned() , db:"?".to_owned()}));
let (internet_loop_sender, internet_loop_receiver) = async_channel::unbounded(); let (internet_loop_sender, internet_loop_receiver) = async_channel::unbounded();
let internet_loop_sender = internet_loop_sender.clone(); let internet_loop_sender = internet_loop_sender.clone();

View File

@ -284,9 +284,12 @@ fn get_kernel_branches() -> Vec<KernelBranch> {
let res: serde_json::Value = serde_json::from_str(&data).expect("Unable to parse"); let res: serde_json::Value = serde_json::from_str(&data).expect("Unable to parse");
if let serde_json::Value::Array(branches) = &res["branches"] { if let serde_json::Value::Array(branches) = &res["branches"] {
for branch in branches { for branch in branches {
println!("Downloading & Parsing package DB for {}.", branch.name);
let branch = KernelBranch { let branch = KernelBranch {
name: branch["name"].as_str().to_owned().unwrap().to_string(), name: branch["name"].as_str().to_owned().unwrap().to_string(),
db: branch["db"].as_str().to_owned().unwrap().to_string(), db_url: branch["db_url"].as_str().to_owned().unwrap().to_string(),
db: reqwest::blocking::get(branch["db_url"].as_str().to_owned().unwrap().to_string(),).unwrap().text().unwrap()
}; };
kernel_branches_array.push(branch) kernel_branches_array.push(branch)
}}; }};

View File

@ -20,6 +20,7 @@ struct RunningKernelInfo {
#[derive(Clone)] #[derive(Clone)]
struct KernelBranch { struct KernelBranch {
name: String, name: String,
db_url: String,
db: String, db: String,
} }