Skip to content

Commit

Permalink
egui 0.24 update
Browse files Browse the repository at this point in the history
  • Loading branch information
aspect committed Nov 25, 2023
1 parent 9bb8637 commit 9fb534d
Show file tree
Hide file tree
Showing 17 changed files with 697 additions and 298 deletions.
13 changes: 7 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,17 @@ kaspa-ng-macros = { version = "0.1.0", path = "macros/" }
# |___ |__] |__| |
# ___________________

egui = "0.23.0"
egui_plot = "0.23.0"
egui_extras = { version = "0.23.0", features = ["svg","image"] }
eframe = { version = "0.23.0", default-features = false, features = [
egui = "0.24.0"
egui_plot = "0.24.0"
egui_extras = { version = "0.24.0", features = ["svg","image"] }
eframe = { version = "0.24.0", default-features = false, features = [
"accesskit", # Make egui comptaible with screen readers. NOTE: adds a lot of dependencies.
"default_fonts", # Embed the default egui fonts.
"glow", # Use the glow rendering backend. Alternative: "wgpu".
"persistence", # Enable restoring app state when restarting the app.
] }
egui-phosphor = { version = "0.3.0", features = ["thin","light","regular","bold"] }
egui-notify = "0.10.0"
egui-phosphor = { version = "0.3.1", features = ["thin","light","regular","bold"] }
egui-notify = "0.11.0"
# egui-toast = "0.9.0"

# egui = { path = "../egui/crates/egui" }
Expand Down Expand Up @@ -140,6 +140,7 @@ pad = "0.1.6"
qrcode = "0.12.0"
rand = "0.8"
ritehash = "0.2.0"
rlimit = "0.10.1"
separator = "0.4.1"
serde = { version = "1", features = ["derive"] }
serde_json = "1.0.107"
Expand Down
1 change: 1 addition & 0 deletions core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ kaspa-rpc-service.workspace = true
kaspa-wrpc-server.workspace = true
kaspad.workspace = true
num_cpus.workspace = true
rlimit.workspace = true
sysinfo.workspace = true
tokio.workspace = true

Expand Down
48 changes: 43 additions & 5 deletions core/src/app.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
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 All @@ -22,7 +23,7 @@ pub const RUSTC_LLVM_VERSION: &str = env!("VERGEN_RUSTC_LLVM_VERSION");
pub const RUSTC_SEMVER: &str = env!("VERGEN_RUSTC_SEMVER");
pub const CARGO_TARGET_TRIPLE: &str = env!("VERGEN_CARGO_TARGET_TRIPLE");
// pub const CARGO_PROFILE: &str = env!("VERGEN_CARGO_PROFILE");
pub const CODENAME: &str = "This is the way";
pub const CODENAME: &str = "DNA";

cfg_if! {
if #[cfg(not(target_arch = "wasm32"))] {
Expand All @@ -32,7 +33,6 @@ cfg_if! {
use kaspa_utils::fd_budget;
use kaspa_core::signals::Signals;
use clap::ArgAction;
use eframe::IconData;
use crate::utils::*;
use std::fs;

Expand Down Expand Up @@ -122,6 +122,29 @@ cfg_if! {

runtime::panic::init_panic_handler();

// TODO - import from kaspad_lib
const DESIRED_DAEMON_SOFT_FD_LIMIT: u64 = 16 * 1024;
const MINIMUM_DAEMON_SOFT_FD_LIMIT: u64 = 4 * 1024;
match try_set_fd_limit(DESIRED_DAEMON_SOFT_FD_LIMIT) {
Ok(limit) => {
if limit < MINIMUM_DAEMON_SOFT_FD_LIMIT {
println!();
println!("| Current OS file descriptor limit (soft FD limit) is set to {limit}");
println!("| The kaspad node requires a setting of at least {DESIRED_DAEMON_SOFT_FD_LIMIT} to operate properly.");
println!("| Please increase the limits using the following command:");
println!("| ulimit -n {DESIRED_DAEMON_SOFT_FD_LIMIT}");
println!();
}
}
Err(err) => {
println!();
println!("| Unable to initialize the necessary OS file descriptor limit (soft FD limit) to: {}", err);
println!("| The kaspad node requires a setting of at least {DESIRED_DAEMON_SOFT_FD_LIMIT} to operate properly.");
println!();
}
}


match parse_args() {
Args::Cli => {
use kaspa_cli_lib::*;
Expand Down Expand Up @@ -150,6 +173,8 @@ cfg_if! {
// Log to stderr (if you run with `RUST_LOG=debug`).
env_logger::init();

set_log_level(LevelFilter::Info);

let mut settings = if reset_settings {
println!("Resetting kaspa-ng settings on user request...");
Settings::default().store_sync()?.clone()
Expand Down Expand Up @@ -182,10 +207,12 @@ cfg_if! {
let runtime: Arc<Mutex<Option<runtime::Runtime>>> = Arc::new(Mutex::new(None));
let delegate = runtime.clone();
let native_options = eframe::NativeOptions {
icon_data : IconData::try_from_png_bytes(KASPA_NG_ICON_256X256).ok(),
persist_window : true,
initial_window_size : Some(egui::Vec2 { x : 1000.0, y : 600.0 }),
// min_window_size : Some(egui::Vec2 { x : 1000.0, y : 600.0 }),
viewport: ViewportBuilder::default()
.with_resizable(true)
.with_title(i18n("Kaspa NG"))
.with_inner_size([1000.0,600.0])
.with_icon(eframe::icon_data::from_png_bytes(KASPA_NG_ICON_256X256).unwrap()),
..Default::default()
};
eframe::run_native(
Expand Down Expand Up @@ -320,3 +347,14 @@ cfg_if! {
}
}
}

#[cfg(not(target_arch = "wasm32"))]
pub fn try_set_fd_limit(limit: u64) -> std::io::Result<u64> {
cfg_if::cfg_if! {
if #[cfg(target_os = "windows")] {
Ok(rlimit::setmaxstdio(limit as u32)?.map(|v| v as u64))
} else if #[cfg(unix)] {
rlimit::increase_nofile_limit(limit)
}
}
}
53 changes: 42 additions & 11 deletions core/src/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ pub struct Core {
discard_hint: bool,
exception: Option<Exception>,

pub wallet_descriptor: Option<WalletDescriptor>,
pub wallet_list: Vec<WalletDescriptor>,
pub account_collection: Option<AccountCollection>,
pub selected_account: Option<Account>,
Expand Down Expand Up @@ -301,6 +302,7 @@ impl Core {
default_style,
large_style,

wallet_descriptor: None,
wallet_list: Vec::new(),
account_collection: None,
selected_account: None,
Expand Down Expand Up @@ -413,10 +415,6 @@ impl Core {
}

impl eframe::App for Core {
#[cfg(not(target_arch = "wasm32"))]
fn on_close_event(&mut self) -> bool {
true
}

#[cfg(not(target_arch = "wasm32"))]
fn on_exit(&mut self, _gl: Option<&eframe::glow::Context>) {
Expand Down Expand Up @@ -528,7 +526,7 @@ impl Core {
ui.menu_button("File", |ui| {
#[cfg(not(target_arch = "wasm32"))]
if ui.button("Quit").clicked() {
_frame.close();
ui.ctx().send_viewport_cmd(ViewportCommand::Close)
}
ui.separator();
ui.label(" ~ Debug Modules ~");
Expand Down Expand Up @@ -698,8 +696,6 @@ impl Core {
});
}

self.module.status_bar(ui);

ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
if icons()
.sliders
Expand Down Expand Up @@ -811,6 +807,9 @@ impl Core {
ui.label("Starting...");
}
}

self.module.status_bar(ui);

// if self.settings.node.node_kind != KaspadNodeKind::Disable {
// ui.label("Not Connected");

Expand Down Expand Up @@ -858,6 +857,8 @@ impl Core {
ui.separator();
ui.label(format!("DAA {}", current_daa_score.separated_string()));
}

self.module.status_bar(ui);
}
Status::Syncing { sync_status, peers } => {
ui.vertical(|ui| {
Expand All @@ -882,6 +883,8 @@ impl Core {
status.render_text_state(ui);
}
}

self.module.status_bar(ui);
});

if let Some(status) = sync_status.as_ref() {
Expand All @@ -908,14 +911,15 @@ impl Core {
self.metrics = Some(snapshot);
}
Events::Exit => {
// println!("bye!");
cfg_if! {
if #[cfg(not(target_arch = "wasm32"))] {
_frame.close();
_ctx.send_viewport_cmd(ViewportCommand::Close);
}
}
}
Events::Error(_error) => {}
Events::Error(error) => {
runtime().notify(UserNotification::error(error.as_str()));
}
Events::WalletList { wallet_list } => {
// println!("getting wallet list!, {:?}", wallet_list);
self.wallet_list = (*wallet_list).clone();
Expand All @@ -935,7 +939,9 @@ impl Core {
// // .map(|account| (account.id(), account)).collect::<HashMap::<_,_>>()
// // );
// }
Events::Notify { notification } => {
Events::Notify {
user_notification: notification,
} => {
notification.render(&mut self.toasts);
}
Events::Close { .. } => {}
Expand Down Expand Up @@ -1005,13 +1011,16 @@ impl Core {
self.discard_hint = false;
}
CoreWallet::WalletOpen {
wallet_descriptor,
account_descriptors,
}
| CoreWallet::WalletReload {
wallet_descriptor,
account_descriptors,
} => {
self.state.is_open = true;

self.wallet_descriptor = wallet_descriptor;
let network_id = self.state.network_id.ok_or(Error::WalletOpenNetworkId)?;
let account_descriptors =
account_descriptors.ok_or(Error::WalletOpenAccountDescriptors)?;
Expand All @@ -1021,6 +1030,23 @@ impl Core {
CoreWallet::AccountActivation { ids: _ } => {
// TODO
}
CoreWallet::AccountCreation { descriptor } => {
if let Some(account_collection) = self.account_collection.as_mut() {
account_collection.push(Account::from(descriptor));
runtime().request_repaint();
// if let Some(account) = account_collection.get(account_id) {
// account.update(descriptor);
// }
}
}
CoreWallet::AccountUpdate { descriptor } => {
let account_id = descriptor.account_id();
if let Some(account_collection) = self.account_collection.as_ref() {
if let Some(account) = account_collection.get(account_id) {
account.update(descriptor);
}
}
}
CoreWallet::WalletError { message: _ } => {
// self.state.is_open = false;
}
Expand All @@ -1029,6 +1055,11 @@ impl Core {
self.hint = None;
self.state.is_open = false;
self.account_collection = None;
self.wallet_descriptor = None;

self.modules.clone().into_iter().for_each(|(_, module)| {
module.reset(self);
});
}
CoreWallet::AccountSelection { id: _ } => {
// self.selected_account = self.wallet().account().ok();
Expand Down
13 changes: 1 addition & 12 deletions core/src/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,16 @@ pub enum Events {
WalletList {
wallet_list: Arc<Vec<WalletDescriptor>>,
},
// AccountList {
// // account_list: Arc<Vec<Arc<dyn runtime::Account>>>,
// account_list: Box<Vec<Account>>,
// },
Wallet {
event: Box<kaspa::Events>,
},
// TryUnlock(Secret),
UnlockSuccess,
UnlockFailure {
message: String,
},
Notify {
notification: UserNotification,
user_notification: UserNotification,
},
Close,
// Send,
// Deposit,
// Overview,
// Transactions,
// Accounts,
// Settings,
Exit,
}
6 changes: 2 additions & 4 deletions core/src/imports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,8 @@ pub use std::path::{Path, PathBuf};
pub use std::pin::Pin;
pub use std::rc::Rc;
pub use std::str::FromStr;
pub use std::sync::{
atomic::{AtomicBool, AtomicU32, AtomicU64, AtomicUsize, Ordering},
OnceLock,
};
pub use std::sync::atomic::{AtomicBool, AtomicU32, AtomicU64, AtomicUsize, Ordering};
pub use std::sync::OnceLock;
pub use std::sync::{Arc, Mutex, MutexGuard, RwLock};
pub use std::time::Duration;

Expand Down
Loading

0 comments on commit 9fb534d

Please sign in to comment.