From 52c0a75a89897c0471119c9b81660edc6a798fc6 Mon Sep 17 00:00:00 2001 From: Nathan Reiner Date: Wed, 26 Jul 2023 23:28:18 +0200 Subject: add spinner to loading view --- src/gui/load.rs | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) (limited to 'src/gui') diff --git a/src/gui/load.rs b/src/gui/load.rs index e075d0f..618f9dd 100644 --- a/src/gui/load.rs +++ b/src/gui/load.rs @@ -2,6 +2,7 @@ use gtk::glib; use gtk::prelude::*; use super::state::{View, ViewManager}; use std::rc::Rc; +use std::thread; use crate::index::Index; @@ -40,13 +41,30 @@ impl View for Load { splash.set_position(gtk::WindowPosition::Center); splash.set_resizable(false); splash.set_size_request(300, 200); - splash.add(>k::Label::new(Some("Loading"))); + + let container = gtk::Box::new(gtk::Orientation::Vertical, 0); + let spinner = gtk::Spinner::builder().active(true).build(); + + container.pack_start(>k::Label::new(Some("Loading")), false, false, 50); + container.pack_start(&spinner, false, true, 0); + + splash.add(&container); splash.show_all(); + + let (tx, rx) = glib::MainContext::channel(glib::Priority::default()); let path = uri.trim_start_matches("file://").to_string(); - let index = Index::from_file(&path); - vm.set_index(index); - vm.set_current_view("search"); - splash.close(); + + thread::spawn(move || { + let index = Index::from_file(&path); + tx.send(index).ok(); + }); + + rx.attach(None, move |index| { + vm.set_index(index); + vm.set_current_view("search"); + splash.close(); + glib::Continue(false) + }); } else { vm.set_current_view("welcome"); } -- cgit v1.2.3-70-g09d2