Add speed meter to apt
This commit is contained in:
parent
f33d2254f0
commit
27217bfc50
@ -18,6 +18,8 @@ fn main() {
|
|||||||
|
|
||||||
let percent_socket_path = "/tmp/pika_apt_upgrade_percent.sock";
|
let percent_socket_path = "/tmp/pika_apt_upgrade_percent.sock";
|
||||||
let status_socket_path = "/tmp/pika_apt_upgrade_status.sock";
|
let status_socket_path = "/tmp/pika_apt_upgrade_status.sock";
|
||||||
|
let speed_socket_path = "/tmp/pika_apt_upgrade_speed.sock";
|
||||||
|
|
||||||
let json_file_path = "/tmp/pika-apt-exclusions.json";
|
let json_file_path = "/tmp/pika-apt-exclusions.json";
|
||||||
let mut excluded_updates_vec: Vec<String> = Vec::new();
|
let mut excluded_updates_vec: Vec<String> = Vec::new();
|
||||||
|
|
||||||
@ -74,6 +76,7 @@ fn main() {
|
|||||||
let mut acquire_progress = AcquireProgress::new(AptUpdateProgressSocket::new(
|
let mut acquire_progress = AcquireProgress::new(AptUpdateProgressSocket::new(
|
||||||
percent_socket_path,
|
percent_socket_path,
|
||||||
status_socket_path,
|
status_socket_path,
|
||||||
|
speed_socket_path,
|
||||||
&hit_strfmt_trans_str,
|
&hit_strfmt_trans_str,
|
||||||
&fetch_strfmt_trans_str,
|
&fetch_strfmt_trans_str,
|
||||||
&done_strfmt_trans_str,
|
&done_strfmt_trans_str,
|
||||||
|
@ -26,9 +26,11 @@ fn main() {
|
|||||||
let update_cache = new_cache!().unwrap();
|
let update_cache = new_cache!().unwrap();
|
||||||
let percent_socket_path = "/tmp/pika_apt_update_percent.sock";
|
let percent_socket_path = "/tmp/pika_apt_update_percent.sock";
|
||||||
let status_socket_path = "/tmp/pika_apt_update_status.sock";
|
let status_socket_path = "/tmp/pika_apt_update_status.sock";
|
||||||
|
let speed_socket_path = "/tmp/pika_apt_update_speed.sock";
|
||||||
match update_cache.update(&mut AcquireProgress::new(AptUpdateProgressSocket::new(
|
match update_cache.update(&mut AcquireProgress::new(AptUpdateProgressSocket::new(
|
||||||
percent_socket_path,
|
percent_socket_path,
|
||||||
status_socket_path,
|
status_socket_path,
|
||||||
|
speed_socket_path,
|
||||||
&hit_strfmt_trans_str,
|
&hit_strfmt_trans_str,
|
||||||
&fetch_strfmt_trans_str,
|
&fetch_strfmt_trans_str,
|
||||||
&done_strfmt_trans_str,
|
&done_strfmt_trans_str,
|
||||||
|
@ -39,6 +39,8 @@ pub fn apt_update_page(
|
|||||||
) -> gtk::Box {
|
) -> gtk::Box {
|
||||||
let (update_percent_sender, update_percent_receiver) = async_channel::unbounded::<String>();
|
let (update_percent_sender, update_percent_receiver) = async_channel::unbounded::<String>();
|
||||||
let update_percent_sender = update_percent_sender.clone();
|
let update_percent_sender = update_percent_sender.clone();
|
||||||
|
let (update_speed_sender, update_speed_receiver) = async_channel::unbounded::<String>();
|
||||||
|
let update_speed_sender = update_speed_sender.clone();
|
||||||
let (update_status_sender, update_status_receiver) = async_channel::unbounded::<String>();
|
let (update_status_sender, update_status_receiver) = async_channel::unbounded::<String>();
|
||||||
let update_status_sender = update_status_sender.clone();
|
let update_status_sender = update_status_sender.clone();
|
||||||
let update_status_sender_clone0 = update_status_sender.clone();
|
let update_status_sender_clone0 = update_status_sender.clone();
|
||||||
@ -56,6 +58,13 @@ pub fn apt_update_page(
|
|||||||
));
|
));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
thread::spawn(move || {
|
||||||
|
Runtime::new().unwrap().block_on(start_socket_server_no_log(
|
||||||
|
update_speed_sender,
|
||||||
|
"/tmp/pika_apt_update_speed.sock",
|
||||||
|
));
|
||||||
|
});
|
||||||
|
|
||||||
thread::spawn(move || {
|
thread::spawn(move || {
|
||||||
Runtime::new().unwrap().block_on(start_socket_server(
|
Runtime::new().unwrap().block_on(start_socket_server(
|
||||||
update_status_sender,
|
update_status_sender,
|
||||||
@ -170,7 +179,14 @@ pub fn apt_update_page(
|
|||||||
.width_request(128)
|
.width_request(128)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
|
let apt_speed_label = gtk::Label::builder()
|
||||||
|
.halign(Align::Center)
|
||||||
|
.margin_top(10)
|
||||||
|
.margin_bottom(10)
|
||||||
|
.build();
|
||||||
|
|
||||||
apt_update_dialog_child_box.append(&apt_update_dialog_spinner);
|
apt_update_dialog_child_box.append(&apt_update_dialog_spinner);
|
||||||
|
apt_update_dialog_child_box.append(&apt_speed_label);
|
||||||
apt_update_dialog_child_box.append(&apt_update_dialog_progress_bar);
|
apt_update_dialog_child_box.append(&apt_update_dialog_progress_bar);
|
||||||
|
|
||||||
let apt_update_dialog = adw::MessageDialog::builder()
|
let apt_update_dialog = adw::MessageDialog::builder()
|
||||||
@ -300,6 +316,18 @@ pub fn apt_update_page(
|
|||||||
}
|
}
|
||||||
));
|
));
|
||||||
|
|
||||||
|
let update_speed_server_context = MainContext::default();
|
||||||
|
// The main loop executes the asynchronous block
|
||||||
|
update_speed_server_context.spawn_local(clone!(
|
||||||
|
#[strong]
|
||||||
|
apt_speed_label,
|
||||||
|
async move {
|
||||||
|
while let Ok(state) = update_speed_receiver.recv().await {
|
||||||
|
apt_speed_label.set_label(&state);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
));
|
||||||
|
|
||||||
let update_status_server_context = MainContext::default();
|
let update_status_server_context = MainContext::default();
|
||||||
// The main loop executes the asynchronous block
|
// The main loop executes the asynchronous block
|
||||||
update_status_server_context.spawn_local(clone!(
|
update_status_server_context.spawn_local(clone!(
|
||||||
|
@ -385,6 +385,8 @@ fn apt_full_upgrade_from_socket(
|
|||||||
) {
|
) {
|
||||||
let (upgrade_percent_sender, upgrade_percent_receiver) = async_channel::unbounded::<String>();
|
let (upgrade_percent_sender, upgrade_percent_receiver) = async_channel::unbounded::<String>();
|
||||||
let upgrade_percent_sender = upgrade_percent_sender.clone();
|
let upgrade_percent_sender = upgrade_percent_sender.clone();
|
||||||
|
let (upgrade_speed_sender, upgrade_speed_receiver) = async_channel::unbounded::<String>();
|
||||||
|
let upgrade_speed_sender = upgrade_speed_sender.clone();
|
||||||
let (upgrade_status_sender, upgrade_status_receiver) = async_channel::unbounded::<String>();
|
let (upgrade_status_sender, upgrade_status_receiver) = async_channel::unbounded::<String>();
|
||||||
let upgrade_status_sender = upgrade_status_sender.clone();
|
let upgrade_status_sender = upgrade_status_sender.clone();
|
||||||
let upgrade_status_sender_clone0 = upgrade_status_sender.clone();
|
let upgrade_status_sender_clone0 = upgrade_status_sender.clone();
|
||||||
@ -402,6 +404,13 @@ fn apt_full_upgrade_from_socket(
|
|||||||
));
|
));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
thread::spawn(move || {
|
||||||
|
Runtime::new().unwrap().block_on(start_socket_server_no_log(
|
||||||
|
upgrade_speed_sender,
|
||||||
|
"/tmp/pika_apt_upgrade_speed.sock",
|
||||||
|
));
|
||||||
|
});
|
||||||
|
|
||||||
thread::spawn(move || {
|
thread::spawn(move || {
|
||||||
Runtime::new().unwrap().block_on(start_socket_server(
|
Runtime::new().unwrap().block_on(start_socket_server(
|
||||||
upgrade_status_sender,
|
upgrade_status_sender,
|
||||||
@ -457,7 +466,14 @@ fn apt_full_upgrade_from_socket(
|
|||||||
.width_request(128)
|
.width_request(128)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
|
let apt_speed_label = gtk::Label::builder()
|
||||||
|
.halign(Align::Center)
|
||||||
|
.margin_top(10)
|
||||||
|
.margin_bottom(10)
|
||||||
|
.build();
|
||||||
|
|
||||||
apt_upgrade_dialog_child_box.append(&apt_upgrade_dialog_spinner);
|
apt_upgrade_dialog_child_box.append(&apt_upgrade_dialog_spinner);
|
||||||
|
apt_upgrade_dialog_child_box.append(&apt_speed_label);
|
||||||
apt_upgrade_dialog_child_box.append(&apt_upgrade_dialog_progress_bar);
|
apt_upgrade_dialog_child_box.append(&apt_upgrade_dialog_progress_bar);
|
||||||
|
|
||||||
let apt_upgrade_dialog = adw::MessageDialog::builder()
|
let apt_upgrade_dialog = adw::MessageDialog::builder()
|
||||||
@ -513,6 +529,18 @@ fn apt_full_upgrade_from_socket(
|
|||||||
}
|
}
|
||||||
));
|
));
|
||||||
|
|
||||||
|
let upgrade_speed_server_context = MainContext::default();
|
||||||
|
// The main loop executes the asynchronous block
|
||||||
|
upgrade_speed_server_context.spawn_local(clone!(
|
||||||
|
#[weak]
|
||||||
|
apt_speed_label,
|
||||||
|
async move {
|
||||||
|
while let Ok(state) = upgrade_speed_receiver.recv().await {
|
||||||
|
apt_speed_label.set_label(&state);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
));
|
||||||
|
|
||||||
let upgrade_status_server_context = MainContext::default();
|
let upgrade_status_server_context = MainContext::default();
|
||||||
// The main loop executes the asynchronous block
|
// The main loop executes the asynchronous block
|
||||||
upgrade_status_server_context.spawn_local(clone!(
|
upgrade_status_server_context.spawn_local(clone!(
|
||||||
|
@ -7,9 +7,11 @@ use tokio::net::UnixStream;
|
|||||||
use tokio::runtime::Runtime;
|
use tokio::runtime::Runtime;
|
||||||
|
|
||||||
pub struct AptUpdateProgressSocket<'a> {
|
pub struct AptUpdateProgressSocket<'a> {
|
||||||
|
last_pulse_bytes: u64,
|
||||||
pulse_interval: usize,
|
pulse_interval: usize,
|
||||||
percent_socket_path: &'a str,
|
percent_socket_path: &'a str,
|
||||||
status_socket_path: &'a str,
|
status_socket_path: &'a str,
|
||||||
|
speed_socket_path: &'a str,
|
||||||
hit_strfmt_trans_str: &'a str,
|
hit_strfmt_trans_str: &'a str,
|
||||||
fetch_strfmt_trans_str: &'a str,
|
fetch_strfmt_trans_str: &'a str,
|
||||||
done_strfmt_trans_str: &'a str,
|
done_strfmt_trans_str: &'a str,
|
||||||
@ -21,15 +23,18 @@ impl<'a> AptUpdateProgressSocket<'a> {
|
|||||||
pub fn new(
|
pub fn new(
|
||||||
percent_socket_path: &'a str,
|
percent_socket_path: &'a str,
|
||||||
status_socket_path: &'a str,
|
status_socket_path: &'a str,
|
||||||
|
speed_socket_path: &'a str,
|
||||||
hit_strfmt_trans_str: &'a str,
|
hit_strfmt_trans_str: &'a str,
|
||||||
fetch_strfmt_trans_str: &'a str,
|
fetch_strfmt_trans_str: &'a str,
|
||||||
done_strfmt_trans_str: &'a str,
|
done_strfmt_trans_str: &'a str,
|
||||||
fail_strfmt_trans_str: &'a str,
|
fail_strfmt_trans_str: &'a str,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
let progress = Self {
|
let progress = Self {
|
||||||
pulse_interval: 0,
|
last_pulse_bytes: 0,
|
||||||
|
pulse_interval: 1000000,
|
||||||
percent_socket_path: percent_socket_path,
|
percent_socket_path: percent_socket_path,
|
||||||
status_socket_path: status_socket_path,
|
status_socket_path: status_socket_path,
|
||||||
|
speed_socket_path: speed_socket_path,
|
||||||
hit_strfmt_trans_str: hit_strfmt_trans_str,
|
hit_strfmt_trans_str: hit_strfmt_trans_str,
|
||||||
fetch_strfmt_trans_str: fetch_strfmt_trans_str,
|
fetch_strfmt_trans_str: fetch_strfmt_trans_str,
|
||||||
done_strfmt_trans_str: done_strfmt_trans_str,
|
done_strfmt_trans_str: done_strfmt_trans_str,
|
||||||
@ -156,10 +161,20 @@ impl<'a> DynAcquireProgress for AptUpdateProgressSocket<'a> {
|
|||||||
fn pulse(&mut self, status: &AcqTextStatus, _owner: &PkgAcquire) {
|
fn pulse(&mut self, status: &AcqTextStatus, _owner: &PkgAcquire) {
|
||||||
let progress_percent: f32 =
|
let progress_percent: f32 =
|
||||||
(status.current_bytes() as f32 * 100.0) / status.total_bytes() as f32;
|
(status.current_bytes() as f32 * 100.0) / status.total_bytes() as f32;
|
||||||
|
let speed = if self.pulse_interval != 0 {
|
||||||
|
(status.current_bytes() as f64 - self.last_pulse_bytes as f64) / (self.pulse_interval as f64 / 1000000.0)
|
||||||
|
} else {
|
||||||
|
status.current_bytes() as f64 - self.last_pulse_bytes as f64
|
||||||
|
};
|
||||||
|
self.last_pulse_bytes = status.current_bytes();
|
||||||
Runtime::new().unwrap().block_on(send_progress_percent(
|
Runtime::new().unwrap().block_on(send_progress_percent(
|
||||||
progress_percent,
|
progress_percent,
|
||||||
self.percent_socket_path,
|
self.percent_socket_path,
|
||||||
));
|
));
|
||||||
|
Runtime::new().unwrap().block_on(send_progress_status(
|
||||||
|
&(pretty_bytes::converter::convert(speed) + "ps").to_lowercase(),
|
||||||
|
self.speed_socket_path,
|
||||||
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user