pika-drivers/src/main.rs

279 lines
9.6 KiB
Rust
Raw Normal View History

2023-06-29 19:39:35 +02:00
use std::process::Command;
use gtk::prelude::*;
use gtk::*;
use glib::*;
fn main() {
let app = Application::builder()
2023-06-29 20:14:30 +02:00
.application_id("com.pika.drivers")
2023-06-29 19:39:35 +02:00
.build();
app.connect_activate(build_ui);
app.run();
}
fn build_ui(app: &Application) {
let main_box = gtk::Box::builder()
.orientation(Orientation::Vertical)
.build();
let drivers_list_row = gtk::ListBox::builder()
.margin_top(20)
.margin_bottom(20)
.margin_start(20)
.margin_end(20)
.vexpand(true)
.hexpand(true)
.show_separators(true)
.build();
main_box.append(&drivers_list_row);
2023-06-29 20:14:30 +02:00
println!("Checking HW paramter script for available drivers:\n");
2023-06-29 22:45:24 +02:00
let ubuntu_drivers_list_cli = Command::new("/usr/lib/pika/drivers/generate_driver_definitions.sh")
2023-06-29 19:39:35 +02:00
.output()
.expect("failed to execute process");
let ubuntu_drivers_list_utf8 = String::from_utf8(ubuntu_drivers_list_cli.stdout).unwrap();
for driver in ubuntu_drivers_list_utf8.lines() {
let driver_name = driver;
let driver_string = driver.to_string();
let driver_box = gtk::Box::builder()
.orientation(Orientation::Horizontal)
.build();
2023-06-30 14:37:03 +02:00
let driver_start_part_box = gtk::Box::builder()
.orientation(Orientation::Horizontal)
.build();
let driver_icon_label_box = gtk::Box::builder()
.orientation(Orientation::Vertical)
.build();
2023-06-29 19:39:35 +02:00
let driver_label = gtk::Label::builder()
.margin_top(12)
.margin_bottom(12)
.margin_start(12)
.margin_end(12)
.build();
2023-06-30 14:37:03 +02:00
let driver_icon = gtk::Image::builder()
.margin_top(12)
.margin_bottom(12)
.margin_start(12)
.margin_end(12)
.pixel_size(48)
.build();
2023-06-29 19:39:35 +02:00
if driver_name != "emScuM8rsa6kuhMePtR5bT8s4z9s" {
2023-06-30 14:37:03 +02:00
driver_label.set_label(driver);
if driver_name == "pika-rocm-meta" {
driver_icon.set_from_icon_name(Some("amd"));
} else if driver_name == "vulkan-amdgpu-pro" {
driver_icon.set_from_icon_name(Some("amd"));
} else if driver_name == "amf-amdgpu-pro" {
driver_icon.set_from_icon_name(Some("amd"));
} else if driver_name == "amdvlk" {
driver_icon.set_from_icon_name(Some("amd"));
} else if driver_name == "opencl-legacy-amdgpu-pro-icd" {
driver_icon.set_from_icon_name(Some("amd"));
} else if driver_name == "amdgpu-pro-oglp" {
driver_icon.set_from_icon_name(Some("amd"));
} else if driver_name == "xone-dkms" {
driver_icon.set_from_icon_name(Some("input-gaming"));
} else if driver_name.contains("nvidia") {
driver_icon.set_from_icon_name(Some("nvidia"));
} else {
driver_icon.set_from_icon_name(Some("pika-drivers"));
}
2023-06-29 19:39:35 +02:00
} else {
2023-06-30 14:37:03 +02:00
driver_label.set_label("No Drivers are required for this system you are good to go! 😎");
driver_icon.hide()
2023-06-29 19:39:35 +02:00
}
2023-06-30 12:36:00 +02:00
let command_version_label = Command::new("/usr/lib/pika/drivers/generate_package_info.sh")
.args(["version", driver.clone()])
.output()
.unwrap();
let command_description_label = Command::new("/usr/lib/pika/drivers/generate_package_info.sh")
.args(["description", driver.clone()])
.output()
.unwrap();
let command_device_label = Command::new("/usr/lib/pika/drivers/generate_package_info.sh")
.args(["device", driver.clone()])
.output()
.unwrap();
2023-06-29 19:39:35 +02:00
let driver_button = gtk::Button::builder()
.margin_top(12)
.margin_bottom(12)
.margin_start(12)
.margin_end(12)
.build();
2023-06-30 15:02:47 +02:00
let driver_device_icon = gtk::Image::builder()
.margin_top(12)
.margin_bottom(12)
.margin_start(12)
.margin_end(12)
.icon_name("edit-select-all-symbolic")
.build();
let driver_version_icon = gtk::Image::builder()
.margin_top(12)
.margin_bottom(12)
.margin_start(12)
.margin_end(12)
.icon_name("dialog-question")
.build();
2023-06-30 12:36:00 +02:00
let driver_middle_part_box = gtk::Box::builder()
2023-06-30 15:02:47 +02:00
.orientation(Orientation::Horizontal)
2023-06-29 19:39:35 +02:00
.hexpand(true)
.build();
2023-06-30 12:36:00 +02:00
let driver_middle_part_description_label = gtk::Label::builder()
2023-06-30 15:02:47 +02:00
.margin_top(12)
.margin_bottom(12)
.margin_start(12)
.margin_end(12)
.hexpand(true)
.justify(Justification::Center)
2023-06-30 12:43:19 +02:00
.wrap(true)
2023-06-30 12:36:00 +02:00
.build();
2023-06-30 15:02:47 +02:00
driver_version_icon.set_tooltip_text(Some(&String::from_utf8(command_version_label.stdout).unwrap()));
driver_device_icon.set_tooltip_text(Some(&String::from_utf8(command_device_label.stdout).unwrap()));
2023-06-30 12:36:00 +02:00
driver_middle_part_description_label.set_text(&String::from_utf8(command_description_label.stdout).unwrap());
driver_button_refresh(&driver_string.clone(), &driver_button);
2023-06-29 19:39:35 +02:00
2023-06-30 12:36:00 +02:00
driver_middle_part_box.append(&driver_middle_part_description_label);
2023-06-30 15:02:47 +02:00
driver_middle_part_box.append(&driver_device_icon);
2023-06-29 19:39:35 +02:00
2023-06-30 14:37:03 +02:00
driver_icon_label_box.append(&driver_label);
2023-06-30 15:02:47 +02:00
driver_icon_label_box.append(&driver_version_icon);
2023-06-30 14:37:03 +02:00
driver_start_part_box.append(&driver_icon);
driver_start_part_box.append(&driver_icon_label_box);
driver_box.append(&driver_start_part_box);
2023-06-30 12:36:00 +02:00
driver_box.append(&driver_middle_part_box);
if driver_name != "emScuM8rsa6kuhMePtR5bT8s4z9s" {
2023-06-29 19:39:35 +02:00
driver_box.append(&driver_button);
}
drivers_list_row.append(&driver_box);
driver_button.connect_clicked(clone!(@weak driver_button => move |_| modify_package(&driver_string, &driver_button)));
}
2023-06-30 13:44:19 +02:00
let window_box = gtk::Box::builder()
.orientation(Orientation::Vertical)
.build();
2023-06-29 19:39:35 +02:00
let main_scroll = gtk::ScrolledWindow::builder()
.child(&main_box)
.build();
2023-06-30 13:44:19 +02:00
let window_title_bar = gtk::HeaderBar::builder()
.show_title_buttons(true)
.build();
let credits_button = gtk::Button::builder()
.icon_name("dialog-information-symbolic")
.build();
window_box.append(&window_title_bar);
window_box.append(&main_scroll);
2023-06-29 19:39:35 +02:00
let window = gtk::ApplicationWindow::builder()
.title("PikaOS Driver Manager")
.application(app)
2023-06-30 13:44:19 +02:00
.child(&window_box)
2023-06-29 19:39:35 +02:00
.icon_name("mintinstall")
2023-06-30 12:43:19 +02:00
.default_width(1200)
.default_height(600)
2023-06-29 19:39:35 +02:00
.width_request(500)
.height_request(500)
2023-06-30 13:44:19 +02:00
.decorated(false)
2023-06-29 19:39:35 +02:00
.startup_id("pika-drivers")
.build();
2023-06-30 13:44:19 +02:00
window.set_titlebar(Some(&window_title_bar));
window_title_bar.pack_end(&credits_button);
2023-06-29 19:39:35 +02:00
window.show()
}
fn modify_package(package: &str, driver_button: &Button) {
2023-06-30 09:32:19 +02:00
let str_pkg = package.to_string();
2023-06-29 20:14:30 +02:00
println!("Start installing driver {}: ", package);
2023-06-29 19:39:35 +02:00
let wrapper_command = Command::new("x-terminal-emulator")
2023-06-30 09:32:19 +02:00
.arg("-e")
.arg("bash")
.arg("-c")
.arg("/usr/lib/pika/drivers/modify-driver.sh \"$1\"")
.arg("bash") // $0
.arg(&str_pkg) // $1
2023-06-29 19:39:35 +02:00
.output()
.unwrap();
if wrapper_command.status.success() {
2023-06-29 20:14:30 +02:00
println!("Installation Command has ended.\n");
println!("Installation was successful!\n");
println!("Refreshing GUI Labels.\n");
2023-06-29 19:39:35 +02:00
driver_button_refresh(package, driver_button);
} else {
2023-06-29 20:14:30 +02:00
println!("Installation Command has ended.\n");
println!("Installation was failed :(\n");
println!("Refreshing GUI Labels.\n");
2023-06-29 19:39:35 +02:00
driver_button_refresh(package, driver_button);
2023-06-29 20:14:30 +02:00
println!("Sending error message.\n");
let _error_command = Command::new("bash")
2023-06-30 09:32:19 +02:00
.arg("-c")
.arg("/usr/lib/pika/drivers/dialog-error.sh \"$1\"")
.arg("bash") // $0
.arg(&str_pkg) // $1
2023-06-29 22:45:24 +02:00
.output()
.unwrap();
2023-06-29 19:39:35 +02:00
}
}
fn driver_button_refresh(driver: &str, driver_button: &Button) {
let driver_command = Command::new("dpkg")
.args(["-s", driver])
.output()
.unwrap();
if driver_command.status.success() {
2023-06-29 20:14:30 +02:00
println!("Checking Driver Presence of {}: Success!", driver);
2023-06-29 21:48:30 +02:00
if driver.contains("nvidia") {
2023-06-30 09:44:48 +02:00
driver_button.set_tooltip_text(Some("Uninstall and revert to nouveau."));
2023-06-29 21:48:30 +02:00
} else {
2023-06-30 09:44:48 +02:00
driver_button.set_tooltip_text(Some("Uninstall."));
2023-06-29 21:48:30 +02:00
}
driver_button.set_icon_name("user-trash-symbolic");
2023-06-29 19:39:35 +02:00
} else {
2023-06-29 20:14:30 +02:00
println!("Checking Driver Presence of {}: Failure! Driver isn't installed", driver);
2023-06-29 21:48:30 +02:00
if driver.contains("nvidia") {
2023-06-30 09:44:48 +02:00
driver_button.set_tooltip_text(Some("Install and override nouveau."));
2023-06-29 21:48:30 +02:00
} else {
2023-06-30 09:44:48 +02:00
driver_button.set_tooltip_text(Some("Install."));
2023-06-29 21:48:30 +02:00
}
2023-06-29 19:39:35 +02:00
driver_button.set_icon_name("go-down-symbolic");
}
}