diff --git a/src/build_ui/mod.rs b/src/build_ui/mod.rs index 8f40c19..a31782b 100644 --- a/src/build_ui/mod.rs +++ b/src/build_ui/mod.rs @@ -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( diff --git a/src/content/mod.rs b/src/content/mod.rs index dd4c9f2..b606fa6 100644 --- a/src/content/mod.rs +++ b/src/content/mod.rs @@ -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 |_| { - content_stack.add_named( - &kernel_pkg::kernel_pkg_page(&content_stack, &window, &selected_kernel_branch), - Some("kernel_pkg_page"), + 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") + }), ); - 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::("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: >k::Box, running_kernel_info: &RunningKernelInfo, selected_kernel_branch: &Rc>) { +fn create_kernel_badges( + badge_box: >k::Box, + running_kernel_info: &RunningKernelInfo, + selected_kernel_branch: &Rc>, +) { 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" + Some(t) => t, + _ => "Unknown", }; let version_css_style = if &running_kernel_info.version == &kernel_version { diff --git a/src/kernel_pkg/mod.rs b/src/kernel_pkg/mod.rs index 53bd3f2..91af25e 100644 --- a/src/kernel_pkg/mod.rs +++ b/src/kernel_pkg/mod.rs @@ -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: >k::Stack, window: &adw::ApplicationWindow, selected_kernel_branch: &Rc>) -> gtk::Box { +pub fn kernel_pkg_page( + content_stack: >k::Stack, + window: &adw::ApplicationWindow, + selected_kernel_branch: &Rc>, +) -> 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: >k::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: >k::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,17 +108,22 @@ pub fn kernel_pkg_page(content_stack: >k::Stack, window: &adw::ApplicationWind main_box } -fn add_package_rows(boxedlist: >k::ListBox, - data: &str, - window: &adw::ApplicationWindow, - rows_size_group: >k::SizeGroup, +fn add_package_rows( + boxedlist: >k::ListBox, + data: &str, + window: &adw::ApplicationWindow, + rows_size_group: >k::SizeGroup, ) { let res: serde_json::Value = serde_json::from_str(&data).expect("Unable to parse"); if let serde_json::Value::Array(kernels) = &res["kernels"] { 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 = log_loop_sender.clone(); @@ -115,13 +132,14 @@ fn add_package_rows(boxedlist: >k::ListBox, let log_status_loop_sender: async_channel::Sender = 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 = kernel_status_loop_sender.clone(); std::thread::spawn(move || loop { - // let command_installed_status = std::Command::new("dpkg") - // .args(["-s", &kernel_package_ind2]) + // let command_installed_status = std::Command::new("dpkg") + // .args(["-s", &kernel_package_ind2]) // .output() // .unwrap(); //if command_installed_status.status.success() { @@ -130,22 +148,20 @@ fn add_package_rows(boxedlist: >k::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: >k::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: >k::ListBox, })); // boxedlist.append(&kernel_expander_row); - }}; + } + }; } const KERNEL_MODIFY_PROG: &str = r###" @@ -358,4 +370,4 @@ fn kernel_modify( child.wait()?; Ok(()) -} \ No newline at end of file +}