commit a broken manager :(

This commit is contained in:
Ward from fusion-voyager-3 2024-02-22 00:10:03 +03:00
parent 361381223d
commit 0df901d5da
6 changed files with 134 additions and 64 deletions

View File

@ -6,6 +6,9 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies] [dependencies]
adw = { version = "0.5.3", package = "libadwaita" } adw = { version = "0.5.3", package = "libadwaita", features = ["v1_4"] }
gtk = { version = "0.7.3", package = "gtk4", features = ["v4_12"] }
async-channel = "2.2.0" async-channel = "2.2.0"
gtk = { version = "0.7.3", package = "gtk4" } duct = "0.13.7"
os_pipe = "1.1.5"
rust-i18n = "3.0.1"

View File

@ -15,4 +15,4 @@ install:
mkdir -p $(DESTDIR)/usr/share/applications mkdir -p $(DESTDIR)/usr/share/applications
mkdir -p $(DESTDIR)/usr/share/icons/hicolor/scalable/apps mkdir -p $(DESTDIR)/usr/share/icons/hicolor/scalable/apps
cp -vf data/pika-drivers.svg $(DESTDIR)/usr/share/icons/hicolor/scalable/apps/ cp -vf data/pika-drivers.svg $(DESTDIR)/usr/share/icons/hicolor/scalable/apps/
cp -vf data/com.pika.drivers.desktop $(DESTDIR)/usr/share/applications/ cp -vf data/com.github.pikaos-linux.pikadrivers.desktop $(DESTDIR)/usr/share/applications/

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<schemalist> <schemalist>
<schema id="com.pika.drivers" path="/com/pika/drivers/"> <schema id="com.github.pikaos-linux.pikadrivers" path="/com/github/pikaos-linux/drivers/">
<key name="window-width" type="i"> <key name="window-width" type="i">
<default>1200</default> <default>1200</default>
<summary>Default window width</summary> <summary>Default window width</summary>

View File

@ -1,18 +1,50 @@
use std::{thread, time};
use std::{
error::Error,
};
use duct::cmd;
use std::io::prelude::*;
use std::io::BufReader;
use crate::save_window_size::save_window_size; use crate::save_window_size::save_window_size;
use std::collections::HashMap; use std::collections::HashMap;
use std::process::Command; use std::process::Command;
use std::thread; use adw::{gio, glib, Window};
use adw::{gio, glib};
use adw::glib::{clone, MainContext, Priority}; use adw::glib::{clone, MainContext, Priority};
use gtk::Orientation; use gtk::Orientation;
use gtk::prelude::{BoxExt, ButtonExt, FrameExt, GtkWindowExt, WidgetExt}; use gtk::prelude::{BoxExt, ButtonExt, FrameExt, GtkWindowExt, WidgetExt};
use crate::{DriverPackage, PROJECT_VERSION}; use crate::{DriverPackage, APP_ICON, VERSION, APP_DEV};
use adw::prelude::{*}; use adw::prelude::{*};
const DRIVER_MODIFY_PROG: &str = r###"
#! /bin/bash
DRIVER="$0"
/usr/lib/pika/drivers/modify-driver.sh "${DRIVER}"
"###;
fn driver_modify(
log_loop_sender: async_channel::Sender<String>,
driver_pkg: &str,
) -> Result<(), std::boxed::Box<dyn Error + Send + Sync>> {
let (pipe_reader, pipe_writer) = os_pipe::pipe()?;
let child = cmd!("bash", "-c", DRIVER_MODIFY_PROG, driver_pkg)
.stderr_to_stdout()
.stdout_file(pipe_writer)
.start()?;
for line in BufReader::new(pipe_reader).lines() {
log_loop_sender
.send_blocking(line?)
.expect("Channel needs to be opened.")
}
child.wait()?;
Ok(())
}
pub fn build_ui(app: &adw::Application) { pub fn build_ui(app: &adw::Application) {
gtk::glib::set_prgname(Some("Pika Drivers")); gtk::glib::set_prgname(Some("Pika Drivers"));
glib::set_application_name("Pika Drivers"); glib::set_application_name("Pika Drivers");
let glib_settings = gio::Settings::new("com.pika.drivers"); let glib_settings = gio::Settings::new("com.github.pikaos-linux.pikadrivers");
let content_box = gtk::Box::builder() let content_box = gtk::Box::builder()
.orientation(Orientation::Vertical) .orientation(Orientation::Vertical)
@ -31,7 +63,7 @@ pub fn build_ui(app: &adw::Application) {
.build(); .build();
let loading_icon = gtk::Image::builder() let loading_icon = gtk::Image::builder()
.icon_name("pika-drivers") .icon_name(APP_ICON)
.margin_top(20) .margin_top(20)
.margin_bottom(20) .margin_bottom(20)
.margin_start(20) .margin_start(20)
@ -70,7 +102,7 @@ pub fn build_ui(app: &adw::Application) {
.title("PikaOS Driver Manager") .title("PikaOS Driver Manager")
.application(app) .application(app)
.content(&content_box) .content(&content_box)
.icon_name("pika-drivers") .icon_name(APP_ICON)
.default_width(glib_settings.int("window-width")) .default_width(glib_settings.int("window-width"))
.default_height(glib_settings.int("window-height")) .default_height(glib_settings.int("window-height"))
.width_request(900) .width_request(900)
@ -83,36 +115,6 @@ pub fn build_ui(app: &adw::Application) {
window.maximize() window.maximize()
} }
let credits_window_box = gtk::Box::builder()
.orientation(Orientation::Vertical)
.build();
let credits_icon = gtk::Image::builder()
.icon_name("pika-drivers")
.margin_top(12)
.margin_bottom(12)
.margin_start(12)
.margin_end(12)
.pixel_size(128)
.build();
let credits_label = gtk::Label::builder()
.label("Pika Drivers\nMade by: Cosmo")
.margin_top(12)
.margin_bottom(12)
.margin_start(12)
.margin_end(12)
.build();
let credits_frame = gtk::Frame::builder()
.margin_top(8)
.margin_bottom(12)
.margin_start(12)
.margin_end(12)
.build();
let window_title_bar = gtk::HeaderBar::builder() let window_title_bar = gtk::HeaderBar::builder()
.show_title_buttons(true) .show_title_buttons(true)
.build(); .build();
@ -121,27 +123,14 @@ pub fn build_ui(app: &adw::Application) {
.icon_name("dialog-information-symbolic") .icon_name("dialog-information-symbolic")
.build(); .build();
credits_frame.set_label_align(0.5); let credits_window = adw::AboutWindow::builder()
.icon_name(APP_ICON)
credits_frame.set_label(Some(PROJECT_VERSION));
let credits_window = adw::Window::builder()
.content(&credits_window_box)
.transient_for(&window) .transient_for(&window)
.resizable(false) .version(VERSION)
.hide_on_close(true) .hide_on_close(true)
.icon_name("pika-drivers") .developer_name(APP_DEV)
.startup_id("pika-drivers")
.build(); .build();
credits_window_box.append(&gtk::HeaderBar::builder().show_title_buttons(true).build());
credits_window_box.append(&credits_icon);
credits_window_box.append(&credits_label);
credits_window_box.append(&credits_frame);
content_box.append(&window_title_bar);
content_box.append(&loading_box);
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_hide(clone!(@weak window => move |_| save_window_size(&window, &glib_settings)));
@ -168,9 +157,9 @@ pub fn build_ui(app: &adw::Application) {
let drive_hws_main_context = MainContext::default(); let drive_hws_main_context = MainContext::default();
// The main loop executes the asynchronous block // The main loop executes the asynchronous block
drive_hws_main_context.spawn_local(clone!(@weak content_box, @weak loading_box => async move { drive_hws_main_context.spawn_local(clone!(@weak content_box, @weak loading_box, @weak window => 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); get_drivers(&content_box, &loading_box, drive_hws_state, &window);
} }
})); }));
@ -178,7 +167,7 @@ pub fn build_ui(app: &adw::Application) {
} }
fn get_drivers(main_window: &gtk::Box, loading_box: &gtk::Box, ubuntu_drivers_list_utf8: String) { fn get_drivers(main_window: &gtk::Box, loading_box: &gtk::Box, ubuntu_drivers_list_utf8: String, window: &adw::ApplicationWindow) {
let main_box = gtk::Box::builder() let main_box = gtk::Box::builder()
.margin_top(20) .margin_top(20)
.margin_bottom(20) .margin_bottom(20)
@ -263,6 +252,11 @@ fn get_drivers(main_window: &gtk::Box, loading_box: &gtk::Box, ubuntu_drivers_li
main_box.append(&drivers_list_row); main_box.append(&drivers_list_row);
for driver in group.iter() { for driver in group.iter() {
let (log_loop_sender, log_loop_receiver) = async_channel::unbounded();
let log_loop_sender: async_channel::Sender<String> = log_loop_sender.clone();
let (log_status_loop_sender, log_status_loop_receiver) = async_channel::unbounded();
let log_status_loop_sender: async_channel::Sender<bool> = log_status_loop_sender.clone();
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()
.icon_name(driver.clone().icon) .icon_name(driver.clone().icon)
@ -323,7 +317,60 @@ fn get_drivers(main_window: &gtk::Box, loading_box: &gtk::Box, ubuntu_drivers_li
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 = gtk::TextView::builder()
.vexpand(true)
.hexpand(true)
.editable(false)
.buffer(&driver_install_log_terminal_buffer)
.build();
let driver_install_log_terminal_scroll = gtk::ScrolledWindow::builder()
.width_request(400)
.height_request(200)
.vexpand(true)
.hexpand(true)
.child(&driver_install_log_terminal)
.build();
let driver_install_dialog = adw::MessageDialog::builder()
.transient_for(window)
.hide_on_close(true)
.extra_child(&driver_install_log_terminal_scroll)
.width_request(400)
.height_request(200)
.heading("driver_install_dialog_heading")
.build();
driver_install_dialog.add_response("driver_install_dialog_ok", "system_update_dialog_ok_label");
let log_loop_context = MainContext::default();
// The main loop executes the asynchronous block
log_loop_context.spawn_local(clone!(@weak driver_install_log_terminal_buffer, @weak driver_install_dialog => async move {
while let Ok(state) = log_loop_receiver.recv().await {
driver_install_log_terminal_buffer.insert(&mut driver_install_log_terminal_buffer.end_iter(), &("\n".to_string() + &state))
}
}));
let log_status_loop_context = MainContext::default();
// The main loop executes the asynchronous block
log_status_loop_context.spawn_local(clone!(@weak driver_install_dialog => async move {
while let Ok(state) = log_status_loop_receiver.recv().await {
if state == true {
driver_install_dialog.set_response_enabled("driver_install_dialog_ok", true);
driver_install_dialog.set_body("driver_install_dialog_success_true");
} else {
driver_install_dialog.set_response_enabled("driver_install_dialog_ok", true);
driver_install_dialog.set_body("driver_install_dialog_success_false");
}
}
}));
driver_install_log_terminal_buffer.connect_changed(clone!(@weak driver_install_log_terminal, @weak driver_install_log_terminal_buffer,@weak driver_install_log_terminal_scroll => move |_|{
if driver_install_log_terminal_scroll.vadjustment().upper() - driver_install_log_terminal_scroll.vadjustment().value() > 100.0 {
driver_install_log_terminal_scroll.vadjustment().set_value(driver_install_log_terminal_scroll.vadjustment().upper())
}
}));
// //
drivers_list_row.append(&driver_expander_row); drivers_list_row.append(&driver_expander_row);
} }

View File

@ -1,6 +1,7 @@
mod save_window_size; mod save_window_size;
mod build_ui; mod build_ui;
use std::env;
use std::collections::HashMap; use std::collections::HashMap;
use std::process::Command; use std::process::Command;
use std::thread; use std::thread;
@ -22,16 +23,36 @@ pub struct DriverPackage {
experimental: bool, experimental: bool,
} }
const PROJECT_VERSION: &str = env!("CARGO_PKG_VERSION"); pub const APP_ID: &str = "com.github.pikaos-linux.pikafirstsetup";
pub const VERSION: &str = env!("CARGO_PKG_VERSION");
pub const APP_ICON: &str = "pika-drivers";
pub const APP_DEV: &str = "Cosmo";
pub const APP_GITHUB: &str = "https://github.com/PikaOS-Linux/pkg-pika-drivers";
use build_ui::build_ui; use build_ui::build_ui;
use std::boxed::Box;
// Init translations for current crate.
#[macro_use]
extern crate rust_i18n;
//i18n!("locales", fallback = "en_US");
/// main function
fn main() { fn main() {
let application = adw::Application::new(Some("com.pika.drivers"), Default::default()); let current_locale = match env::var_os("LANG") {
Some(v) => v.into_string().unwrap(),
None => panic!("$LANG is not set"),
};
//rust_i18n::set_locale(current_locale.strip_suffix(".UTF-8").unwrap());
let application = adw::Application::new(
Some(APP_ID),
Default::default(),
);
application.connect_startup(|app| { application.connect_startup(|app| {
// The CSS "magic" happens here. // The CSS "magic" happens here.
let provider = CssProvider::new(); let provider = CssProvider::new();
provider.load_from_data(include_str!("style.css")); provider.load_from_string(include_str!("style.css"));
// We give the CssProvided to the default screen so the CSS rules we added // We give the CssProvided to the default screen so the CSS rules we added
// can be applied to our window. // can be applied to our window.
gtk::style_context_add_provider_for_display( gtk::style_context_add_provider_for_display(
@ -39,7 +60,6 @@ fn main() {
&provider, &provider,
STYLE_PROVIDER_PRIORITY_APPLICATION, STYLE_PROVIDER_PRIORITY_APPLICATION,
); );
app.connect_activate(build_ui); app.connect_activate(build_ui);
}); });