From 76766a4b4843bc77171389d69b5f12f8ec388c73 Mon Sep 17 00:00:00 2001 From: Ward from fusion-voyager-3 Date: Mon, 15 Jan 2024 21:20:01 +0300 Subject: [PATCH] bad :( --- Cargo.lock | 1 + Cargo.toml | 1 + src/build_ui.rs | 39 ++++++++++++++++++++++----------------- 3 files changed, 24 insertions(+), 17 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 61b3e88..67a54e7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -572,6 +572,7 @@ version = "0.1.0" dependencies = [ "async-channel", "fragile", + "glib", "gtk4", "libadwaita", "time", diff --git a/Cargo.toml b/Cargo.toml index 6e16d51..12f4384 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,5 +9,6 @@ edition = "2021" adw = { version = "0.5.3", package = "libadwaita" } async-channel = "2.1.1" fragile = "2.0.0" +glib = "0.18.5" gtk = { version = "0.7.3", package = "gtk4" } time = "0.3.31" diff --git a/src/build_ui.rs b/src/build_ui.rs index 6c193f7..33b8f46 100644 --- a/src/build_ui.rs +++ b/src/build_ui.rs @@ -139,25 +139,30 @@ pub fn build_ui(app: &adw::Application) { window.connect_hide(clone!(@weak window => move |_| save_window_size(&window, &glib_settings))); window.connect_hide(clone!(@weak window => move |_| window.destroy())); - window.show(); - - let bottom_box_clone = fragile::Fragile::new(bottom_box.clone()); - let content_stack_clone = fragile::Fragile::new(content_stack.clone()); - - gio::spawn_blocking(move || { - while gtk_loops == true { - glib::MainContext::default().invoke( move || { - bottom_box_loop( &bottom_box_clone, &content_stack_clone) - }); - } + let (sender, receiver) = MainContext::channel(Priority::default()); + window.connect_show(move |_| { + let sender = sender.clone(); + // The long running operation runs now in a separate thread + thread::spawn(move || { + sender.send(false).expect("Could not send through channel"); + }); }); + + window.show(); + + receiver.attach( + None, + clone!(@weak bottom_box => @default-return Continue(false), + move |state| { + bottom_box_loop(&bottom_box, state); + glib::ControlFlow::Continue + } + ), + + ); } -fn bottom_box_loop(bottom_box: &Fragile, content_stack: &Fragile) { - if content_stack.get().visible_child_name().expect("gstring to string").as_str() == "welcome_page" { - bottom_box.get().set_visible(false) - } else { - bottom_box.get().set_visible(true) - } +fn bottom_box_loop(bottom_box: >k::Box, state: bool) { + bottom_box.set_visible(state) } \ No newline at end of file