From 7fef8d8739139e71a6dc28fb64db4d7cb9307e02 Mon Sep 17 00:00:00 2001 From: Ward from fusion-voyager-3 Date: Tue, 9 Jul 2024 02:08:32 +0300 Subject: [PATCH] checkpoint --- .idea/workspace.xml | 3 ++- src/apt_update/main.rs | 3 ++- src/apt_update_page/mod.rs | 35 ++++++++++++++++++++--------------- src/build_ui/mod.rs | 7 ++++++- 4 files changed, 30 insertions(+), 18 deletions(-) diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 673adb0..9875144 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -111,7 +111,8 @@ - + + diff --git a/src/apt_update/main.rs b/src/apt_update/main.rs index 8d53a83..1348f1a 100644 --- a/src/apt_update/main.rs +++ b/src/apt_update/main.rs @@ -1,3 +1,4 @@ +use std::process::exit; use pika_unixsocket_tools::*; use rust_apt::new_cache; use rust_apt::progress::{AcquireProgress, DynAcquireProgress}; @@ -110,7 +111,7 @@ impl<'a> DynAcquireProgress for AptUpdateProgressSocket<'a> { Runtime::new() .unwrap() .block_on(send_failed_to_socket(self.status_socket_path)); - panic!("{}", message.to_string()) + exit(53) } /// Called periodically to provide the overall progress information diff --git a/src/apt_update_page/mod.rs b/src/apt_update_page/mod.rs index 4f647d6..fa0d8cd 100644 --- a/src/apt_update_page/mod.rs +++ b/src/apt_update_page/mod.rs @@ -32,18 +32,12 @@ pub struct AptPackageSocket { pub installed_size: u64, pub is_last: bool, } - -pub fn apt_update_page(window: adw::ApplicationWindow) -> adw::Bin { - adw::Bin::builder() - .child(&create_bin_content(window)) - .build() -} - -fn create_bin_content(window: adw::ApplicationWindow) -> gtk::Box { +pub fn apt_update_page(window: adw::ApplicationWindow) -> gtk::Box { let (update_percent_sender, update_percent_receiver) = async_channel::unbounded::(); let update_percent_sender = update_percent_sender.clone(); let (update_status_sender, update_status_receiver) = async_channel::unbounded::(); let update_status_sender = update_status_sender.clone(); + let update_status_sender_clone0 = update_status_sender.clone(); let (get_upgradable_sender, get_upgradable_receiver) = async_channel::unbounded(); let get_upgradable_sender = get_upgradable_sender.clone(); @@ -59,9 +53,20 @@ fn create_bin_content(window: adw::ApplicationWindow) -> gtk::Box { .block_on(update_status_socket_server(update_status_sender)); }); - Command::new("pkexec") - .args(["/home/ward/RustroverProjects/pika-idk-manager/target/debug/apt_update"]) - .spawn(); + thread::spawn(move || { + let apt_update_command = Command::new("pkexec") + .args(["/home/ward/RustroverProjects/pika-idk-manager/target/debug/apt_update"]) + .status() + .unwrap(); + match apt_update_command.code().unwrap() { + 0 => {} + 53 => {} + _ => { + update_status_sender_clone0.send_blocking(t!("update_status_error_perms").to_string()).unwrap(); + update_status_sender_clone0.send_blocking("FN_OVERRIDE_FAILED".to_owned()).unwrap() + } + } + }); let main_box = gtk::Box::builder() .hexpand(true) @@ -208,14 +213,14 @@ fn create_bin_content(window: adw::ApplicationWindow) -> gtk::Box { let update_status_server_context = MainContext::default(); // The main loop executes the asynchronous block update_status_server_context.spawn_local( - clone!(@weak apt_update_dialog, @weak apt_update_dialog_spinner => async move { + clone!(@weak apt_update_dialog, @weak apt_update_dialog_child_box => async move { while let Ok(state) = update_status_receiver.recv().await { - println!("egg: {}", state); match state.as_ref() { "FN_OVERRIDE_SUCCESSFUL" => {} "FN_OVERRIDE_FAILED" => { - apt_update_dialog_spinner.set_spinning(false); - apt_update_dialog.set_body(&t!("apt_update_dialog_status_failed").to_string()) + apt_update_dialog_child_box.set_visible(false); + apt_update_dialog.set_title(Some(&t!("apt_update_dialog_status_failed").to_string())) + //apt_update_dialog.add_response("apt_update_dialog_retry", &t!("apt_update_dialog_retry_label").to_string()); } _ => apt_update_dialog.set_body(&state) } diff --git a/src/build_ui/mod.rs b/src/build_ui/mod.rs index aaa3c25..0e7955f 100644 --- a/src/build_ui/mod.rs +++ b/src/build_ui/mod.rs @@ -124,6 +124,11 @@ pub fn build_ui(app: &adw::Application) { // show the window window.present(); - window_adw_view_stack.add_titled_with_icon(&apt_update_page::apt_update_page(window), Some("apt_update_page"), &t!("apt_update_page_title"), "software-update-available-symbolic"); + // Apt Update Page + let apt_update_view_stack_bin = adw::Bin::builder() + .child(&apt_update_page::apt_update_page(window)) + .build(); + + window_adw_view_stack.add_titled_with_icon(&apt_update_view_stack_bin, Some("apt_update_page"), &t!("apt_update_page_title"), "software-update-available-symbolic"); window_adw_view_stack.add_titled(>k::Image::builder().icon_name("firefox").build(), Some("apt_update_page2"), &t!("apt_update_page_title2")); }