Skip to content

Commit

Permalink
wip - popup panels, passive settings storage, block dag viz improveme…
Browse files Browse the repository at this point in the history
…nts, metrics selection
  • Loading branch information
aspect committed Nov 27, 2023
1 parent 9fb534d commit 3573948
Show file tree
Hide file tree
Showing 35 changed files with 1,240 additions and 577 deletions.
23 changes: 12 additions & 11 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -93,27 +93,27 @@ kaspad = { path = "../rusty-kaspa/kaspad" }
# |_|_| |__| | \ | \_ | |___ |__| |_|_| | \ ___]
# _________________________________________________________

# workflow-chrome = "0.8.1"
# workflow-core = "0.8.1"
# workflow-dom = "0.8.1"
# workflow-http = "0.8.1"
# workflow-i18n = { version = "0.8.1", features = ["preserve-order"] }
# workflow-log = "0.8.1"
# workflow-store = "0.8.1"
# workflow-chrome = "0.9.0"
# workflow-dom = "0.9.0"
# workflow-http = "0.9.0"
# workflow-log = "0.9.0"
# workflow-store = "0.9.0"
# workflow-core = { version = "0.9.0", features = ["no-unsafe-eval"] }
# workflow-i18n = { version = "0.9.0", features = ["preserve-order"] }
workflow-chrome = { path = "../workflow-rs/chrome" }
workflow-core = { path = "../workflow-rs/core", features = ["no-unsafe-eval"] }
workflow-dom = { path = "../workflow-rs/dom" }
workflow-http = { path = "../workflow-rs/http" }
workflow-i18n = { path = "../workflow-rs/i18n", features = ["preserve-order"] }
workflow-log = { path = "../workflow-rs/log" }
workflow-store = { path = "../workflow-rs/store" }
workflow-core = { path = "../workflow-rs/core", features = ["no-unsafe-eval"] }
workflow-i18n = { path = "../workflow-rs/i18n", features = ["preserve-order"] }
# workflow-chrome = { git = "https://github.com/workflow-rs/workflow-rs.git", branch = "master" }
# workflow-core = { git = "https://github.com/workflow-rs/workflow-rs.git", branch = "master", features = ["no-unsafe-eval"] }
# workflow-dom = { git = "https://github.com/workflow-rs/workflow-rs.git", branch = "master" }
# workflow-http = { git = "https://github.com/workflow-rs/workflow-rs.git", branch = "master" }
# workflow-i18n = { git = "https://github.com/workflow-rs/workflow-rs.git", branch = "master", features = ["preserve-order"] }
# workflow-log = { git = "https://github.com/workflow-rs/workflow-rs.git", branch = "master" }
# workflow-store = { git = "https://github.com/workflow-rs/workflow-rs.git", branch = "master" }
# workflow-core = { git = "https://github.com/workflow-rs/workflow-rs.git", branch = "master", features = ["no-unsafe-eval"] }
# workflow-i18n = { git = "https://github.com/workflow-rs/workflow-rs.git", branch = "master", features = ["preserve-order"] }

# ----------------------------------------
# ----------------------------------------
Expand All @@ -135,6 +135,7 @@ futures = { version = "0.3" }
futures-util = { version = "0.3", default-features = false, features = ["alloc"] }
js-sys = "0.3.64"
log = "0.4"
nix = "0.27.1"
num_cpus = "1.15.0"
pad = "0.1.6"
qrcode = "0.12.0"
Expand Down
3 changes: 3 additions & 0 deletions core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ features = [


# -- native
[target.'cfg(unix)'.dependencies]
nix.workspace = true

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
clap.workspace = true
ctrlc.workspace = true
Expand Down
3 changes: 1 addition & 2 deletions core/src/app.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use crate::result::Result;
use cfg_if::cfg_if;
use egui::ViewportBuilder;
use kaspa_ng_core::runtime;
use kaspa_ng_core::settings::Settings;
use kaspa_wallet_core::api::WalletApi;
Expand Down Expand Up @@ -208,7 +207,7 @@ cfg_if! {
let delegate = runtime.clone();
let native_options = eframe::NativeOptions {
persist_window : true,
viewport: ViewportBuilder::default()
viewport: egui::ViewportBuilder::default()
.with_resizable(true)
.with_title(i18n("Kaspa NG"))
.with_inner_size([1000.0,600.0])
Expand Down
70 changes: 64 additions & 6 deletions core/src/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use egui_notify::Toasts;
use kaspa_metrics::MetricsSnapshot;
use kaspa_wallet_core::api::TransactionDataGetResponse;
use kaspa_wallet_core::events::Events as CoreWallet;
use kaspa_wallet_core::storage::{Binding, Hint};
use kaspa_wallet_core::storage::{Binding, Hint, PrvKeyDataInfo};
use std::borrow::Cow;
use workflow_i18n::*;

Expand Down Expand Up @@ -75,6 +75,10 @@ impl State {
}

pub struct Core {
is_shutdown_pending: bool,
settings_storage_requested: bool,
last_settings_storage_request: Instant,

runtime: Runtime,
wallet: Arc<dyn WalletApi>,
channel: ApplicationEventsChannel,
Expand All @@ -95,6 +99,7 @@ pub struct Core {

pub wallet_descriptor: Option<WalletDescriptor>,
pub wallet_list: Vec<WalletDescriptor>,
pub prv_key_data_map: HashMap<PrvKeyDataId, Arc<PrvKeyDataInfo>>,
pub account_collection: Option<AccountCollection>,
pub selected_account: Option<Account>,
}
Expand All @@ -113,7 +118,7 @@ impl Core {

// ---
fonts.font_data.insert(
"kng_mono".to_owned(),
"ubuntu_mono".to_owned(),
// egui::FontData::from_static(include_bytes!("../../resources/fonts/NotoSans-Regular.ttf")),
// egui::FontData::from_static(include_bytes!("../../resources/fonts/Open Sans.ttf")),
egui::FontData::from_static(include_bytes!(
Expand All @@ -131,7 +136,7 @@ impl Core {
.families
.entry(egui::FontFamily::Monospace)
.or_default()
.insert(0, "kng_mono".to_owned());
.insert(0, "ubuntu_mono".to_owned());

// ---

Expand Down Expand Up @@ -290,6 +295,9 @@ impl Core {

let mut this = Self {
runtime,
is_shutdown_pending: false,
settings_storage_requested: false,
last_settings_storage_request: Instant::now(),
wallet,
channel,
deactivation: None,
Expand All @@ -304,6 +312,7 @@ impl Core {

wallet_descriptor: None,
wallet_list: Vec::new(),
prv_key_data_map: HashMap::new(),
account_collection: None,
selected_account: None,

Expand Down Expand Up @@ -333,6 +342,8 @@ impl Core {
.expect("Unknown module");

if self.module.type_id() != module.type_id() {
// crate::egui::clear_popup_states();

let next = module.clone();
self.stack.push_back(self.module.clone());
self.deactivation = Some(self.module.clone());
Expand Down Expand Up @@ -369,6 +380,10 @@ impl Core {
self.channel.sender.clone()
}

pub fn store_settings(&self) {
self.channel.sender.try_send(Events::StoreSettings).unwrap();
}

pub fn wallet(&self) -> &Arc<dyn WalletApi> {
&self.wallet
}
Expand Down Expand Up @@ -415,9 +430,9 @@ impl Core {
}

impl eframe::App for Core {

#[cfg(not(target_arch = "wasm32"))]
fn on_exit(&mut self, _gl: Option<&eframe::glow::Context>) {
self.is_shutdown_pending = true;
crate::runtime::halt();
println!("{}", i18n("bye!"));
}
Expand All @@ -432,6 +447,17 @@ impl eframe::App for Core {
}
}

if self.is_shutdown_pending {
return;
}

if self.settings_storage_requested
&& self.last_settings_storage_request.elapsed() > Duration::from_secs(5)
{
self.settings_storage_requested = false;
self.settings.store_sync().unwrap();
}

// ctx.set_visuals(self.default_style.clone());
let mut current_visuals = ctx.style().visuals.clone(); //.widgets.noninteractive;
let mut visuals = current_visuals.clone();
Expand Down Expand Up @@ -616,8 +642,10 @@ impl Core {

cols[1].with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
let dictionary = i18n::dictionary();
// use egui_phosphor::light::TRANSLATE;
#[allow(clippy::useless_format)]
ui.menu_button(format!("{} ⏷", dictionary.current_title()), |ui| {
// ui.menu_button(RichText::new(format!("{TRANSLATE} ⏷")).size(18.), |ui| {
dictionary
.enabled_languages()
.into_iter()
Expand Down Expand Up @@ -906,13 +934,18 @@ impl Core {
_frame: &mut eframe::Frame,
) -> Result<()> {
match event {
Events::StoreSettings => {
self.settings_storage_requested = true;
self.last_settings_storage_request = Instant::now();
}
Events::UpdateLogs => {}
Events::Metrics { snapshot } => {
self.metrics = Some(snapshot);
}
Events::Exit => {
cfg_if! {
if #[cfg(not(target_arch = "wasm32"))] {
self.is_shutdown_pending = true;
_ctx.send_viewport_cmd(ViewportCommand::Close);
}
}
Expand Down Expand Up @@ -957,6 +990,11 @@ impl Core {
// self.select::<section::Account>();
}
Events::UnlockFailure { .. } => {}
Events::PrvKeyDataInfo {
prv_key_data_info_map,
} => {
self.prv_key_data_map = prv_key_data_info_map;
}
Events::Wallet { event } => {
match *event {
CoreWallet::UtxoProcStart => {
Expand Down Expand Up @@ -987,7 +1025,7 @@ impl Core {
self.state.url = None;
self.state.network_id = None;
self.state.current_daa_score = None;
self.metrics = None;
self.metrics = Some(Box::default());
}
CoreWallet::UtxoIndexNotEnabled { url } => {
self.exception = Some(Exception::UtxoIndexNotEnabled { url });
Expand Down Expand Up @@ -1021,7 +1059,11 @@ impl Core {
self.state.is_open = true;

self.wallet_descriptor = wallet_descriptor;
let network_id = self.state.network_id.ok_or(Error::WalletOpenNetworkId)?;
// let network_id = self.state.network_id.ok_or(Error::WalletOpenNetworkId)?;
let network_id = self
.state
.network_id
.unwrap_or(self.settings.node.network.into());
let account_descriptors =
account_descriptors.ok_or(Error::WalletOpenAccountDescriptors)?;
self.load_accounts(network_id, account_descriptors)?;
Expand Down Expand Up @@ -1170,6 +1212,8 @@ impl Core {
network_id: NetworkId,
account_descriptors: Vec<AccountDescriptor>,
) -> Result<()> {
let application_events_sender = self.channel.sender.clone();

let account_list = account_descriptors
.into_iter()
.map(Account::from)
Expand All @@ -1179,6 +1223,20 @@ impl Core {

let runtime = self.runtime.clone();
spawn(async move {
let prv_key_data_info_map = runtime
.wallet()
.prv_key_data_enumerate()
.await?
.clone()
.into_iter()
.map(|prv_key_data_info| (*prv_key_data_info.id(), prv_key_data_info))
.collect::<HashMap<_, _>>();
application_events_sender
.send(Events::PrvKeyDataInfo {
prv_key_data_info_map,
})
.await?;

let account_ids = account_list
.iter()
.map(|account| account.id())
Expand Down
10 changes: 10 additions & 0 deletions core/src/egui/extensions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -269,3 +269,13 @@ where
response
}
}

pub trait WidgetSpacerExtension {
fn space(&mut self);
}

impl WidgetSpacerExtension for Ui {
fn space(&mut self) {
self.add_space(theme().widget_spacing);
}
}
24 changes: 15 additions & 9 deletions core/src/egui/mod.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
pub mod button;
pub mod compositebutton;
pub mod compositegraph;
pub mod compositeicon;
pub mod easy_mark;
pub mod extensions;
pub mod icon;
pub mod network;
pub mod theme;
// mod button;
mod compositebutton;
mod compositegraph;
mod compositeicon;
mod easy_mark;
mod extensions;
mod icon;
mod network;
mod popup;
mod theme;

pub use compositebutton::CompositeButton;
pub use compositegraph::CompositeGraph;
pub use compositeicon::CompositeIcon;
pub use easy_mark::easy_mark;
pub use extensions::*;
pub use icon::{icons, Icon, IconSize, Icons};
pub use network::NetworkInterfaceEditor;
pub use popup::PopupPanel;
pub use theme::*;
Loading

0 comments on commit 3573948

Please sign in to comment.