Limit connection checks, and make them non locking
All checks were successful
PikaOS Package Build & Release (amd64-v3) / build (push) Successful in 2m13s

This commit is contained in:
Ward from fusion-voyager-3 2024-09-04 11:57:12 +03:00
parent 7f4683c653
commit f6e0cc6750
10 changed files with 16 additions and 185 deletions

View File

@ -1 +1 @@
6
7

2
debian/changelog vendored
View File

@ -1,4 +1,4 @@
pika-welcome (5.0.0-101pika4) pika; urgency=low
pika-welcome (5.0.0-101pika5) pika; urgency=low
* Port to PikaOS 4

View File

@ -16,7 +16,7 @@
"recommended_addons_command_dialog_ok_label": "Ok",
"welcome_page_text_title": "Welcome to PikaOS",
"welcome_page_text_description": "Thank you for choosing PikaOS!\nThis welcome screen will help guide you through the\navailable resources for PikaOS as well as help you setup \nyour computer to your liking.\n\nEnjoy!\nThe PikaOS team",
"window_banner_no_internet": "Application Locked: No Internet Connection!",
"window_banner_no_internet": "Warning: No Internet Connection!",
"launch-label": "Launch",
"update-pikaos-title": "Update my system",
"update-pikaos-subtitle": "Update all applications and system packages.",

View File

@ -4,11 +4,8 @@ use adw::*;
use duct::cmd;
use glib::*;
use serde::Deserialize;
use std::cell::RefCell;
use std::fs;
use std::path::Path;
use std::rc::Rc;
use std::{thread, time};
#[allow(non_camel_case_types)]
#[derive(PartialEq, Debug, Eq, Hash, Clone, Ord, PartialOrd, Deserialize)]
@ -24,19 +21,7 @@ struct community_entry {
pub fn community_page(
community_content_page_stack: &gtk::Stack,
window: &adw::ApplicationWindow,
internet_connected: &Rc<RefCell<bool>>,
) {
let internet_connected_status = internet_connected.clone();
let (internet_loop_sender, internet_loop_receiver) = async_channel::unbounded();
let internet_loop_sender = internet_loop_sender.clone();
// The long running operation runs now in a separate thread
gio::spawn_blocking(move || loop {
thread::sleep(time::Duration::from_secs(1));
internet_loop_sender
.send_blocking(true)
.expect("The channel needs to be open.");
});
let community_page_box = gtk::Box::builder().vexpand(true).hexpand(true).build();
@ -60,20 +45,6 @@ pub fn community_page(
.min_content_width(520)
.build();
let internet_loop_context = MainContext::default();
// The main loop executes the asynchronous block
internet_loop_context.spawn_local(
clone!(@strong internet_connected_status, @weak community_page_box => async move {
while let Ok(_state) = internet_loop_receiver.recv().await {
if *internet_connected_status.borrow_mut() == true {
community_page_box.set_sensitive(true);
} else {
community_page_box.set_sensitive(false);
}
}
}),
);
let mut json_array: Vec<community_entry> = Vec::new();
let json_path = "/usr/share/pika-welcome/config/community.json";
let json_data = fs::read_to_string(json_path).expect("Unable to read json");

View File

@ -4,11 +4,8 @@ use adw::*;
use duct::cmd;
use glib::*;
use serde::Deserialize;
use std::cell::RefCell;
use std::fs;
use std::path::Path;
use std::rc::Rc;
use std::{thread, time};
#[allow(non_camel_case_types)]
#[derive(PartialEq, Debug, Eq, Hash, Clone, Ord, PartialOrd, Deserialize)]
@ -24,19 +21,7 @@ struct contribute_entry {
pub fn contribute_page(
contribute_content_page_stack: &gtk::Stack,
window: &adw::ApplicationWindow,
internet_connected: &Rc<RefCell<bool>>,
) {
let internet_connected_status = internet_connected.clone();
let (internet_loop_sender, internet_loop_receiver) = async_channel::unbounded();
let internet_loop_sender = internet_loop_sender.clone();
// The long running operation runs now in a separate thread
gio::spawn_blocking(move || loop {
thread::sleep(time::Duration::from_secs(1));
internet_loop_sender
.send_blocking(true)
.expect("The channel needs to be open.");
});
let contribute_page_box = gtk::Box::builder().vexpand(true).hexpand(true).build();
@ -60,20 +45,6 @@ pub fn contribute_page(
.min_content_width(520)
.build();
let internet_loop_context = MainContext::default();
// The main loop executes the asynchronous block
internet_loop_context.spawn_local(
clone!(@strong internet_connected_status, @weak contribute_page_box => async move {
while let Ok(_state) = internet_loop_receiver.recv().await {
if *internet_connected_status.borrow_mut() == true {
contribute_page_box.set_sensitive(true);
} else {
contribute_page_box.set_sensitive(false);
}
}
}),
);
let mut json_array: Vec<contribute_entry> = Vec::new();
let json_path = "/usr/share/pika-welcome/config/contribute.json";
let json_data = fs::read_to_string(json_path).expect("Unable to read json");

View File

@ -4,11 +4,8 @@ use adw::*;
use duct::cmd;
use glib::*;
use serde::Deserialize;
use std::cell::RefCell;
use std::path::Path;
use std::rc::Rc;
use std::{env, fs};
use std::{thread, time};
#[allow(non_camel_case_types)]
#[derive(PartialEq, Debug, Eq, Hash, Clone, Ord, PartialOrd, Deserialize)]
@ -25,19 +22,7 @@ struct look_and_feel_entry {
pub fn look_and_feel_page(
look_and_feel_content_page_stack: &gtk::Stack,
window: &adw::ApplicationWindow,
internet_connected: &Rc<RefCell<bool>>,
) {
let internet_connected_status = internet_connected.clone();
let (internet_loop_sender, internet_loop_receiver) = async_channel::unbounded();
let internet_loop_sender = internet_loop_sender.clone();
// The long running operation runs now in a separate thread
gio::spawn_blocking(move || loop {
thread::sleep(time::Duration::from_secs(1));
internet_loop_sender
.send_blocking(true)
.expect("The channel needs to be open.");
});
let look_and_feel_page_box = gtk::Box::builder().vexpand(true).hexpand(true).build();
@ -61,20 +46,6 @@ pub fn look_and_feel_page(
.min_content_width(520)
.build();
let internet_loop_context = MainContext::default();
// The main loop executes the asynchronous block
internet_loop_context.spawn_local(
clone!(@strong internet_connected_status, @weak look_and_feel_page_box => async move {
while let Ok(_state) = internet_loop_receiver.recv().await {
if *internet_connected_status.borrow_mut() == true {
look_and_feel_page_box.set_sensitive(true);
} else {
look_and_feel_page_box.set_sensitive(false);
}
}
}),
);
let mut json_array: Vec<look_and_feel_entry> = Vec::new();
let json_path = "/usr/share/pika-welcome/config/look_and_feel.json";
let json_data = fs::read_to_string(json_path).expect("Unable to read json");

View File

@ -34,6 +34,7 @@ pub fn welcome_content_page(window: &adw::ApplicationWindow, content_box: &gtk::
let internet_loop_sender = internet_loop_sender.clone();
// The long running operation runs now in a separate thread
gio::spawn_blocking(move || {
let mut last_result = false;
loop {
//match check_internet_connection() {
// Ok(_) => {
@ -43,6 +44,10 @@ pub fn welcome_content_page(window: &adw::ApplicationWindow, content_box: &gtk::
// internet_loop_sender.send_blocking(false).expect("The channel needs to be open.");
// }
//}
if last_result == true {
std::thread::sleep(std::time::Duration::from_secs(60));
}
let check_internet_connection_cli = Command::new("ping")
.arg("iso.pika-os.com")
.arg("-c 1")
@ -52,10 +57,12 @@ pub fn welcome_content_page(window: &adw::ApplicationWindow, content_box: &gtk::
internet_loop_sender
.send_blocking(true)
.expect("The channel needs to be open.");
last_result = true
} else {
internet_loop_sender
.send_blocking(false)
.expect("The channel needs to be open.");
last_result = false
}
}
});
@ -206,10 +213,10 @@ pub fn welcome_content_page(window: &adw::ApplicationWindow, content_box: &gtk::
&window_banner,
&internet_connected,
);
setup_steps_page(&welcome_content_page_stack, &window, &internet_connected);
recommended_addons_page(&welcome_content_page_stack, &window, &internet_connected);
look_and_feel_page(&welcome_content_page_stack, &window, &internet_connected);
troubleshoot_page(&welcome_content_page_stack, &window, &internet_connected);
community_page(&welcome_content_page_stack, &window, &internet_connected);
contribute_page(&welcome_content_page_stack, &window, &internet_connected);
setup_steps_page(&welcome_content_page_stack, &window);
recommended_addons_page(&welcome_content_page_stack, &window);
look_and_feel_page(&welcome_content_page_stack, &window);
troubleshoot_page(&welcome_content_page_stack, &window);
community_page(&welcome_content_page_stack, &window);
contribute_page(&welcome_content_page_stack, &window);
}

View File

@ -4,13 +4,11 @@ use adw::*;
use duct::cmd;
use glib::*;
use serde::Deserialize;
use std::cell::RefCell;
use std::error::Error;
use std::fs;
use std::io::BufRead;
use std::io::BufReader;
use std::process::Command;
use std::rc::Rc;
use std::{thread, time};
#[allow(non_camel_case_types)]
@ -71,20 +69,7 @@ fn run_addon_command(
pub fn recommended_addons_page(
recommended_addons_content_page_stack: &gtk::Stack,
window: &adw::ApplicationWindow,
internet_connected: &Rc<RefCell<bool>>,
) {
let internet_connected_status = internet_connected.clone();
let (internet_loop_sender, internet_loop_receiver) = async_channel::unbounded();
let internet_loop_sender = internet_loop_sender.clone();
// The long running operation runs now in a separate thread
gio::spawn_blocking(move || loop {
thread::sleep(time::Duration::from_secs(1));
internet_loop_sender
.send_blocking(true)
.expect("The channel needs to be open.");
});
let recommended_addons_page_box = gtk::Box::builder().vexpand(true).hexpand(true).build();
let recommended_addons_page_listbox = gtk::ListBox::builder()
@ -107,20 +92,6 @@ pub fn recommended_addons_page(
.min_content_width(520)
.build();
let internet_loop_context = MainContext::default();
// The main loop executes the asynchronous block
internet_loop_context.spawn_local(
clone!(@strong internet_connected_status, @weak recommended_addons_page_box => async move {
while let Ok(_state) = internet_loop_receiver.recv().await {
if *internet_connected_status.borrow_mut() == true {
recommended_addons_page_box.set_sensitive(true);
} else {
recommended_addons_page_box.set_sensitive(false);
}
}
}),
);
let entry_buttons_size_group = gtk::SizeGroup::new(gtk::SizeGroupMode::Both);
let mut json_array: Vec<recommended_addons_entry> = Vec::new();

View File

@ -4,11 +4,8 @@ use adw::*;
use duct::cmd;
use glib::*;
use serde::Deserialize;
use std::cell::RefCell;
use std::fs;
use std::path::Path;
use std::rc::Rc;
use std::{thread, time};
#[allow(non_camel_case_types)]
#[derive(PartialEq, Debug, Eq, Hash, Clone, Ord, PartialOrd, Deserialize)]
@ -24,20 +21,7 @@ struct setup_steps_entry {
pub fn setup_steps_page(
setup_steps_content_page_stack: &gtk::Stack,
window: &adw::ApplicationWindow,
internet_connected: &Rc<RefCell<bool>>,
) {
let internet_connected_status = internet_connected.clone();
let (internet_loop_sender, internet_loop_receiver) = async_channel::unbounded();
let internet_loop_sender = internet_loop_sender.clone();
// The long running operation runs now in a separate thread
gio::spawn_blocking(move || loop {
thread::sleep(time::Duration::from_secs(1));
internet_loop_sender
.send_blocking(true)
.expect("The channel needs to be open.");
});
let setup_steps_page_box = gtk::Box::builder().vexpand(true).hexpand(true).build();
let setup_steps_page_listbox = gtk::ListBox::builder()
@ -60,20 +44,6 @@ pub fn setup_steps_page(
.min_content_width(520)
.build();
let internet_loop_context = MainContext::default();
// The main loop executes the asynchronous block
internet_loop_context.spawn_local(
clone!(@strong internet_connected_status, @weak setup_steps_page_box => async move {
while let Ok(_state) = internet_loop_receiver.recv().await {
if *internet_connected_status.borrow_mut() == true {
setup_steps_page_box.set_sensitive(true);
} else {
setup_steps_page_box.set_sensitive(false);
}
}
}),
);
let mut json_array: Vec<setup_steps_entry> = Vec::new();
let json_path = "/usr/share/pika-welcome/config/setup_steps.json";
let json_data = fs::read_to_string(json_path).expect("Unable to read json");

View File

@ -4,11 +4,8 @@ use adw::*;
use duct::cmd;
use glib::*;
use serde::Deserialize;
use std::cell::RefCell;
use std::fs;
use std::path::Path;
use std::rc::Rc;
use std::{thread, time};
#[allow(non_camel_case_types)]
#[derive(PartialEq, Debug, Eq, Hash, Clone, Ord, PartialOrd, Deserialize)]
@ -24,20 +21,7 @@ struct troubleshoot_entry {
pub fn troubleshoot_page(
troubleshoot_content_page_stack: &gtk::Stack,
window: &adw::ApplicationWindow,
internet_connected: &Rc<RefCell<bool>>,
) {
let internet_connected_status = internet_connected.clone();
let (internet_loop_sender, internet_loop_receiver) = async_channel::unbounded();
let internet_loop_sender = internet_loop_sender.clone();
// The long running operation runs now in a separate thread
gio::spawn_blocking(move || loop {
thread::sleep(time::Duration::from_secs(1));
internet_loop_sender
.send_blocking(true)
.expect("The channel needs to be open.");
});
let troubleshoot_page_box = gtk::Box::builder().vexpand(true).hexpand(true).build();
let troubleshoot_page_listbox = gtk::ListBox::builder()
@ -60,20 +44,6 @@ pub fn troubleshoot_page(
.min_content_width(520)
.build();
let internet_loop_context = MainContext::default();
// The main loop executes the asynchronous block
internet_loop_context.spawn_local(
clone!(@strong internet_connected_status, @weak troubleshoot_page_box => async move {
while let Ok(_state) = internet_loop_receiver.recv().await {
if *internet_connected_status.borrow_mut() == true {
troubleshoot_page_box.set_sensitive(true);
} else {
troubleshoot_page_box.set_sensitive(false);
}
}
}),
);
let mut json_array: Vec<troubleshoot_entry> = Vec::new();
let json_path = "/usr/share/pika-welcome/config/troubleshoot.json";
let json_data = fs::read_to_string(json_path).expect("Unable to read json");