wip
This commit is contained in:
Generated
+459
-206
File diff suppressed because it is too large
Load Diff
+7
-4
@@ -42,7 +42,9 @@ spmc = "0.3.0"
|
|||||||
thread-priority = "1.2.0"
|
thread-priority = "1.2.0"
|
||||||
|
|
||||||
# Optional dependencies regulated by features
|
# Optional dependencies regulated by features
|
||||||
web-view = { git = "https://github.com/Boscop/web-view", features = [], optional = true }
|
# web-view = { git = "https://github.com/Boscop/web-view", features = [], optional = true }
|
||||||
|
gtk = { package = "gtk4", version = "0.9.6", features = ["v4_16"], optional = true }
|
||||||
|
adw = { version = "0.7.2", package = "libadwaita", features = ["v1_5"], optional = true }
|
||||||
tinyfiledialogs = { version = "3.9.1", optional = true }
|
tinyfiledialogs = { version = "3.9.1", optional = true }
|
||||||
open = { version = "5.3.0", optional = true }
|
open = { version = "5.3.0", optional = true }
|
||||||
|
|
||||||
@@ -69,7 +71,8 @@ ProductName="ALFIS"
|
|||||||
FileDescription="Alternative Free Identity System"
|
FileDescription="Alternative Free Identity System"
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
webgui = ["web-view", "tinyfiledialogs", "open"]
|
gui = ["gtk", "adw"]
|
||||||
edge = ["webgui", "web-view/edge"]
|
# webgui = ["web-view", "tinyfiledialogs", "open"]
|
||||||
|
# edge = ["webgui", "web-view/edge"]
|
||||||
doh = ["ureq"]
|
doh = ["ureq"]
|
||||||
default = ["webgui", "doh"]
|
default = ["gui", "doh"]
|
||||||
|
|||||||
+7
-5
@@ -29,8 +29,9 @@ use alfis::{dns_utils, Block, Bytes, Chain, Context, Keystore, Miner, Network, S
|
|||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
use crate::win_service::start_service;
|
use crate::win_service::start_service;
|
||||||
|
|
||||||
#[cfg(feature = "webgui")]
|
// #[cfg(feature = "webgui")]
|
||||||
mod web_ui;
|
// mod web_ui;
|
||||||
|
mod ui;
|
||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
mod win_service;
|
mod win_service;
|
||||||
|
|
||||||
@@ -142,7 +143,7 @@ fn main() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
let mut no_gui = opt_matches.opt_present("n");
|
let mut no_gui = opt_matches.opt_present("n");
|
||||||
if !cfg!(feature = "webgui")
|
if !cfg!(feature = "gui")
|
||||||
{
|
{
|
||||||
no_gui = true;
|
no_gui = true;
|
||||||
}
|
}
|
||||||
@@ -250,8 +251,9 @@ fn main() {
|
|||||||
post(Event::Error { text: String::from("Error starting DNS-server. Please, check that it’s port is not busy.") });
|
post(Event::Error { text: String::from("Error starting DNS-server. Please, check that it’s port is not busy.") });
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
#[cfg(feature = "webgui")]
|
// #[cfg(feature = "webgui")]
|
||||||
web_ui::run_interface(Arc::clone(&context), miner);
|
// web_ui::run_interface(Arc::clone(&context), miner);
|
||||||
|
ui::run_ui(Arc::clone(&context), miner);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Without explicitly detaching the console cmd won't redraw it's prompt.
|
// Without explicitly detaching the console cmd won't redraw it's prompt.
|
||||||
|
|||||||
+160
@@ -0,0 +1,160 @@
|
|||||||
|
#[warn(unused_imports)]
|
||||||
|
use alfis::{
|
||||||
|
blockchain::{
|
||||||
|
transaction::DomainData,
|
||||||
|
types::MineResult
|
||||||
|
},
|
||||||
|
commons::*,
|
||||||
|
crypto::CryptoBox,
|
||||||
|
dns::protocol::DnsRecord,
|
||||||
|
event::Event,
|
||||||
|
eventbus::{post, register},
|
||||||
|
miner::Miner,
|
||||||
|
keystore, Block, Bytes, Context, Keystore, Transaction
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
use std::{
|
||||||
|
sync::{Arc, Mutex, MutexGuard},
|
||||||
|
thread,
|
||||||
|
time::{Duration, Instant}
|
||||||
|
};
|
||||||
|
|
||||||
|
use gtk::prelude::*;
|
||||||
|
use gtk::{
|
||||||
|
glib,
|
||||||
|
ApplicationWindow,
|
||||||
|
Button,
|
||||||
|
Label,
|
||||||
|
HeaderBar,
|
||||||
|
Box,
|
||||||
|
Orientation,
|
||||||
|
Notebook,
|
||||||
|
Entry,
|
||||||
|
FileDialog
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// pub use run_ui;
|
||||||
|
|
||||||
|
#[warn(unused_variables)]
|
||||||
|
pub fn run_ui(context: Arc<Mutex<Context>>, miner: Arc<Mutex<Miner>>) -> glib::ExitCode {
|
||||||
|
let application = adw::Application::builder()
|
||||||
|
.application_id("ru.Revertron.Alfis")
|
||||||
|
.build();
|
||||||
|
|
||||||
|
let context = context.clone();
|
||||||
|
application.connect_activate(move |app| {
|
||||||
|
let window = ApplicationWindow::builder()
|
||||||
|
.application(app)
|
||||||
|
.title(format!("ALFIS {}", env!("CARGO_PKG_VERSION")))
|
||||||
|
.default_width(1023)
|
||||||
|
.default_height(720)
|
||||||
|
.resizable(false)
|
||||||
|
// .show_menubar(true)
|
||||||
|
.build();
|
||||||
|
let ab = HeaderBar::new();
|
||||||
|
// ab.pack_start(&Label::new(Some("Application name")));
|
||||||
|
window.set_titlebar(Some(&ab));
|
||||||
|
|
||||||
|
let nb = Notebook::new();
|
||||||
|
window.set_child(Some(&nb));
|
||||||
|
|
||||||
|
let main = Box::new(Orientation::Vertical, 5);
|
||||||
|
// main.set_hexpand(true);
|
||||||
|
menu_credentials(&window, &main, &context);
|
||||||
|
|
||||||
|
|
||||||
|
nb.append_page(&main, Some(&Label::new(Some("Credentials"))));
|
||||||
|
|
||||||
|
|
||||||
|
// window.set_child(Some(&main));
|
||||||
|
window.present();
|
||||||
|
});
|
||||||
|
|
||||||
|
application.run()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn menu_credentials(window: &ApplicationWindow, parent: >k::Box, context: &Arc<Mutex<Context>>) {
|
||||||
|
let keys = Box::new(Orientation::Horizontal, 8);
|
||||||
|
keys.set_hexpand(true);
|
||||||
|
parent.append(&keys);
|
||||||
|
|
||||||
|
let key_hash = Entry::builder()
|
||||||
|
.placeholder_text("No key loaded")
|
||||||
|
.editable(false)
|
||||||
|
.tooltip_text("If you load or mine a keypair the public key will be displayed here")
|
||||||
|
.hexpand(true)
|
||||||
|
.focusable(false)
|
||||||
|
.build();
|
||||||
|
keys.append(&key_hash);
|
||||||
|
|
||||||
|
let load_btn = Button::with_label("Load key");
|
||||||
|
|
||||||
|
let window = window.clone();
|
||||||
|
let context = context.clone();
|
||||||
|
load_btn.connect_clicked(move |_| { open_file(&window, &context); });
|
||||||
|
keys.append(&load_btn);
|
||||||
|
|
||||||
|
let save_btn = Button::builder()
|
||||||
|
.label("Save key")
|
||||||
|
.sensitive(false)
|
||||||
|
.build();
|
||||||
|
keys.append(&save_btn);
|
||||||
|
|
||||||
|
let mine_btn = Button::with_label("Mine new key");
|
||||||
|
mine_btn.add_css_class("suggested-action");
|
||||||
|
keys.append(&mine_btn);
|
||||||
|
|
||||||
|
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<Mutex<Context>>) {
|
||||||
|
let filter = gtk::FileFilter::new();
|
||||||
|
filter.add_pattern("*.key");
|
||||||
|
filter.add_pattern("*.toml");
|
||||||
|
filter.set_name(Some("Key files"));
|
||||||
|
|
||||||
|
let fc = FileDialog::builder()
|
||||||
|
.title("Select key")
|
||||||
|
.default_filter(&filter)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
// let window = window.clone();
|
||||||
|
let context = context.clone();
|
||||||
|
fc.open(Some(window), None::<gtk::gio::Cancellable>.as_ref(), move |result| {
|
||||||
|
match result {
|
||||||
|
Ok(file) => {
|
||||||
|
match Keystore::from_file(file.path().unwrap().to_str().unwrap(), "") {
|
||||||
|
None => {
|
||||||
|
todo!("Setup error messages");
|
||||||
|
// error!("Error loading keystore '{}'!", &file_name);
|
||||||
|
// show_warning(web_view, "Error loading key!<br>Key cannot be loaded or its difficulty is not enough.");
|
||||||
|
// event_fail(web_view, &format!("Error loading key from \\'{}\\'!", &file_name));
|
||||||
|
}
|
||||||
|
Some(keystore) => {
|
||||||
|
// todo!("Setup info messages");
|
||||||
|
// info!("Loaded keystore with keys: {:?}, {:?}", &keystore.get_public(), &keystore.get_encryption_public());
|
||||||
|
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 });
|
||||||
|
|
||||||
|
if !context.lock().unwrap().select_key_by_public(&keystore.get_public()) {
|
||||||
|
context.lock().unwrap().add_keystore(keystore);
|
||||||
|
} else {
|
||||||
|
todo!();
|
||||||
|
// warn!("This key is already loaded!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(e) => {
|
||||||
|
if !e.matches(gtk::gio::IOErrorEnum::Cancelled) {
|
||||||
|
eprintln!("Error selecting file: {}", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user