From 509746951cb6869deee12cd1cf9177393253f14e Mon Sep 17 00:00:00 2001 From: Ward from fusion-voyager-3 Date: Fri, 23 Feb 2024 17:50:02 +0300 Subject: [PATCH] Update json --- Cargo.toml | 3 +++ driver-db.json | 36 ++++++++++++++++++------------------ src/build_ui/mod.rs | 36 ++++++++++++++++++++++++++---------- 3 files changed, 47 insertions(+), 28 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 33561e3..5c173a2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,3 +13,6 @@ duct = "0.13.7" os_pipe = "1.1.5" rust-i18n = "3.0.1" users = "0.11.0" +serde = { version = "1.0", features = ["derive"] } +serde_json = "1.0" +reqwest = { version = "0.11", features = ["blocking", "json"] } diff --git a/driver-db.json b/driver-db.json index b84c840..066da25 100644 --- a/driver-db.json +++ b/driver-db.json @@ -1,100 +1,100 @@ { - "drivers": { - "pika-rocm-meta": { + "drivers": [ + { "driver": "pika-rocm-meta", "icon": "amd", "experimental": false, "detection": "inxi -G | grep driver | grep -i amdgpu" }, - "vulkan-amdgpu-pro": { + { "driver": "vulkan-amdgpu-pro", "icon": "amd", "experimental": false, "detection": "inxi -G | grep driver | grep -i amdgpu" }, - "amf-amdgpu-pro": { + { "driver": "amf-amdgpu-pro", "icon": "amd", "experimental": false, "detection": "inxi -G | grep driver | grep -i amdgpu" }, - "amdvlk": { + { "driver": "amdvlk", "icon": "amd", "experimental": false, "detection": "inxi -G | grep driver | grep -i amdgpu" }, - "opencl-legacy-amdgpu-pro-icd": { + { "driver": "opencl-legacy-amdgpu-pro-icd", "icon": "amd", "experimental": false, "detection": "inxi -G | grep driver | grep -i amdgpu" }, - "amdgpu-pro-oglp": { + { "driver": "amdgpu-pro-oglp", "icon": "amd", "experimental": false, "detection": "inxi -G | grep driver | grep -i amdgpu" }, - "nvidia-driver-525": { + { "driver": "nvidia-driver-525", "icon": "nvidia", "experimental": false, "detection": "lspci -D | grep -iE 'VGA|3D' | grep -i nvidia | cut -d: -f 4" }, - "nvidia-driver-525-open": { + { "driver": "nvidia-driver-525-open", "icon": "nvidia", "experimental": true, "detection": "lspci -D | grep -iE 'VGA|3D' | grep -i nvidia | cut -d: -f 4" }, - "nvidia-driver-535": { + { "driver": "nvidia-driver-535", "icon": "nvidia", "experimental": false, "detection": "lspci -D | grep -iE 'VGA|3D' | grep -i nvidia | cut -d: -f 4" }, - "nvidia-driver-535-open": { + { "driver": "nvidia-driver-535-open", "icon": "nvidia", "experimental": true, "detection": "lspci -D | grep -iE 'VGA|3D' | grep -i nvidia | cut -d: -f 4" }, - "nvidia-driver-545": { + { "driver": "nvidia-driver-545", "icon": "nvidia", "experimental": false, "detection": "lspci -D | grep -iE 'VGA|3D' | grep -i nvidia | cut -d: -f 4" }, - "nvidia-driver-545-open": { + { "driver": "nvidia-driver-545-open", "icon": "nvidia", "experimental": true, "detection": "lspci -D | grep -iE 'VGA|3D' | grep -i nvidia | cut -d: -f 4" }, - "nvidia-driver-550": { + { "driver": "nvidia-driver-550", "icon": "nvidia", "experimental": true, "detection": "lspci -D | grep -iE 'VGA|3D' | grep -i nvidia | cut -d: -f 4" }, - "nvidia-driver-550-open": { + { "driver": "nvidia-driver-550-open", "icon": "nvidia", "experimental": true, "detection": "lspci -D | grep -iE 'VGA|3D' | grep -i nvidia | cut -d: -f 4" }, - "xone-dkms": { + { "driver": "xone-dkms", "icon": "input-gaming", "experimental": false, "detection": "lsusb | grep -i xbox" }, - "intel-gpu-compute": { + { "driver": "intel-gpu-compute", "icon": "intel", "experimental": false, "detection": "inxi -G | grep driver | grep -i intel" } - } + ] } \ No newline at end of file diff --git a/src/build_ui/mod.rs b/src/build_ui/mod.rs index b336e81..3619515 100644 --- a/src/build_ui/mod.rs +++ b/src/build_ui/mod.rs @@ -1,3 +1,5 @@ +use std::path::Path; +use std::fs; use crate::config::*; use crate::save_window_size::save_window_size; use crate::DriverPackage; @@ -12,8 +14,12 @@ use std::error::Error; use std::io::BufRead; use std::io::BufReader; use std::process::Command; + use users::*; +use serde_json::json; +use serde_json::Value; + pub fn build_ui(app: &adw::Application) { gtk::glib::set_prgname(Some(APP_NAME)); glib::set_application_name(APP_NAME); @@ -118,16 +124,26 @@ pub fn build_ui(app: &adw::Application) { let drive_hws_sender = drive_hws_sender.clone(); // The long running operation runs now in a separate thread gio::spawn_blocking(move || { - println!("Checking HW paramter script for available drivers:\n"); - let ubuntu_drivers_list_cli = - Command::new("/usr/lib/pika/drivers/generate_driver_definitions.sh") - .output() - .expect("failed to execute process"); - - let ubuntu_drivers_list_utf8 = String::from_utf8(ubuntu_drivers_list_cli.stdout).unwrap_or_default(); - drive_hws_sender - .send_blocking(ubuntu_drivers_list_utf8) - .expect("channel needs to be open.") + println!("Downloading driver DB..."); + let data = reqwest::blocking::get("https://raw.githubusercontent.com/PikaOS-Linux/pkg-pika-drivers/main/driver-db.json").unwrap().text().unwrap(); + println!("Parsing Downloaded driver DB..."); + let res: serde_json::Value = serde_json::from_str(&data).expect("Unable to parse"); + if let serde_json::Value::Array(drivers) = &res["drivers"] { + for driver in drivers { + if Path::new("/tmp/run-pkdm-detect.sh").exists() { + fs::remove_file("/tmp/run-pkdm-detect.sh").expect("Bad permissions on /tmp/pika-installer-gtk4-target-manual.txt"); + } + fs::write("/tmp/run-pkdm-detect.sh", "#! /bin/bash\nset -e\n".to_owned() + driver["detection"].as_str().to_owned().unwrap()).expect("Unable to write file"); + let _ = cmd!("chmod", "+x", "/tmp/run-pkdm-detect.sh").run(); + let result = cmd!("/tmp/run-pkdm-detect.sh").run(); + if result.is_ok() { + println!("{}", driver["driver"]) + } + } + } + // drive_hws_sender + // .send_blocking(ubuntu_drivers_list_utf8) + // .expect("channel needs to be open.") }); window.present();