diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index d14d50c..04a3df0 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -9,6 +9,8 @@
+
+
@@ -162,7 +164,7 @@
-
+
diff --git a/src/bin/apt/apt_full_upgrade/main.rs b/src/bin/apt/apt_full_upgrade/main.rs
index 03c479b..5d81f9b 100644
--- a/src/bin/apt/apt_full_upgrade/main.rs
+++ b/src/bin/apt/apt_full_upgrade/main.rs
@@ -1,11 +1,11 @@
use pika_unixsocket_tools::apt_install_progress_socket::AptInstallProgressSocket;
use pika_unixsocket_tools::apt_update_progress_socket::AptUpdateProgressSocket;
use pika_unixsocket_tools::pika_unixsocket_tools::*;
+use rust_apt::cache::Upgrade;
use rust_apt::new_cache;
use rust_apt::progress::{AcquireProgress, InstallProgress};
use std::fs::*;
use std::process::exit;
-use rust_apt::cache::Upgrade;
use tokio::runtime::Runtime;
fn main() {
@@ -59,34 +59,14 @@ fn main() {
apt_upgrade_cache.resolve(true).unwrap();
match apt_upgrade_cache.get_archives(&mut acquire_progress) {
- Ok(_) => {
- Runtime::new()
- .unwrap()
- .block_on(send_successful_to_socket(percent_socket_path));
- Runtime::new()
- .unwrap()
- .block_on(send_successful_to_socket(status_socket_path));
- }
+ Ok(_) => {}
Err(e) => {
- Runtime::new()
- .unwrap()
- .block_on(send_failed_to_socket(percent_socket_path));
- Runtime::new()
- .unwrap()
- .block_on(send_failed_to_socket(status_socket_path));
panic!("{}", e.to_string())
}
};
match apt_upgrade_cache.do_install(&mut install_progress) {
- Ok(_) => {
- Runtime::new()
- .unwrap()
- .block_on(send_successful_to_socket(percent_socket_path));
- Runtime::new()
- .unwrap()
- .block_on(send_successful_to_socket(status_socket_path));
- }
+ Ok(_) => {}
Err(e) => {
Runtime::new()
.unwrap()
diff --git a/src/bin/apt/apt_update/main.rs b/src/bin/apt/apt_update/main.rs
index b55c131..d3622f2 100644
--- a/src/bin/apt/apt_update/main.rs
+++ b/src/bin/apt/apt_update/main.rs
@@ -13,14 +13,7 @@ fn main() {
percent_socket_path,
status_socket_path,
))) {
- Ok(_) => {
- Runtime::new()
- .unwrap()
- .block_on(send_successful_to_socket(percent_socket_path));
- Runtime::new()
- .unwrap()
- .block_on(send_successful_to_socket(status_socket_path));
- }
+ Ok(_) => {}
Err(e) => {
Runtime::new()
.unwrap()
diff --git a/src/bin/gui/apt_update_page/mod.rs b/src/bin/gui/apt_update_page/mod.rs
index 0268b93..721a4b3 100644
--- a/src/bin/gui/apt_update_page/mod.rs
+++ b/src/bin/gui/apt_update_page/mod.rs
@@ -61,7 +61,7 @@ pub fn apt_update_page(
Runtime::new().unwrap().block_on(start_socket_server(
update_status_sender,
"/tmp/pika_apt_update_status.sock",
- "/tmp/pika-apt-update.log"
+ "/tmp/pika-apt-update.log",
));
});
@@ -71,7 +71,9 @@ pub fn apt_update_page(
.status()
.unwrap();
match apt_update_command.code().unwrap() {
- 0 => {}
+ 0 => update_status_sender_clone0
+ .send_blocking("FN_OVERRIDE_SUCCESSFUL".to_owned())
+ .unwrap(),
53 => {}
_ => {
update_status_sender_clone0
@@ -218,9 +220,18 @@ pub fn apt_update_page(
// The main loop executes the asynchronous block
update_percent_server_context.spawn_local(clone!(@weak apt_update_dialog_progress_bar, @weak apt_update_dialog, @strong get_upgradable_sender => async move {
while let Ok(state) = update_percent_receiver.recv().await {
+ apt_update_dialog_progress_bar.set_fraction(state.parse::().unwrap()/100.0)
+ }
+ }));
+
+ 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_child_box => async move {
+ while let Ok(state) = update_status_receiver.recv().await {
match state.as_ref() {
"FN_OVERRIDE_SUCCESSFUL" => {
- let get_upgradable_sender = get_upgradable_sender.clone();
+ let get_upgradable_sender = get_upgradable_sender.clone();
thread::spawn(move || {
// Create upgradable list cache
let upgradable_cache = new_cache!().unwrap();
@@ -257,21 +268,7 @@ pub fn apt_update_page(
}
});
apt_update_dialog.close();
- }
- _ => {
- apt_update_dialog_progress_bar.set_fraction(state.parse::().unwrap()/100.0)
- }
- }
- }
- }));
-
- 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_child_box => async move {
- while let Ok(state) = update_status_receiver.recv().await {
- match state.as_ref() {
- "FN_OVERRIDE_SUCCESSFUL" => {}
+ }
"FN_OVERRIDE_FAILED" => {
apt_update_dialog_child_box.set_visible(false);
apt_update_dialog.set_extra_child(Some(>k::Image::builder().pixel_size(128).icon_name("dialog-error-symbolic").halign(Align::Center).build()));
diff --git a/src/bin/gui/apt_update_page/process.rs b/src/bin/gui/apt_update_page/process.rs
index fd3765a..3f5f12c 100644
--- a/src/bin/gui/apt_update_page/process.rs
+++ b/src/bin/gui/apt_update_page/process.rs
@@ -1,7 +1,10 @@
+use adw::gio::SimpleAction;
use adw::prelude::*;
use gtk::glib::*;
use gtk::*;
-use pika_unixsocket_tools::pika_unixsocket_tools::{start_socket_server, start_socket_server_no_log};
+use pika_unixsocket_tools::pika_unixsocket_tools::{
+ start_socket_server, start_socket_server_no_log,
+};
use pretty_bytes::converter::convert;
use rust_apt::cache::Upgrade;
use rust_apt::new_cache;
@@ -10,7 +13,6 @@ use serde_json::Value;
use std::path::Path;
use std::process::Command;
use std::{fs::*, thread};
-use adw::gio::SimpleAction;
use tokio::runtime::Runtime;
struct AptChangesInfo {
@@ -53,7 +55,11 @@ impl AptChangesInfo {
}
}
-pub fn apt_process_update(excluded_updates_vec: &Vec, window: adw::ApplicationWindow, retry_signal_action: &SimpleAction,) {
+pub fn apt_process_update(
+ excluded_updates_vec: &Vec,
+ window: adw::ApplicationWindow,
+ retry_signal_action: &SimpleAction,
+) {
let excluded_updates_alert_dialog = adw::MessageDialog::builder()
.transient_for(&window)
.heading(t!("excluded_updates_alert_dialog_heading"))
@@ -97,7 +103,11 @@ pub fn apt_process_update(excluded_updates_vec: &Vec, window: adw::Appli
}
}
-fn apt_confirm_window(excluded_updates_vec: &Vec, window: adw::ApplicationWindow, retry_signal_action: &SimpleAction,) {
+fn apt_confirm_window(
+ excluded_updates_vec: &Vec,
+ window: adw::ApplicationWindow,
+ retry_signal_action: &SimpleAction,
+) {
// Emulate Apt Full Upgrade to get transaction info
let mut apt_changes_struct = AptChangesInfo {
package_count_upgrade: 0,
@@ -284,14 +294,20 @@ fn apt_confirm_window(excluded_updates_vec: &Vec, window: adw::Applicati
});
}
-fn apt_full_upgrade_from_socket(window: adw::ApplicationWindow, retry_signal_action: &SimpleAction) {
+fn apt_full_upgrade_from_socket(
+ window: adw::ApplicationWindow,
+ retry_signal_action: &SimpleAction,
+) {
let (upgrade_percent_sender, upgrade_percent_receiver) = async_channel::unbounded::();
let upgrade_percent_sender = upgrade_percent_sender.clone();
let (upgrade_status_sender, upgrade_status_receiver) = async_channel::unbounded::();
let upgrade_status_sender = upgrade_status_sender.clone();
let upgrade_status_sender_clone0 = upgrade_status_sender.clone();
- let log_file_path = format!("/tmp/pika-apt-upgrade_{}.log", chrono::offset::Local::now().format("%Y-%m-%d_%H:%M"));
+ let log_file_path = format!(
+ "/tmp/pika-apt-upgrade_{}.log",
+ chrono::offset::Local::now().format("%Y-%m-%d_%H:%M")
+ );
let log_file_path_clone0 = log_file_path.clone();
thread::spawn(move || {
@@ -305,13 +321,15 @@ fn apt_full_upgrade_from_socket(window: adw::ApplicationWindow, retry_signal_act
Runtime::new().unwrap().block_on(start_socket_server(
upgrade_status_sender,
"/tmp/pika_apt_upgrade_status.sock",
- &log_file_path
+ &log_file_path,
));
});
thread::spawn(move || {
let apt_upgrade_command = Command::new("pkexec")
- .args(["/home/ward/RustroverProjects/pikman-update-manager/target/debug/apt_full_upgrade"])
+ .args([
+ "/home/ward/RustroverProjects/pikman-update-manager/target/debug/apt_full_upgrade",
+ ])
.status()
.unwrap();
match apt_upgrade_command.code().unwrap() {
@@ -430,8 +448,10 @@ fn apt_full_upgrade_from_socket(window: adw::ApplicationWindow, retry_signal_act
let retry_signal_action0 = retry_signal_action.clone();
- apt_upgrade_log_button.connect_clicked( move |_| {
- let _ = std::process::Command::new("xdg-open").arg(log_file_path_clone0.to_owned()).spawn();
+ apt_upgrade_log_button.connect_clicked(move |_| {
+ let _ = std::process::Command::new("xdg-open")
+ .arg(log_file_path_clone0.to_owned())
+ .spawn();
});
apt_upgrade_dialog.choose(None::<&gio::Cancellable>, move |choice| {
diff --git a/src/lib/pika_unixsocket_tools/mod.rs b/src/lib/pika_unixsocket_tools/mod.rs
index 45943fe..63a70fc 100644
--- a/src/lib/pika_unixsocket_tools/mod.rs
+++ b/src/lib/pika_unixsocket_tools/mod.rs
@@ -1,11 +1,11 @@
+use chrono;
use std::fs;
+use std::fs::OpenOptions;
+use std::io::Write;
use std::path::Path;
use tokio::io::{AsyncReadExt, AsyncWriteExt};
use tokio::net::{UnixListener, UnixStream};
use tokio::task;
-use chrono;
-use std::fs::OpenOptions;
-use std::io::Write;
pub async fn send_successful_to_socket(socket_path: &str) {
// Connect to the Unix socket
@@ -38,7 +38,11 @@ pub async fn send_failed_to_socket(socket_path: &str) {
}
// Function to handle a single client connection
-pub async fn handle_client(mut stream: UnixStream, buffer_sender: async_channel::Sender, log_file_path: String) {
+pub async fn handle_client(
+ mut stream: UnixStream,
+ buffer_sender: async_channel::Sender,
+ log_file_path: String,
+) {
// Buffer to store incoming data
let mut buffer = [0; 1024];
@@ -66,7 +70,12 @@ pub async fn handle_client(mut stream: UnixStream, buffer_sender: async_channel:
.open(&log_file_path)
.unwrap();
- if let Err(e) = writeln!(log_file, "[{}] {}", chrono::offset::Local::now().format("%Y/%m/%d_%H:%M"), message) {
+ if let Err(e) = writeln!(
+ log_file,
+ "[{}] {}",
+ chrono::offset::Local::now().format("%Y/%m/%d_%H:%M"),
+ message
+ ) {
eprintln!("Couldn't write to file: {}", e);
}
}
@@ -77,7 +86,11 @@ pub async fn handle_client(mut stream: UnixStream, buffer_sender: async_channel:
}
}
-pub async fn start_socket_server(buffer_sender: async_channel::Sender, socket_path: &str, log_file_path: &str) {
+pub async fn start_socket_server(
+ buffer_sender: async_channel::Sender,
+ socket_path: &str,
+ log_file_path: &str,
+) {
// Remove the socket file if it already exists
if Path::new(socket_path).exists() {
fs::remove_file(socket_path).expect("Could not remove existing socket file");
@@ -94,7 +107,11 @@ pub async fn start_socket_server(buffer_sender: async_channel::Sender, s
match listener.accept().await {
Ok((stream, _)) => {
// Handle the connection in a separate task
- task::spawn(handle_client(stream, buffer_sender.clone(), log_file_path.to_owned()));
+ task::spawn(handle_client(
+ stream,
+ buffer_sender.clone(),
+ log_file_path.to_owned(),
+ ));
}
Err(e) => {
// Print error message if a connection fails
@@ -104,7 +121,10 @@ pub async fn start_socket_server(buffer_sender: async_channel::Sender, s
}
}
-pub async fn handle_client_no_log(mut stream: UnixStream, buffer_sender: async_channel::Sender) {
+pub async fn handle_client_no_log(
+ mut stream: UnixStream,
+ buffer_sender: async_channel::Sender,
+) {
// Buffer to store incoming data
let mut buffer = [0; 1024];
@@ -126,7 +146,10 @@ pub async fn handle_client_no_log(mut stream: UnixStream, buffer_sender: async_c
}
}
-pub async fn start_socket_server_no_log(buffer_sender: async_channel::Sender, socket_path: &str) {
+pub async fn start_socket_server_no_log(
+ buffer_sender: async_channel::Sender,
+ socket_path: &str,
+) {
// Remove the socket file if it already exists
if Path::new(socket_path).exists() {
fs::remove_file(socket_path).expect("Could not remove existing socket file");
@@ -143,7 +166,10 @@ pub async fn start_socket_server_no_log(buffer_sender: async_channel::Sender {
// Handle the connection in a separate task
- task::spawn(crate::pika_unixsocket_tools::handle_client_no_log(stream, buffer_sender.clone()));
+ task::spawn(crate::pika_unixsocket_tools::handle_client_no_log(
+ stream,
+ buffer_sender.clone(),
+ ));
}
Err(e) => {
// Print error message if a connection fails
@@ -151,4 +177,4 @@ pub async fn start_socket_server_no_log(buffer_sender: async_channel::Sender