From e3c1464a6737dc9547b9fb695a7e64ec513a7aa3 Mon Sep 17 00:00:00 2001 From: Jordan Petridis Date: Wed, 18 Oct 2017 02:34:59 +0300 Subject: [PATCH] Spawn a separate thread to update the db and dont freeze the gui. --- hammond-gtk/src/main.rs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/hammond-gtk/src/main.rs b/hammond-gtk/src/main.rs index a52b273..7e42c28 100644 --- a/hammond-gtk/src/main.rs +++ b/hammond-gtk/src/main.rs @@ -15,7 +15,9 @@ extern crate loggerv; use log::LogLevel; use diesel::prelude::*; use hammond_data::dbqueries; + use std::rc; +use std::thread; use gtk::prelude::*; use gio::ApplicationExt; @@ -209,11 +211,12 @@ fn build_ui() { home_button.connect_clicked(move |_| stack_clone.set_visible_child(&grid_clone)); let refresh_button: gtk::Button = header_build.get_object("refbutton").unwrap(); - // FIXME: This locks the ui atm. - // FIXME: it also leaks memmory. + // FIXME: There appears to be a memmory leak here. refresh_button.connect_clicked(move |_| { - let db = hammond_data::establish_connection(); - hammond_data::index_feed::index_loop(db, false).unwrap(); + thread::spawn(|| { + let db = hammond_data::establish_connection(); + hammond_data::index_feed::index_loop(db, false).unwrap(); + }); }); // let pd_model = create_and_fill_tree_store(&db, &builder);