From 6c68564a778a22b10a30c913ba90f14b9f7ba361 Mon Sep 17 00:00:00 2001 From: Savanni D'Gerinel Date: Tue, 30 Jan 2024 08:46:10 -0500 Subject: [PATCH] Create a function which safely initializes GTK once This is only available in test code, and it allows GUI component tests to run without having to worry about double-initializing GTK --- fitnesstrax/app/src/gtk_init.rs | 10 ++++++++++ fitnesstrax/app/src/main.rs | 2 ++ 2 files changed, 12 insertions(+) create mode 100644 fitnesstrax/app/src/gtk_init.rs diff --git a/fitnesstrax/app/src/gtk_init.rs b/fitnesstrax/app/src/gtk_init.rs new file mode 100644 index 0000000..2ac6662 --- /dev/null +++ b/fitnesstrax/app/src/gtk_init.rs @@ -0,0 +1,10 @@ +use std::sync::Once; + +static INITIALIZED: Once = Once::new(); + +pub fn gtk_init() { + INITIALIZED.call_once(|| { + eprintln!("initializing GTK"); + let _ = gtk::init(); + }); +} diff --git a/fitnesstrax/app/src/main.rs b/fitnesstrax/app/src/main.rs index 1e86d60..316bfa6 100644 --- a/fitnesstrax/app/src/main.rs +++ b/fitnesstrax/app/src/main.rs @@ -17,6 +17,8 @@ You should have received a copy of the GNU General Public License along with Fit mod app; mod app_window; mod components; +#[cfg(test)] +mod gtk_init; mod types; mod view_models; mod views;