diff --git a/src/ui/mod.rs b/src/ui/mod.rs index 81619e4..28d4361 100644 --- a/src/ui/mod.rs +++ b/src/ui/mod.rs @@ -17,7 +17,8 @@ use alfis::{ use std::{ sync::{Arc, Mutex, MutexGuard}, thread, - time::{Duration, Instant} + time::{Duration, Instant}, + rc::Rc, cell::RefCell }; use gtk::prelude::*; @@ -34,6 +35,17 @@ use gtk::{ FileDialog }; +// use glib::{Sender, Receiver, MainContext, PRIORITY_DEFAULT}; + + +#[derive(Clone, Debug)] +pub struct KeyData { + pub path: String, + pub public: String, + pub hash: String, +} +// static mut KEY_DATA: KeyData = KeyData { path: String::new(), public: String::new(), hash: String::new() }; +// let (sender, receiver) = MainContext::channel(PRIORITY_DEFAULT); // pub use run_ui; @@ -77,6 +89,7 @@ pub fn run_ui(context: Arc>, miner: Arc>) -> glib::E } fn menu_credentials(window: &ApplicationWindow, parent: >k::Box, context: &Arc>) { + let key_data = Rc::new(RefCell::from(KeyData{hash: String::new(), path: String::new(), public: String::new()})); let keys = Box::new(Orientation::Horizontal, 8); keys.set_hexpand(true); parent.append(&keys); @@ -94,7 +107,10 @@ fn menu_credentials(window: &ApplicationWindow, parent: >k::Box, context: &Arc let window = window.clone(); let context = context.clone(); - load_btn.connect_clicked(move |_| { open_file(&window, &context); }); + load_btn.connect_clicked(move |_| { + open_file(&window, &context, key_data.clone()); + key_hash.set_text(key_data.borrow().public.as_str()); + }); keys.append(&load_btn); let save_btn = Button::builder() @@ -110,7 +126,7 @@ fn menu_credentials(window: &ApplicationWindow, parent: >k::Box, context: &Arc parent.append(&Label::new(Some("To mine domains you need a strong pair of signing keys and a pair of ecryption keys."))); } -fn open_file(window: &ApplicationWindow, context: &Arc>) { +fn open_file(window: &ApplicationWindow, context: &Arc>, keydata: Rc>) { let filter = gtk::FileFilter::new(); filter.add_pattern("*.key"); filter.add_pattern("*.toml"); @@ -128,8 +144,8 @@ fn open_file(window: &ApplicationWindow, context: &Arc>) { Ok(file) => { match Keystore::from_file(file.path().unwrap().to_str().unwrap(), "") { None => { - todo!("Setup error messages"); - // error!("Error loading keystore '{}'!", &file_name); + // todo!("Setup error messages"); + /*error*/eprintln!("Error loading keystore '{}'!", &file.path().unwrap().to_str().unwrap()); // show_warning(web_view, "Error loading key!
Key cannot be loaded or its difficulty is not enough."); // event_fail(web_view, &format!("Error loading key from \\'{}\\'!", &file_name)); } @@ -139,7 +155,13 @@ fn open_file(window: &ApplicationWindow, context: &Arc>) { let path = keystore.get_path().to_owned(); let public = keystore.get_public().to_string(); let hash = keystore.get_hash().to_string(); - post(Event::KeyLoaded { path, public, hash }); + eprintln!("Key: {}, {}, {}", path, public, hash); + // post(Event::KeyLoaded { path, public, hash }); + + let key_data = KeyData { path, public, hash }; + keydata.replace(key_data); + // let (sender, _) = MainContext:: ::channel(PRIORITY_DEFAULT); + // sender.send(key_data).expect("Failed to send key data to UI"); if !context.lock().unwrap().select_key_by_public(&keystore.get_public()) { context.lock().unwrap().add_keystore(keystore);