This commit is contained in:
2025-09-30 23:51:12 +03:00
parent 9b1dc672a9
commit 6240208c17
4 changed files with 633 additions and 215 deletions
Generated
+459 -206
View File
File diff suppressed because it is too large Load Diff
+7 -4
View File
@@ -42,7 +42,9 @@ spmc = "0.3.0"
thread-priority = "1.2.0"
# 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 }
open = { version = "5.3.0", optional = true }
@@ -69,7 +71,8 @@ ProductName="ALFIS"
FileDescription="Alternative Free Identity System"
[features]
webgui = ["web-view", "tinyfiledialogs", "open"]
edge = ["webgui", "web-view/edge"]
gui = ["gtk", "adw"]
# webgui = ["web-view", "tinyfiledialogs", "open"]
# edge = ["webgui", "web-view/edge"]
doh = ["ureq"]
default = ["webgui", "doh"]
default = ["gui", "doh"]
+7 -5
View File
@@ -29,8 +29,9 @@ use alfis::{dns_utils, Block, Bytes, Chain, Context, Keystore, Miner, Network, S
#[cfg(windows)]
use crate::win_service::start_service;
#[cfg(feature = "webgui")]
mod web_ui;
// #[cfg(feature = "webgui")]
// mod web_ui;
mod ui;
#[cfg(windows)]
mod win_service;
@@ -142,7 +143,7 @@ fn main() {
};
let mut no_gui = opt_matches.opt_present("n");
if !cfg!(feature = "webgui")
if !cfg!(feature = "gui")
{
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.") });
});
}
#[cfg(feature = "webgui")]
web_ui::run_interface(Arc::clone(&context), miner);
// #[cfg(feature = "webgui")]
// 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.
+160
View File
@@ -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: &gtk::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);
}
}
}
});
}