RR: Internet Page!

This commit is contained in:
Ward from fusion-voyager-3 2024-02-03 00:07:41 +03:00
parent b115aab247
commit d48c2e1062
3 changed files with 69 additions and 4 deletions

View File

@ -13,6 +13,7 @@ use std::process::Command;
use std::cell::RefCell; use std::cell::RefCell;
use std::rc::Rc; use std::rc::Rc;
use std::borrow::Borrow as the_rc_borrow; use std::borrow::Borrow as the_rc_borrow;
use std::env;
pub fn internet_carousel(first_setup_carousel: &adw::Carousel, internet_connected: &Rc<RefCell<bool>>) { pub fn internet_carousel(first_setup_carousel: &adw::Carousel, internet_connected: &Rc<RefCell<bool>>) {
@ -85,6 +86,8 @@ pub fn internet_carousel(first_setup_carousel: &adw::Carousel, internet_connecte
.orientation(Orientation::Horizontal) .orientation(Orientation::Horizontal)
.halign(Align::Center) .halign(Align::Center)
.valign(Align::End) .valign(Align::End)
.vexpand(true)
.hexpand(true)
.hexpand(true) .hexpand(true)
.margin_end(15) .margin_end(15)
.margin_start(15) .margin_start(15)
@ -93,14 +96,37 @@ pub fn internet_carousel(first_setup_carousel: &adw::Carousel, internet_connecte
.spacing(80) .spacing(80)
.build(); .build();
let first_setup_internet_button_content_box = gtk::Box::builder()
.orientation(Orientation::Vertical)
.build();
let first_setup_internet_button_content_text = gtk::Label::builder()
.label("Set up a network connection and a proxy/VPN.")
.build();
let first_setup_internet_button_content = adw::ButtonContent::builder()
.label("Open Network Settings.")
.icon_name("network-wired")
.build();
let first_setup_internet_button = gtk::Button::builder()
.child(&first_setup_internet_button_content_box)
.halign(Align::Center)
.valign(Align::Center)
.build();
internet_buttons_box.append(&internet_skip_button); internet_buttons_box.append(&internet_skip_button);
internet_buttons_box.append(&internet_next_button); internet_buttons_box.append(&internet_next_button);
first_setup_internet_box.append(&first_setup_internet_box_text); first_setup_internet_button_content_box.append(&first_setup_internet_button_content);
first_setup_internet_box.append(&internet_buttons_box); first_setup_internet_button_content_box.append(&first_setup_internet_button_content_text);
first_setup_carousel.append(&first_setup_internet_box); first_setup_carousel.append(&first_setup_internet_box);
first_setup_internet_box.append(&first_setup_internet_box_text);
first_setup_internet_box.append(&first_setup_internet_button);
first_setup_internet_box.append(&internet_buttons_box);
let internet_connected_status = internet_connected.clone(); let internet_connected_status = internet_connected.clone();
let internet_loop_context = MainContext::default(); let internet_loop_context = MainContext::default();
@ -123,6 +149,20 @@ pub fn internet_carousel(first_setup_carousel: &adw::Carousel, internet_connecte
} }
})); }));
first_setup_internet_button.connect_clicked(move |_| {
let env_xdg_session_desktop = env::var("XDG_SESSION_DESKTOP").unwrap();
if env_xdg_session_desktop.contains("gnome") || env_xdg_session_desktop.contains("ubuntu") {
Command::new("gtk-launch")
.arg("gnome-network-panel.desktop")
.spawn()
.expect("gnome-control-center failed to start");
} else {
Command::new("nm-connection-editor")
.spawn()
.expect("nm-connection-editor failed to start");
}
});
internet_next_button.connect_clicked(clone!(@weak first_setup_carousel => move |_| { internet_next_button.connect_clicked(clone!(@weak first_setup_carousel => move |_| {
first_setup_carousel.scroll_to(&first_setup_carousel.nth_page(2), true); first_setup_carousel.scroll_to(&first_setup_carousel.nth_page(2), true);
})); }));

View File

@ -1,4 +1,5 @@
use std::cell::RefCell; use std::cell::RefCell;
use std::process::Command;
use std::rc::Rc; use std::rc::Rc;
// GTK crates // GTK crates
/// Use all gtk4 libraries (gtk4 -> gtk because cargo) /// Use all gtk4 libraries (gtk4 -> gtk because cargo)
@ -11,10 +12,22 @@ use adw::ffi::ADW_TOOLBAR_FLAT;
use glib::*; use glib::*;
use gdk::Display; use gdk::Display;
use std::{thread, time};
pub fn update_carousel(first_setup_carousel: &adw::Carousel, internet_connected: &Rc<RefCell<bool>>) { pub fn update_carousel(first_setup_carousel: &adw::Carousel, internet_connected: &Rc<RefCell<bool>>) {
let internet_connected_status = internet_connected.clone(); 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 first_setup_update_box = gtk::Box::builder() let first_setup_update_box = gtk::Box::builder()
// that puts items vertically // that puts items vertically
.orientation(Orientation::Vertical) .orientation(Orientation::Vertical)
@ -44,7 +57,19 @@ pub fn update_carousel(first_setup_carousel: &adw::Carousel, internet_connected:
first_setup_carousel.append(&first_setup_update_box); first_setup_carousel.append(&first_setup_update_box);
first_setup_start_button.connect_clicked(clone!(@weak first_setup_carousel => move |_| { let internet_loop_context = MainContext::default();
// The main loop executes the asynchronous block
internet_loop_context.spawn_local(clone!(@strong internet_connected_status, @weak first_setup_start_button => async move {
while let Ok(state) = internet_loop_receiver.recv().await {
if *internet_connected_status.borrow_mut() == true {
first_setup_start_button.set_label("true");
} else {
first_setup_start_button.set_label("false");
}
}
}));
first_setup_start_button.connect_clicked(clone!(@strong internet_connected_status, @weak first_setup_carousel => move |_| {
println!("{}", internet_connected_status.borrow_mut()); println!("{}", internet_connected_status.borrow_mut());
})); }));
} }

View File

@ -1 +1 @@
{"rustc_fingerprint":16368633458058699409,"outputs":{"4614504638168534921":{"success":true,"status":"","code":0,"stdout":"rustc 1.75.0 (82e1608df 2023-12-21)\nbinary: rustc\ncommit-hash: 82e1608dfa6e0b5569232559e3d385fea5a93112\ncommit-date: 2023-12-21\nhost: x86_64-unknown-linux-gnu\nrelease: 1.75.0\nLLVM version: 17.0.6\n","stderr":""},"14371922958718593042":{"success":true,"status":"","code":0,"stdout":"___\nlib___.rlib\nlib___.so\nlib___.so\nlib___.a\nlib___.so\n/home/ward/.rustup/toolchains/stable-x86_64-unknown-linux-gnu\noff\npacked\nunpacked\n___\ndebug_assertions\noverflow_checks\npanic=\"unwind\"\nproc_macro\nrelocation_model=\"pic\"\ntarget_abi=\"\"\ntarget_arch=\"x86_64\"\ntarget_endian=\"little\"\ntarget_env=\"gnu\"\ntarget_family=\"unix\"\ntarget_feature=\"fxsr\"\ntarget_feature=\"sse\"\ntarget_feature=\"sse2\"\ntarget_has_atomic\ntarget_has_atomic=\"16\"\ntarget_has_atomic=\"32\"\ntarget_has_atomic=\"64\"\ntarget_has_atomic=\"8\"\ntarget_has_atomic=\"ptr\"\ntarget_has_atomic_equal_alignment=\"16\"\ntarget_has_atomic_equal_alignment=\"32\"\ntarget_has_atomic_equal_alignment=\"64\"\ntarget_has_atomic_equal_alignment=\"8\"\ntarget_has_atomic_equal_alignment=\"ptr\"\ntarget_has_atomic_load_store\ntarget_has_atomic_load_store=\"16\"\ntarget_has_atomic_load_store=\"32\"\ntarget_has_atomic_load_store=\"64\"\ntarget_has_atomic_load_store=\"8\"\ntarget_has_atomic_load_store=\"ptr\"\ntarget_os=\"linux\"\ntarget_pointer_width=\"64\"\ntarget_thread_local\ntarget_vendor=\"unknown\"\nunix\n","stderr":""}},"successes":{}} {"rustc_fingerprint":11104695642277176061,"outputs":{"4614504638168534921":{"success":true,"status":"","code":0,"stdout":"rustc 1.75.0 (82e1608df 2023-12-21)\nbinary: rustc\ncommit-hash: 82e1608dfa6e0b5569232559e3d385fea5a93112\ncommit-date: 2023-12-21\nhost: x86_64-unknown-linux-gnu\nrelease: 1.75.0\nLLVM version: 17.0.6\n","stderr":""},"15729799797837862367":{"success":true,"status":"","code":0,"stdout":"___\nlib___.rlib\nlib___.so\nlib___.so\nlib___.a\nlib___.so\n/home/ward/.rustup/toolchains/stable-x86_64-unknown-linux-gnu\noff\npacked\nunpacked\n___\ndebug_assertions\npanic=\"unwind\"\nproc_macro\ntarget_arch=\"x86_64\"\ntarget_endian=\"little\"\ntarget_env=\"gnu\"\ntarget_family=\"unix\"\ntarget_feature=\"fxsr\"\ntarget_feature=\"sse\"\ntarget_feature=\"sse2\"\ntarget_has_atomic=\"16\"\ntarget_has_atomic=\"32\"\ntarget_has_atomic=\"64\"\ntarget_has_atomic=\"8\"\ntarget_has_atomic=\"ptr\"\ntarget_os=\"linux\"\ntarget_pointer_width=\"64\"\ntarget_vendor=\"unknown\"\nunix\n","stderr":""}},"successes":{}}