fix inputless terminal

This commit is contained in:
Ward from fusion-voyager-3 2024-02-26 18:02:47 +03:00
parent be30228a8a
commit 45d1339950
3 changed files with 62 additions and 26 deletions

View File

@ -43,18 +43,18 @@ then
then then
zenity --error --text "the following driver "$1" can not be removed only swapped" zenity --error --text "the following driver "$1" can not be removed only swapped"
else else
echo "pikaos" | sudo -S bash -c "apt remove $pkg -y && sudo apt autoremove -y" echo "pikaos" | sudo -S bash -c "DEBIAN_FRONTEND=noninteractive apt remove $pkg -y -o Dpkg::Options::='--force-confnew' && sudo DEBIAN_FRONTEND=noninteractive apt autoremove -y -o Dpkg::Options::='--force-confnew'"
fi fi
else else
if echo $pkg | grep -i nvidia if echo $pkg | grep -i nvidia
then then
echo "pikaos" | sudo -S bash -c "apt update -y && apt purge nvidia-driver-* -y && apt install $pkg -y && sudo apt autoremove -y" echo "pikaos" | sudo -S bash -c "DEBIAN_FRONTEND=noninteractive apt update -y -o Dpkg::Options::='--force-confnew' && DEBIAN_FRONTEND=noninteractive apt purge nvidia-driver-* -y -o Dpkg::Options::='--force-confnew' && DEBIAN_FRONTEND=noninteractive apt install $pkg -y -o Dpkg::Options::='--force-confnew' && sudo DEBIAN_FRONTEND=noninteractive apt autoremove -y -o Dpkg::Options::='--force-confnew'"
else else
if echo $pkg | grep -i mesa-hybrid if echo $pkg | grep -i mesa-hybrid
then then
echo "pikaos" | sudo -S bash -c "apt update -y && apt install mesa-stable -y && apt install mesa-hybrid -y && sudo apt autoremove -y" echo "pikaos" | sudo -S bash -c "DEBIAN_FRONTEND=noninteractive apt update -y -o Dpkg::Options::='--force-confnew' && DEBIAN_FRONTEND=noninteractive apt install mesa-stable -y -o Dpkg::Options::='--force-confnew' && DEBIAN_FRONTEND=noninteractive apt install mesa-hybrid -y -o Dpkg::Options::='--force-confnew' && sudo DEBIAN_FRONTEND=noninteractive apt autoremove -y -o Dpkg::Options::='--force-confnew'"
else else
echo "pikaos" | sudo -S bash -c "apt update -y && apt install $pkg -y && sudo apt autoremove -y" echo "pikaos" | sudo -S bash -c "DEBIAN_FRONTEND=noninteractive apt update -y -o Dpkg::Options::='--force-confnew' && DEBIAN_FRONTEND=noninteractive apt install $pkg -y -o Dpkg::Options::='--force-confnew' && sudo DEBIAN_FRONTEND=noninteractive apt autoremove -y -o Dpkg::Options::='--force-confnew'"
fi fi
fi fi
fi fi
@ -100,18 +100,18 @@ then
then then
zenity --error --text "the following driver "$1" can not be removed only swapped" zenity --error --text "the following driver "$1" can not be removed only swapped"
else else
pkexec env DISPLAY=$DISPLAY XAUTHORITY=$XAUTHORITY bash -c "apt remove $pkg -y && sudo apt autoremove -y" pkexec env DISPLAY=$DISPLAY XAUTHORITY=$XAUTHORITY bash -c "DEBIAN_FRONTEND=noninteractive apt remove $pkg -y -o Dpkg::Options::='--force-confnew' && sudo DEBIAN_FRONTEND=noninteractive apt autoremove -y -o Dpkg::Options::='--force-confnew'"
fi fi
else else
if echo $pkg | grep -i nvidia if echo $pkg | grep -i nvidia
then then
pkexec env DISPLAY=$DISPLAY XAUTHORITY=$XAUTHORITY bash -c "apt update -y && apt purge nvidia-driver-* -y && apt install $pkg -y && sudo apt autoremove -y" pkexec env DISPLAY=$DISPLAY XAUTHORITY=$XAUTHORITY bash -c "DEBIAN_FRONTEND=noninteractive apt update -y -o Dpkg::Options::='--force-confnew' && DEBIAN_FRONTEND=noninteractive apt purge nvidia-driver-* -y -o Dpkg::Options::='--force-confnew' && DEBIAN_FRONTEND=noninteractive apt install $pkg -y -o Dpkg::Options::='--force-confnew' && sudo DEBIAN_FRONTEND=noninteractive apt autoremove -y -o Dpkg::Options::='--force-confnew'"
else else
if echo $pkg | grep -i mesa-hybrid if echo $pkg | grep -i mesa-hybrid
then then
pkexec env DISPLAY=$DISPLAY XAUTHORITY=$XAUTHORITY bash -c "apt update -y && apt install mesa-stable -y && apt install mesa-hybrid -y && sudo apt autoremove -y" pkexec env DISPLAY=$DISPLAY XAUTHORITY=$XAUTHORITY bash -c "DEBIAN_FRONTEND=noninteractive apt update -y -o Dpkg::Options::='--force-confnew' && DEBIAN_FRONTEND=noninteractive apt install mesa-stable -y -o Dpkg::Options::='--force-confnew' && DEBIAN_FRONTEND=noninteractive apt install mesa-hybrid -y -o Dpkg::Options::='--force-confnew' && sudo DEBIAN_FRONTEND=noninteractive apt autoremove -y -o Dpkg::Options::='--force-confnew'"
else else
pkexec env DISPLAY=$DISPLAY XAUTHORITY=$XAUTHORITY bash -c "apt update -y && apt install $pkg -y && sudo apt autoremove -y" pkexec env DISPLAY=$DISPLAY XAUTHORITY=$XAUTHORITY bash -c "DEBIAN_FRONTEND=noninteractive apt update -y -o Dpkg::Options::='--force-confnew' && DEBIAN_FRONTEND=noninteractive apt install $pkg -y -o Dpkg::Options::='--force-confnew' && sudo DEBIAN_FRONTEND=noninteractive apt autoremove -y -o Dpkg::Options::='--force-confnew'"
fi fi
fi fi
fi fi

View File

@ -1,5 +1,5 @@
{ {
"app_name": "PikaOS Welcome", "app_name": "PikaOS Driver Manager",
"app_dev": "Cosmo", "app_dev": "Cosmo",
"loading_label_label": "Downloading driver database...", "loading_label_label": "Downloading driver database...",
"loading_no_internet_box_text_title": "Network Error!", "loading_no_internet_box_text_title": "Network Error!",

View File

@ -1,3 +1,4 @@
use std::thread;
use crate::config::*; use crate::config::*;
use crate::save_window_size::save_window_size; use crate::save_window_size::save_window_size;
use crate::DriverPackage; use crate::DriverPackage;
@ -6,7 +7,7 @@ use adw::prelude::*;
use adw::{gio, glib}; use adw::{gio, glib};
use duct::cmd; use duct::cmd;
use gtk::prelude::{BoxExt, ButtonExt, GtkWindowExt, WidgetExt}; use gtk::prelude::{BoxExt, ButtonExt, GtkWindowExt, WidgetExt};
use gtk::Orientation; use gtk::{Orientation, SizeGroupMode};
use std::collections::HashMap; use std::collections::HashMap;
use std::error::Error; use std::error::Error;
use std::fs; use std::fs;
@ -14,6 +15,7 @@ use std::io::BufRead;
use std::io::BufReader; use std::io::BufReader;
use std::path::Path; use std::path::Path;
use std::process::Command; use std::process::Command;
use std::time::Duration;
use users::*; use users::*;
@ -84,7 +86,6 @@ pub fn build_ui(app: &adw::Application) {
.width_request(950) .width_request(950)
.height_request(500) .height_request(500)
.startup_id(APP_ID) .startup_id(APP_ID)
.hide_on_close(true)
.build(); .build();
if glib_settings.boolean("is-maximized") == true { if glib_settings.boolean("is-maximized") == true {
@ -107,12 +108,20 @@ pub fn build_ui(app: &adw::Application) {
.issue_url(APP_GITHUB.to_owned() + "/issues") .issue_url(APP_GITHUB.to_owned() + "/issues")
.build(); .build();
let list_row_size_group = gtk::SizeGroup::new(SizeGroupMode::Horizontal);
let rows_size_group = gtk::SizeGroup::new(SizeGroupMode::Both);
content_box.append(&window_title_bar); content_box.append(&window_title_bar);
window_title_bar.pack_end(&credits_button.clone()); window_title_bar.pack_end(&credits_button.clone());
window.connect_hide(clone!(@weak window => move |_| save_window_size(&window, &glib_settings))); window.connect_close_request(move |window| {
window.connect_hide(clone!(@weak window => move |_| window.destroy())); if let Some(application) = window.application() {
save_window_size(&window, &glib_settings);
application.remove_window(window);
}
glib::Propagation::Proceed
});
credits_button credits_button
.connect_clicked(clone!(@weak credits_button => move |_| credits_window.present())); .connect_clicked(clone!(@weak credits_button => move |_| credits_window.present()));
@ -193,7 +202,7 @@ pub fn build_ui(app: &adw::Application) {
drive_hws_main_context.spawn_local( drive_hws_main_context.spawn_local(
clone!(@weak content_box, @weak loading_box, @strong data => async move { clone!(@weak content_box, @weak loading_box, @strong data => async move {
while let Ok(drive_hws_state) = drive_hws_receiver.recv().await { while let Ok(drive_hws_state) = drive_hws_receiver.recv().await {
get_drivers(&content_box, &loading_box, drive_hws_state, &window); get_drivers(&content_box, &loading_box, drive_hws_state, &window, &list_row_size_group, &rows_size_group);
} }
}), }),
); );
@ -240,6 +249,8 @@ fn get_drivers(
loading_box: &gtk::Box, loading_box: &gtk::Box,
driver_array: Vec<DriverPackage>, driver_array: Vec<DriverPackage>,
window: &adw::ApplicationWindow, window: &adw::ApplicationWindow,
list_row_size_group: &gtk::SizeGroup,
rows_size_group: &gtk::SizeGroup,
) { ) {
let main_box = gtk::Box::builder() let main_box = gtk::Box::builder()
.margin_top(20) .margin_top(20)
@ -295,6 +306,8 @@ fn get_drivers(
.build(); .build();
drivers_list_row.add_css_class("boxed-list"); drivers_list_row.add_css_class("boxed-list");
list_row_size_group.add_widget(&drivers_list_row);
main_box.append(&drivers_list_row); main_box.append(&drivers_list_row);
for driver in group.iter() { for driver in group.iter() {
@ -305,6 +318,26 @@ fn get_drivers(
let log_status_loop_sender: async_channel::Sender<bool> = let log_status_loop_sender: async_channel::Sender<bool> =
log_status_loop_sender.clone(); log_status_loop_sender.clone();
let (driver_status_loop_sender, driver_status_loop_receiver) = async_channel::unbounded();
let driver_status_loop_sender: async_channel::Sender<bool> =
driver_status_loop_sender.clone();
let driver_package_ind2 = driver.driver.to_owned();
let driver_package_removeble = driver.removeble.to_owned();
gio::spawn_blocking(move || loop {
thread::sleep(Duration::from_secs(5));
let command_installed_status = Command::new("dpkg")
.args(["-s", &driver_package_ind2])
.output()
.unwrap();
if command_installed_status.status.success() {
driver_status_loop_sender.send_blocking(true).expect("channel needs to be open")
} else {
driver_status_loop_sender.send_blocking(false).expect("channel needs to be open")
}
});
let driver_package_ind = driver.driver.to_owned(); let driver_package_ind = driver.driver.to_owned();
let driver_expander_row = adw::ExpanderRow::new(); let driver_expander_row = adw::ExpanderRow::new();
let driver_icon = gtk::Image::builder() let driver_icon = gtk::Image::builder()
@ -353,20 +386,23 @@ fn get_drivers(
driver_action_box.append(&driver_install_button); driver_action_box.append(&driver_install_button);
driver_content_row.add_suffix(&driver_action_box); driver_content_row.add_suffix(&driver_action_box);
driver_expander_row.add_row(&driver_content_row); driver_expander_row.add_row(&driver_content_row);
rows_size_group.add_widget(&driver_action_box);
// //
let command_installed_status = Command::new("dpkg") let driver_status_loop_context = MainContext::default();
.args(["-s", &driver.clone().driver]) // The main loop executes the asynchronous block
.output() driver_status_loop_context.spawn_local(clone!(@weak driver_remove_button, @weak driver_install_button, @strong driver_status_loop_receiver => async move {
.unwrap(); while let Ok(driver_status_state) = driver_status_loop_receiver.recv().await {
if command_installed_status.status.success() { if driver_status_state == true {
driver_install_button.set_sensitive(false); driver_install_button.set_sensitive(false);
if driver.clone().removeble == true { if driver_package_removeble == true {
driver_remove_button.set_sensitive(true); driver_remove_button.set_sensitive(true);
} }
} else { } else {
driver_remove_button.set_sensitive(false); driver_remove_button.set_sensitive(false);
driver_install_button.set_sensitive(true); driver_install_button.set_sensitive(true);
} }
}
}));
// //
let driver_install_log_terminal_buffer = gtk::TextBuffer::builder().build(); let driver_install_log_terminal_buffer = gtk::TextBuffer::builder().build();