loading box
This commit is contained in:
parent
dfe340584c
commit
90575150fa
@ -17,6 +17,7 @@ pub fn build_ui(app: &adw::Application) {
|
|||||||
db_url: "?".to_owned(),
|
db_url: "?".to_owned(),
|
||||||
db: "?".to_owned(),
|
db: "?".to_owned(),
|
||||||
}));
|
}));
|
||||||
|
let db_load_complete = Rc::new(RefCell::new(false));
|
||||||
|
|
||||||
let (internet_loop_sender, internet_loop_receiver) = async_channel::unbounded();
|
let (internet_loop_sender, internet_loop_receiver) = async_channel::unbounded();
|
||||||
let internet_loop_sender = internet_loop_sender.clone();
|
let internet_loop_sender = internet_loop_sender.clone();
|
||||||
@ -46,7 +47,6 @@ pub fn build_ui(app: &adw::Application) {
|
|||||||
let banner_text = "Warning: No internet connection";
|
let banner_text = "Warning: No internet connection";
|
||||||
if state == true {
|
if state == true {
|
||||||
*internet_connected_status.borrow_mut()=true;
|
*internet_connected_status.borrow_mut()=true;
|
||||||
println!("{}", selected_kernel_branch.borrow().name);
|
|
||||||
if window_banner.title() == banner_text {
|
if window_banner.title() == banner_text {
|
||||||
window_banner.set_revealed(false)
|
window_banner.set_revealed(false)
|
||||||
}
|
}
|
||||||
@ -69,7 +69,7 @@ pub fn build_ui(app: &adw::Application) {
|
|||||||
let window_toolbar = adw::ToolbarView::builder().content(&content_stack).build();
|
let window_toolbar = adw::ToolbarView::builder().content(&content_stack).build();
|
||||||
|
|
||||||
content_stack.add_named(
|
content_stack.add_named(
|
||||||
&content::content(&content_stack, &selected_kernel_branch2),
|
&content::content(&content_stack, &selected_kernel_branch2, &db_load_complete),
|
||||||
Some("content_page"),
|
Some("content_page"),
|
||||||
);
|
);
|
||||||
content_stack.add_named(
|
content_stack.add_named(
|
||||||
|
@ -9,7 +9,7 @@ use gtk::prelude::*;
|
|||||||
use gtk::*;
|
use gtk::*;
|
||||||
use homedir::get_my_home;
|
use homedir::get_my_home;
|
||||||
use std::cell::RefCell;
|
use std::cell::RefCell;
|
||||||
use std::fs;
|
use std::{fs, time};
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use std::process::{Command, Stdio};
|
use std::process::{Command, Stdio};
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
@ -19,6 +19,7 @@ use Vec;
|
|||||||
pub fn content(
|
pub fn content(
|
||||||
content_stack: >k::Stack,
|
content_stack: >k::Stack,
|
||||||
selected_kernel_branch: &Rc<RefCell<KernelBranch>>,
|
selected_kernel_branch: &Rc<RefCell<KernelBranch>>,
|
||||||
|
db_load_complete: &Rc<RefCell<bool>>,
|
||||||
) -> gtk::Box {
|
) -> gtk::Box {
|
||||||
let running_kernel_info = get_running_kernel_info();
|
let running_kernel_info = get_running_kernel_info();
|
||||||
|
|
||||||
@ -31,6 +32,31 @@ pub fn content(
|
|||||||
.expect("channel needs to be open.");
|
.expect("channel needs to be open.");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
let loading_spinner = gtk::Spinner::builder()
|
||||||
|
.hexpand(true)
|
||||||
|
.valign(Align::Start)
|
||||||
|
.halign(Align::Center)
|
||||||
|
.spinning(true)
|
||||||
|
.height_request(128)
|
||||||
|
.width_request(128)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
let loading_label = gtk::Label::builder()
|
||||||
|
.hexpand(true)
|
||||||
|
.valign(Align::Start)
|
||||||
|
.halign(Align::Center)
|
||||||
|
.label("Downloading Database...")
|
||||||
|
.build();
|
||||||
|
|
||||||
|
let loading_box = gtk::Box::builder()
|
||||||
|
.hexpand(true)
|
||||||
|
.vexpand(true)
|
||||||
|
.orientation(Orientation::Vertical)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
loading_box.append(&loading_spinner);
|
||||||
|
loading_box.append(&loading_label);
|
||||||
|
|
||||||
let content_box = gtk::Box::builder()
|
let content_box = gtk::Box::builder()
|
||||||
.hexpand(true)
|
.hexpand(true)
|
||||||
.vexpand(true)
|
.vexpand(true)
|
||||||
@ -64,6 +90,7 @@ pub fn content(
|
|||||||
kernel_branch_expander_row.add_row(&kernel_branch_expandable(
|
kernel_branch_expander_row.add_row(&kernel_branch_expandable(
|
||||||
&kernel_branch_expander_row,
|
&kernel_branch_expander_row,
|
||||||
selected_kernel_branch,
|
selected_kernel_branch,
|
||||||
|
db_load_complete,
|
||||||
get_kernel_branches_receiver.clone(),
|
get_kernel_branches_receiver.clone(),
|
||||||
));
|
));
|
||||||
|
|
||||||
@ -126,53 +153,33 @@ pub fn content(
|
|||||||
kernel_branch_expander_row_boxedlist.add_css_class("boxed-list");
|
kernel_branch_expander_row_boxedlist.add_css_class("boxed-list");
|
||||||
kernel_branch_expander_row_boxedlist.append(&kernel_branch_expander_row);
|
kernel_branch_expander_row_boxedlist.append(&kernel_branch_expander_row);
|
||||||
|
|
||||||
create_kernel_badges(&kernel_badge_box, &running_kernel_info, &selected_kernel_branch);
|
content_box.append(&loading_box);
|
||||||
|
|
||||||
content_box.append(&kernel_badge_box);
|
content_box.append(&kernel_badge_box);
|
||||||
content_box.append(&tux_icon);
|
content_box.append(&tux_icon);
|
||||||
content_box.append(&kernel_branch_expander_row_boxedlist);
|
content_box.append(&kernel_branch_expander_row_boxedlist);
|
||||||
content_box.append(&button_box);
|
content_box.append(&button_box);
|
||||||
|
|
||||||
let get_kernel_branches_loop_context = MainContext::default();
|
|
||||||
// The main loop executes the asynchronous block
|
|
||||||
get_kernel_branches_loop_context.spawn_local(
|
|
||||||
clone!(@strong selected_kernel_branch => async move {
|
|
||||||
while let Ok(data) = get_kernel_branches_receiver.recv().await {
|
|
||||||
let selected_kernel_branch_clone0 = selected_kernel_branch.clone();
|
|
||||||
let selected_kernel_branch_clone1 = selected_kernel_branch.clone();
|
|
||||||
|
|
||||||
match get_my_home()
|
let (load_badge_async_sender, load_badge_async_receiver) = async_channel::unbounded();
|
||||||
.unwrap()
|
let load_badge_async_sender = load_badge_async_sender.clone();
|
||||||
.unwrap()
|
// The long running operation runs now in a separate thread
|
||||||
.join(".config/fedora-kernel-manager/branch")
|
std::thread::spawn(move || loop {
|
||||||
.exists()
|
load_badge_async_sender
|
||||||
{
|
.send_blocking(true)
|
||||||
true => {
|
.expect("The channel needs to be open.");
|
||||||
let narrow_branch: Vec<KernelBranch> = data
|
std::thread::sleep(time::Duration::from_secs(5));
|
||||||
.clone()
|
});
|
||||||
.into_iter()
|
|
||||||
.filter(|a| {
|
let load_badge_async_context = MainContext::default();
|
||||||
a.name
|
// The main loop executes the asynchronous block
|
||||||
== fs::read_to_string(
|
load_badge_async_context.spawn_local(clone!(@weak kernel_badge_box, @strong selected_kernel_branch, @strong db_load_complete => async move {
|
||||||
get_my_home()
|
while let Ok(_state) = load_badge_async_receiver.recv().await {
|
||||||
.unwrap()
|
if *db_load_complete.borrow() == true {
|
||||||
.unwrap()
|
create_kernel_badges(&kernel_badge_box, &running_kernel_info, &selected_kernel_branch);
|
||||||
.join(".config/fedora-kernel-manager/branch"),
|
loading_box.set_visible(false)
|
||||||
)
|
|
||||||
.unwrap()
|
|
||||||
})
|
|
||||||
.collect();
|
|
||||||
*selected_kernel_branch_clone0.borrow_mut() =
|
|
||||||
narrow_branch.get(0).unwrap().clone()
|
|
||||||
}
|
}
|
||||||
_ => {
|
|
||||||
let normal_branch = data.clone().get(0).unwrap().clone();
|
|
||||||
*selected_kernel_branch_clone0.borrow_mut() = normal_branch
|
|
||||||
}
|
}
|
||||||
};
|
}));
|
||||||
}
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
|
|
||||||
content_box
|
content_box
|
||||||
}
|
}
|
||||||
@ -180,6 +187,7 @@ pub fn content(
|
|||||||
fn kernel_branch_expandable(
|
fn kernel_branch_expandable(
|
||||||
expander_row: &adw::ExpanderRow,
|
expander_row: &adw::ExpanderRow,
|
||||||
selected_kernel_branch: &Rc<RefCell<KernelBranch>>,
|
selected_kernel_branch: &Rc<RefCell<KernelBranch>>,
|
||||||
|
db_load_complete: &Rc<RefCell<bool>>,
|
||||||
get_kernel_branches_receiver: Receiver<Vec<KernelBranch>>,
|
get_kernel_branches_receiver: Receiver<Vec<KernelBranch>>,
|
||||||
) -> gtk::ListBox {
|
) -> gtk::ListBox {
|
||||||
let searchbar = gtk::SearchEntry::builder().search_delay(500).build();
|
let searchbar = gtk::SearchEntry::builder().search_delay(500).build();
|
||||||
@ -202,7 +210,7 @@ fn kernel_branch_expandable(
|
|||||||
|
|
||||||
let get_kernel_branches_loop_context = MainContext::default();
|
let get_kernel_branches_loop_context = MainContext::default();
|
||||||
// The main loop executes the asynchronous block
|
// The main loop executes the asynchronous block
|
||||||
get_kernel_branches_loop_context.spawn_local(clone!(@weak expander_row, @weak branch_container, @strong selected_kernel_branch => async move {
|
get_kernel_branches_loop_context.spawn_local(clone!(@weak expander_row, @weak branch_container, @strong selected_kernel_branch, @strong db_load_complete => async move {
|
||||||
while let Ok(data) = get_kernel_branches_receiver.recv().await {
|
while let Ok(data) = get_kernel_branches_receiver.recv().await {
|
||||||
for branch in data {
|
for branch in data {
|
||||||
let branch_clone0 = branch.clone();
|
let branch_clone0 = branch.clone();
|
||||||
@ -247,7 +255,10 @@ for branch in data {
|
|||||||
branch_checkbutton.set_active(true)
|
branch_checkbutton.set_active(true)
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
};
|
||||||
|
|
||||||
|
*db_load_complete.borrow_mut() = true;
|
||||||
|
println!("DB load complete!")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
@ -364,6 +375,7 @@ fn get_kernel_branches() -> Vec<KernelBranch> {
|
|||||||
.text()
|
.text()
|
||||||
.unwrap(),
|
.unwrap(),
|
||||||
};
|
};
|
||||||
|
println!("Download Complete!");
|
||||||
kernel_branches_array.push(branch)
|
kernel_branches_array.push(branch)
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -440,7 +452,11 @@ fn create_kernel_badges(badge_box: >k::Box, running_kernel_info: &RunningKerne
|
|||||||
let kernel_badges_size_group1 = 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");
|
let json: serde_json::Value = serde_json::from_str(&selected_kernel_branch_clone.db).expect("Unable to parse");
|
||||||
let kernel_version = json["latest_version"].as_str().expect("invalid json");
|
|
||||||
|
let kernel_version = match json["latest_version"].as_str() {
|
||||||
|
Some(t) => t,
|
||||||
|
_ => "Unknown"
|
||||||
|
};
|
||||||
|
|
||||||
let version_css_style = if &running_kernel_info.version == &kernel_version {
|
let version_css_style = if &running_kernel_info.version == &kernel_version {
|
||||||
"background-green-bg"
|
"background-green-bg"
|
||||||
|
Loading…
Reference in New Issue
Block a user