fix config corruption crash

This commit is contained in:
Ward from fusion-voyager-3 2024-06-19 02:44:51 +03:00
parent 8109f2db5e
commit 632dca0f46
3 changed files with 75 additions and 63 deletions

View File

@ -77,7 +77,12 @@ pub fn build_ui(app: &adw::Application) {
.build();
content_stack.add_named(
&content::content(&content_stack, &selected_kernel_branch2, &db_load_complete, &window),
&content::content(
&content_stack,
&selected_kernel_branch2,
&db_load_complete,
&window,
),
Some("content_page"),
);
content_stack.add_named(

View File

@ -9,10 +9,10 @@ use gtk::prelude::*;
use gtk::*;
use homedir::get_my_home;
use std::cell::RefCell;
use std::{fs, time};
use std::path::Path;
use std::process::{Command, Stdio};
use std::rc::Rc;
use std::{fs, time};
use version_compare::Version;
use Vec;
@ -128,13 +128,15 @@ pub fn content(
.build();
browse_kernels_button.add_css_class("circular");
browse_kernels_button.connect_clicked(clone!(@weak window, @weak content_stack, @strong selected_kernel_branch => move |_| {
browse_kernels_button.connect_clicked(
clone!(@weak window, @weak content_stack, @strong selected_kernel_branch => move |_| {
content_stack.add_named(
&kernel_pkg::kernel_pkg_page(&content_stack, &window, &selected_kernel_branch),
Some("kernel_pkg_page"),
);
content_stack.set_visible_child_name("kernel_pkg_page")
}));
}),
);
let config_kernel_button = gtk::Button::builder()
.icon_name("settings")
@ -164,7 +166,6 @@ pub fn content(
content_box.append(&kernel_branch_expander_row_boxedlist);
content_box.append(&button_box);
let (load_badge_async_sender, load_badge_async_receiver) = async_channel::unbounded();
let load_badge_async_sender = load_badge_async_sender.clone();
// The long running operation runs now in a separate thread
@ -243,24 +244,12 @@ for branch in data {
}),
);
match get_my_home()
.unwrap()
.unwrap()
.join(".config/fedora-kernel-manager/branch")
.exists()
{
true if fs::read_to_string(
get_my_home()
.unwrap()
.unwrap()
.join(".config/fedora-kernel-manager/branch"),
)
.unwrap()
== branch_clone1.name =>
match get_my_home().unwrap().unwrap().join(".config/fedora-kernel-manager/branch").exists() {
true if fs::read_to_string(get_my_home().unwrap().unwrap().join(".config/fedora-kernel-manager/branch")).unwrap()== branch_clone1.name && std::fs::metadata(get_my_home().unwrap().unwrap().join(".config/fedora-kernel-manager/branch")).expect("file metadata not found").len() == 0 =>
{
branch_checkbutton.set_active(true)
}
_ => {}
_ => branch_container.first_child().unwrap().property::<gtk::CheckButton>("activatable_widget").set_property("active", true),
};
*db_load_complete.borrow_mut() = true;
@ -450,18 +439,24 @@ fn bore_check() -> bool {
is_bore
}
fn create_kernel_badges(badge_box: &gtk::Box, running_kernel_info: &RunningKernelInfo, selected_kernel_branch: &Rc<RefCell<KernelBranch>>) {
fn create_kernel_badges(
badge_box: &gtk::Box,
running_kernel_info: &RunningKernelInfo,
selected_kernel_branch: &Rc<RefCell<KernelBranch>>,
) {
let selected_kernel_branch_clone = selected_kernel_branch.borrow().clone();
let kernel_badges_size_group = gtk::SizeGroup::new(SizeGroupMode::Both);
let kernel_badges_size_group0 = gtk::SizeGroup::new(SizeGroupMode::Both);
let kernel_badges_size_group1 = gtk::SizeGroup::new(SizeGroupMode::Both);
let json: serde_json::Value = serde_json::from_str(&selected_kernel_branch_clone.db).expect("Unable to parse");
dbg!(&selected_kernel_branch_clone.db);
let json: serde_json::Value =
serde_json::from_str(&selected_kernel_branch_clone.db).expect("Unable to parse");
let kernel_version = match json["latest_version"].as_str() {
Some(t) => t,
_ => "Unknown"
_ => "Unknown",
};
let version_css_style = if &running_kernel_info.version == &kernel_version {

View File

@ -1,21 +1,25 @@
use std::io::BufReader;
use duct::cmd;
use std::process::Command;
use std::cell::RefCell;
use crate::content::get_running_kernel_info;
use crate::{KernelBranch, RunningKernelInfo};
use adw::prelude::*;
use duct::cmd;
use glib::*;
use gtk::prelude::*;
use gtk::*;
use std::cell::RefCell;
use std::error::Error;
use std::fs;
use std::fs::*;
use std::io::BufRead;
use std::io::BufReader;
use std::process::Command;
use std::rc::Rc;
use std::time::*;
use std::error::Error;
use std::io::BufRead;
pub fn kernel_pkg_page(content_stack: &gtk::Stack, window: &adw::ApplicationWindow, selected_kernel_branch: &Rc<RefCell<KernelBranch>>) -> gtk::Box {
pub fn kernel_pkg_page(
content_stack: &gtk::Stack,
window: &adw::ApplicationWindow,
selected_kernel_branch: &Rc<RefCell<KernelBranch>>,
) -> gtk::Box {
let selected_kernel_branch_clone0 = selected_kernel_branch.borrow().clone();
let main_box = gtk::Box::builder()
@ -25,7 +29,10 @@ pub fn kernel_pkg_page(content_stack: &gtk::Stack, window: &adw::ApplicationWind
.build();
let main_label = gtk::Label::builder()
.label(format!("Available Kernel Packages for {}", &selected_kernel_branch_clone0.name))
.label(format!(
"Available Kernel Packages for {}",
&selected_kernel_branch_clone0.name
))
.hexpand(true)
.margin_start(10)
.margin_end(10)
@ -49,7 +56,12 @@ pub fn kernel_pkg_page(content_stack: &gtk::Stack, window: &adw::ApplicationWind
.build();
packages_boxedlist.add_css_class("boxed-list");
let rows_size_group = gtk::SizeGroup::new(SizeGroupMode::Both);
add_package_rows(&packages_boxedlist, &selected_kernel_branch_clone0.db, &window, &rows_size_group);
add_package_rows(
&packages_boxedlist,
&selected_kernel_branch_clone0.db,
&window,
&rows_size_group,
);
let packages_viewport = gtk::ScrolledWindow::builder()
.hscrollbar_policy(PolicyType::Never)
@ -96,7 +108,8 @@ pub fn kernel_pkg_page(content_stack: &gtk::Stack, window: &adw::ApplicationWind
main_box
}
fn add_package_rows(boxedlist: &gtk::ListBox,
fn add_package_rows(
boxedlist: &gtk::ListBox,
data: &str,
window: &adw::ApplicationWindow,
rows_size_group: &gtk::SizeGroup,
@ -106,7 +119,11 @@ fn add_package_rows(boxedlist: &gtk::ListBox,
for kernel in kernels {
let kernel_name = kernel["name"].as_str().to_owned().unwrap().to_string();
let kernel_package = kernel["package"].as_str().to_owned().unwrap().to_string();
let kernel_description = kernel["description"].as_str().to_owned().unwrap().to_string();
let kernel_description = kernel["description"]
.as_str()
.to_owned()
.unwrap()
.to_string();
let (log_loop_sender, log_loop_receiver) = async_channel::unbounded();
let log_loop_sender: async_channel::Sender<String> = log_loop_sender.clone();
@ -115,7 +132,8 @@ fn add_package_rows(boxedlist: &gtk::ListBox,
let log_status_loop_sender: async_channel::Sender<bool> =
log_status_loop_sender.clone();
let (kernel_status_loop_sender, kernel_status_loop_receiver) = async_channel::unbounded();
let (kernel_status_loop_sender, kernel_status_loop_receiver) =
async_channel::unbounded();
let kernel_status_loop_sender: async_channel::Sender<bool> =
kernel_status_loop_sender.clone();
@ -130,22 +148,20 @@ fn add_package_rows(boxedlist: &gtk::ListBox,
// kernel_status_loop_sender.send_blocking(false).expect("channel needs to be open")
//}
std::thread::sleep(Duration::from_secs(6));
kernel_status_loop_sender.send_blocking(true).expect("channel needs to be open")
kernel_status_loop_sender
.send_blocking(true)
.expect("channel needs to be open")
});
let kernel_expander_row = adw::ExpanderRow::new();
let kernel_package_label = gtk::Label::builder()
.label(&kernel_package)
.build();
let kernel_package_label = gtk::Label::builder().label(&kernel_package).build();
let kernel_status_icon = gtk::Image::builder()
.icon_name("emblem-default")
.pixel_size(24)
.visible(false)
.tooltip_text("Installed")
.build();
let kernel_description_label = gtk::Label::builder()
.label(&kernel_description)
.build();
let kernel_description_label = gtk::Label::builder().label(&kernel_description).build();
let kernel_content_row = adw::ActionRow::builder().build();
let kernel_install_button = gtk::Button::builder()
.margin_start(5)
@ -221,14 +237,9 @@ fn add_package_rows(boxedlist: &gtk::ListBox,
.height_request(200)
.heading("Installing Kernel")
.build();
kernel_install_dialog.add_response(
"kernel_install_dialog_ok",
"OK",
);
kernel_install_dialog.add_response(
"kernel_install_dialog_reboot",
"Reboot Now (Optional)",
);
kernel_install_dialog.add_response("kernel_install_dialog_ok", "OK");
kernel_install_dialog
.add_response("kernel_install_dialog_reboot", "Reboot Now (Optional)");
kernel_install_dialog.set_response_appearance(
"kernel_install_dialog_reboot",
adw::ResponseAppearance::Suggested,
@ -333,7 +344,8 @@ fn add_package_rows(boxedlist: &gtk::ListBox,
}));
//
boxedlist.append(&kernel_expander_row);
}};
}
};
}
const KERNEL_MODIFY_PROG: &str = r###"