fix full select

This commit is contained in:
Ward from fusion-voyager-3 2024-07-11 08:53:14 +03:00
parent 0c03d60203
commit c055c23e08
4 changed files with 42 additions and 26 deletions

View File

@ -10,38 +10,48 @@ fn main() {
let percent_socket_path = "/tmp/pika_apt_upgrade_percent.sock";
let status_socket_path = "/tmp/pika_apt_upgrade_status.sock";
let json_file_path = "/tmp/pika-apt-exclusions.json";
let mut excluded_updates_vec = Vec::new();
let mut excluded_updates_vec: Vec<String> = Vec::new();
let json: serde_json::Value = serde_json::from_str(
&std::fs::read_to_string(json_file_path).expect("Unable to read file"),
)
.expect("JSON was not well-formatted");
if let serde_json::Value::Array(exclusions) = &json["exclusions"] {
for exclusion in exclusions {
excluded_updates_vec.push(exclusion["package"].as_str().unwrap());
if std::path::Path::new(json_file_path).exists() {
let data = std::fs::read_to_string(json_file_path).expect("Unable to read file");
let json: serde_json::Value = serde_json::from_str(&data).expect("JSON was not well-formatted");
if let serde_json::Value::Array(exclusions) = &json["exclusions"] {
for exclusion in exclusions {
match exclusion["package"].as_str() {
Some(v) => {
excluded_updates_vec.push(v.to_owned());
}
None => {}
}
}
}
}
let apt_cache = new_cache!().unwrap();
let apt_upgrade_cache = new_cache!().unwrap();
apt_cache.upgrade(Upgrade::FullUpgrade).unwrap();
for change in apt_cache.get_changes(false) {
if !excluded_updates_vec
.iter()
.any(|e| change.name().contains(e))
{
let pkg = apt_upgrade_cache.get(change.name()).unwrap();
if change.marked_upgrade() || change.marked_install() || change.marked_downgrade() {
pkg.mark_install(true, false);
} else if change.marked_delete() {
pkg.mark_delete(false);
let apt_upgrade_cache = if excluded_updates_vec.is_empty() {
apt_cache
} else {
let apt_upgrade_cache = new_cache!().unwrap();
for change in apt_cache.get_changes(false) {
if !excluded_updates_vec
.iter()
.any(|e| change.name().contains(e))
{
let pkg = apt_upgrade_cache.get(change.name()).unwrap();
if change.marked_upgrade() || change.marked_install() || change.marked_downgrade() {
pkg.mark_install(true, false);
} else if change.marked_delete() {
pkg.mark_delete(false);
}
pkg.protect();
}
pkg.protect();
}
}
apt_upgrade_cache
};
apt_upgrade_cache.resolve(true).unwrap();

View File

@ -209,7 +209,10 @@ 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, async move {
while let Ok(state) = update_percent_receiver.recv().await {
apt_update_dialog_progress_bar.set_fraction(state.parse::<f64>().unwrap()/100.0)
match state.parse::<f64>() {
Ok(p) => apt_update_dialog_progress_bar.set_fraction(p/100.0),
Err(_) => {}
}
}
}));

View File

@ -471,7 +471,10 @@ fn apt_full_upgrade_from_socket(
match state.as_ref() {
"FN_OVERRIDE_SUCCESSFUL" => {}
_ => {
apt_upgrade_dialog_progress_bar.set_fraction(state.parse::<f64>().unwrap()/100.0)
match state.parse::<f64>() {
Ok(p) => apt_upgrade_dialog_progress_bar.set_fraction(p/100.0),
Err(_) => {}
}
}
}
}

View File

@ -11,8 +11,8 @@ use std::thread;
pub fn build_ui(app: &Application) {
// setup glib
glib::set_prgname(Some(t!("app_name").to_string()));
glib::set_application_name(&t!("app_name").to_string());
glib::set_prgname(Some(t!("application_name").to_string()));
glib::set_application_name(&t!("application_name").to_string());
let internet_connected = Rc::new(RefCell::new(false));
let (internet_loop_sender, internet_loop_receiver) = async_channel::unbounded();