Use circullar progress bars

This commit is contained in:
Ward from fusion-voyager-3 2024-10-24 16:06:31 +03:00
parent ca384651e6
commit d36bda43a5
7 changed files with 132 additions and 44 deletions

40
Cargo.lock generated
View File

@ -241,6 +241,15 @@ dependencies = [
"windows-targets 0.52.6",
]
[[package]]
name = "circularprogressbar-rs"
version = "0.1.1"
source = "git+https://github.com/CosmicFusion/circularprogressbar-rs#30e859449207875bb2ec1c9992d96f6cfb63fd9a"
dependencies = [
"gtk4",
"pangocairo",
]
[[package]]
name = "clap"
version = "2.34.0"
@ -1003,9 +1012,9 @@ dependencies = [
[[package]]
name = "gtk4"
version = "0.9.0"
version = "0.9.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "eaffc6c743c9160514cc9b67eace364e5dc5798369fa809cdb04e035c21c5c5d"
checksum = "31e2d105ce672f5cdcb5af2602e91c2901e91c72da15ab76f613ad57ecf04c6d"
dependencies = [
"cairo-rs",
"field-offset",
@ -1689,6 +1698,32 @@ dependencies = [
"system-deps 7.0.1",
]
[[package]]
name = "pangocairo"
version = "0.20.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4291ca8cdd05e4330752bf8a450d3a4e701ca48fd9aad2b3566e92849ee4055e"
dependencies = [
"cairo-rs",
"glib 0.20.0",
"libc",
"pango",
"pangocairo-sys",
]
[[package]]
name = "pangocairo-sys"
version = "0.20.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "be0ed959258ea648a49bde7dfdbaa98310717cb15159b421fa76510c45ec306e"
dependencies = [
"cairo-sys-rs",
"glib-sys 0.20.0",
"libc",
"pango-sys",
"system-deps 7.0.1",
]
[[package]]
name = "parking"
version = "2.2.0"
@ -1763,6 +1798,7 @@ dependencies = [
"async-channel",
"async-trait",
"chrono",
"circularprogressbar-rs",
"configparser",
"crossbeam-utils 0.8.20",
"deb822-tools",

View File

@ -22,7 +22,7 @@ path = "src/bin/apt/apt_full_upgrade/main.rs"
[dependencies]
adw = { version = "0.7.0", package = "libadwaita", features = ["v1_4"] }
gtk = { version = "0.9.0", package = "gtk4", features = ["v4_12"] }
gtk = { version = "0.9.2", package = "gtk4", features = ["v4_12"] }
async-channel = "2.1.1"
rust-i18n = "3.0.1"
rust-apt = "0.8.0"
@ -47,4 +47,4 @@ configparser = "3.1.0"
ksni = "0.2.2"
single-instance = "0.3.3"
os_pipe = "1.1.5"
circularprogressbar-rs = { git = "https://github.com/CosmicFusion/circularprogressbar-rs", version = "0.1.1" }

View File

@ -167,5 +167,6 @@
"apt_update_str_fail": "Download Failed: {DESC} {SHORT_DESC}",
"retry_interval_labal_label": "Automatically Check for updates",
"retry_interval_spinrow_title": "Automatic Check Interval",
"retry_interval_spinrow_subtitle": "In Hours"
"retry_interval_spinrow_subtitle": "In Hours",
"progress_bar_circle_center_text": "Percent %"
}

View File

@ -17,6 +17,8 @@ use std::rc::Rc;
use std::thread;
use tokio::runtime::Runtime;
use crate::build_ui::get_current_font;
struct AptChangesInfo {
package_count_upgrade: u64,
package_count_install: u64,
@ -454,17 +456,22 @@ fn apt_full_upgrade_from_socket(
let apt_upgrade_dialog_child_box = Box::builder().orientation(Orientation::Vertical).build();
let apt_upgrade_dialog_progress_bar =
ProgressBar::builder().show_text(true).hexpand(true).build();
let apt_upgrade_dialog_spinner = Spinner::builder()
.hexpand(true)
.valign(Align::Start)
.halign(Align::Center)
.spinning(true)
.height_request(128)
.width_request(128)
.build();
let apt_upgrade_dialog_progress_bar = circularprogressbar_rs::CircularProgressBar::new();
apt_upgrade_dialog_progress_bar.set_line_width(10.0);
apt_upgrade_dialog_progress_bar.set_fill_radius(true);
apt_upgrade_dialog_progress_bar.set_hexpand(true);
apt_upgrade_dialog_progress_bar.set_vexpand(true);
apt_upgrade_dialog_progress_bar.set_width_request(200);
apt_upgrade_dialog_progress_bar.set_height_request(200);
#[allow(deprecated)]
apt_upgrade_dialog_progress_bar.set_progress_fill_color(window.style_context().lookup_color("accent_bg_color").unwrap());
#[allow(deprecated)]
apt_upgrade_dialog_progress_bar.set_radius_fill_color(window.style_context().lookup_color("headerbar_bg_color").unwrap());
#[warn(deprecated)]
apt_upgrade_dialog_progress_bar.set_progress_font(get_current_font());
apt_upgrade_dialog_progress_bar.set_center_text(t!("progress_bar_circle_center_text"));
apt_upgrade_dialog_progress_bar.set_fraction_font_size(24);
apt_upgrade_dialog_progress_bar.set_center_text_font_size(8);
let apt_speed_label = gtk::Label::builder()
.halign(Align::Center)
@ -472,9 +479,8 @@ fn apt_full_upgrade_from_socket(
.margin_bottom(10)
.build();
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_speed_label);
let apt_upgrade_dialog = adw::MessageDialog::builder()
.transient_for(&window)

View File

@ -16,6 +16,41 @@ use std::sync::Arc;
use std::sync::Mutex;
use std::thread;
fn get_gsettings_font() -> String {
let glib_settings = gio::Settings::new("org.gnome.desktop.interface");
let font = glib_settings.string("font-name").to_string();
let re = regex::Regex::new(r" [^ ]*$").unwrap();
re.replace(&font, "").to_string()
}
pub fn get_current_font() -> String {
let mut gtk_config_file = configparser::ini::Ini::new();
match std::fs::read_to_string(std::env::var_os("HOME").unwrap().to_string_lossy().to_string() + "/.config/gtk-4.0/settings.ini") {
Ok(t) => {
match gtk_config_file.read(t) {
Ok(_) => {
match gtk_config_file.get("Settings", "gtk-font-name") {
Some(s) => {
let re = regex::Regex::new(r",[^,]*$").unwrap();
return re.replace(&s, "").to_string();
},
None => {
return get_gsettings_font();
}
}
}
Err(_) => {
return get_gsettings_font();
}
}
}
Err(_) => {
return get_gsettings_font();
}
}
}
#[derive(Debug)]
struct PikmanTray {
icon_name: Option<String>,

View File

@ -1,5 +1,6 @@
mod process;
use crate::build_ui::get_current_font;
use crate::flatpak_ref_row::FlatpakRefRow;
use adw::gio::SimpleAction;
use adw::prelude::*;
@ -205,19 +206,23 @@ pub fn flatpak_update_page(
let flatpak_update_dialog_child_box = Box::builder().orientation(Orientation::Vertical).build();
let flatpak_update_dialog_progress_bar =
ProgressBar::builder().show_text(true).hexpand(true).build();
let flatpak_update_dialog_progress_bar = circularprogressbar_rs::CircularProgressBar::new();
flatpak_update_dialog_progress_bar.set_line_width(10.0);
flatpak_update_dialog_progress_bar.set_fill_radius(true);
flatpak_update_dialog_progress_bar.set_hexpand(true);
flatpak_update_dialog_progress_bar.set_vexpand(true);
flatpak_update_dialog_progress_bar.set_width_request(200);
flatpak_update_dialog_progress_bar.set_height_request(200);
#[allow(deprecated)]
flatpak_update_dialog_progress_bar.set_progress_fill_color(window.style_context().lookup_color("accent_bg_color").unwrap());
#[allow(deprecated)]
flatpak_update_dialog_progress_bar.set_radius_fill_color(window.style_context().lookup_color("headerbar_bg_color").unwrap());
#[warn(deprecated)]
flatpak_update_dialog_progress_bar.set_progress_font(get_current_font());
flatpak_update_dialog_progress_bar.set_center_text(t!("progress_bar_circle_center_text"));
flatpak_update_dialog_progress_bar.set_fraction_font_size(24);
flatpak_update_dialog_progress_bar.set_center_text_font_size(8);
let flatpak_update_dialog_spinner = Spinner::builder()
.hexpand(true)
.valign(Align::Start)
.halign(Align::Center)
.spinning(true)
.height_request(128)
.width_request(128)
.build();
flatpak_update_dialog_child_box.append(&flatpak_update_dialog_spinner);
flatpak_update_dialog_child_box.append(&flatpak_update_dialog_progress_bar);
let flatpak_update_dialog = adw::MessageDialog::builder()
@ -344,7 +349,7 @@ pub fn flatpak_update_page(
flatpak_update_dialog_progress_bar,
async move {
while let Ok(state) = appstream_sync_percent_receiver.recv().await {
flatpak_update_dialog_progress_bar.set_fraction(state as f64 / 100.0)
flatpak_update_dialog_progress_bar.set_fraction(state as f64 / 100.0);
}
}
));

View File

@ -1,3 +1,4 @@
use crate::build_ui::get_current_font;
use crate::flatpak_ref_row::FlatpakRefRow;
use adw::gio::SimpleAction;
use adw::prelude::*;
@ -362,19 +363,23 @@ fn flatpak_run_transactions(
let flatpak_transaction_dialog_child_box =
Box::builder().orientation(Orientation::Vertical).build();
let flatpak_transaction_dialog_progress_bar =
ProgressBar::builder().show_text(true).hexpand(true).build();
let flatpak_transaction_dialog_progress_bar = circularprogressbar_rs::CircularProgressBar::new();
flatpak_transaction_dialog_progress_bar.set_line_width(10.0);
flatpak_transaction_dialog_progress_bar.set_fill_radius(true);
flatpak_transaction_dialog_progress_bar.set_hexpand(true);
flatpak_transaction_dialog_progress_bar.set_vexpand(true);
flatpak_transaction_dialog_progress_bar.set_width_request(200);
flatpak_transaction_dialog_progress_bar.set_height_request(200);
#[allow(deprecated)]
flatpak_transaction_dialog_progress_bar.set_progress_fill_color(window.style_context().lookup_color("accent_bg_color").unwrap());
#[allow(deprecated)]
flatpak_transaction_dialog_progress_bar.set_radius_fill_color(window.style_context().lookup_color("headerbar_bg_color").unwrap());
#[warn(deprecated)]
flatpak_transaction_dialog_progress_bar.set_progress_font(get_current_font());
flatpak_transaction_dialog_progress_bar.set_center_text(t!("progress_bar_circle_center_text"));
flatpak_transaction_dialog_progress_bar.set_fraction_font_size(24);
flatpak_transaction_dialog_progress_bar.set_center_text_font_size(8);
let flatpak_transaction_dialog_spinner = Spinner::builder()
.hexpand(true)
.valign(Align::Start)
.halign(Align::Center)
.spinning(true)
.height_request(128)
.width_request(128)
.build();
flatpak_transaction_dialog_child_box.append(&flatpak_transaction_dialog_spinner);
flatpak_transaction_dialog_child_box.append(&flatpak_transaction_dialog_progress_bar);
let flatpak_transaction_dialog = adw::MessageDialog::builder()
@ -419,7 +424,7 @@ fn flatpak_run_transactions(
flatpak_transaction_dialog_progress_bar,
async move {
while let Ok(state) = transaction_percent_receiver.recv().await {
flatpak_transaction_dialog_progress_bar.set_fraction((state as f32 / 100.0).into());
flatpak_transaction_dialog_progress_bar.set_fraction(state as f64 / 100.0);
}
}
));