Skip to content

Commit

Permalink
wip (themes, misc)
Browse files Browse the repository at this point in the history
  • Loading branch information
aspect committed Dec 3, 2023
1 parent 695ff1a commit 8bc1cfc
Show file tree
Hide file tree
Showing 47 changed files with 1,231 additions and 703 deletions.
6 changes: 6 additions & 0 deletions .rustfmt.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# max_width = 100
# use_field_init_shorthand = true
# use_try_shorthand = true
# use_small_heuristics = "Max"
# newline_style = "auto"
# edition = "2021"
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ kaspa-ng-macros = { version = "0.1.0", path = "macros/" }
# ___________________

egui = "0.24.0"
epaint = "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 = [
Expand Down
1 change: 1 addition & 0 deletions core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ wasm-bindgen.workspace = true
zeroize.workspace = true

egui.workspace = true
epaint.workspace = true
egui_plot.workspace = true
egui_extras.workspace = true
chrono.workspace = true
Expand Down
42 changes: 27 additions & 15 deletions core/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ use std::sync::Arc;
use workflow_i18n::*;
use workflow_log::*;

#[allow(unused)]
pub const KASPA_NG_ICON_256X256: &[u8] = include_bytes!("../../resources/icons/icon-256.png");
// #[allow(unused)]
pub const KASPA_NG_ICON_SVG: &[u8] = include_bytes!("../../resources/images/kaspa.svg");
pub const KASPA_NG_LOGO_SVG: &[u8] = include_bytes!("../../resources/images/kaspa-ng.svg");
pub const I18N_EMBEDDED: &str = include_str!("../../resources/i18n/i18n.json");
pub const BUILD_TIMESTAMP: &str = env!("VERGEN_BUILD_TIMESTAMP");
Expand All @@ -21,12 +21,16 @@ pub const RUSTC_HOST_TRIPLE: &str = env!("VERGEN_RUSTC_HOST_TRIPLE");
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 VERSION: &str = env!("CARGO_PKG_VERSION");
pub const CODENAME: &str = "DNA";

cfg_if! {
if #[cfg(not(target_arch = "wasm32"))] {
use kaspad_lib::daemon::create_core;
use kaspad_lib::daemon::{
create_core,
DESIRED_DAEMON_SOFT_FD_LIMIT,
MINIMUM_DAEMON_SOFT_FD_LIMIT
};
use kaspad_lib::args::Args as NodeArgs;
use kaspad_lib::args::parse_args as parse_kaspad_args;
use kaspa_utils::fd_budget;
Expand All @@ -37,9 +41,9 @@ cfg_if! {

#[derive(Debug)]
enum I18n {

Import,
Export,
Reset,
}

enum Args {
Expand All @@ -62,29 +66,31 @@ cfg_if! {

let cmd = Command::new("kaspa-ng")

.about(format!("kaspa-ng v{}-{GIT_DESCRIBE} (rusty-kaspa v{})", env!("CARGO_PKG_VERSION"), kaspa_wallet_core::version()))
.about(format!("kaspa-ng v{VERSION}-{GIT_DESCRIBE} (rusty-kaspa v{})", kaspa_wallet_core::version()))
.arg(arg!(--disable "Disable node services when starting"))
.arg(arg!(--daemon "Run as Rusty Kaspa p2p daemon"))
.arg(
Arg::new("reset-settings")
.long("reset-settings")
.action(ArgAction::SetTrue)
.help("Reset kaspa-ng settings")
)

.subcommand(
Command::new("i18n").hide(true)
.about("kaspa-ng i18n user interface translation")
.subcommand(
Command::new("import")
// .help("import i18n data")
.about("import JSON files suffixed with language codes (*_en.json, *_de.json, etc.)")
.about("import JSON files suffixed with language codes (*_en.json, *_de.json, etc.)")
)
.subcommand(
Command::new("export")
.about("export default 'en' translations as JSON")
.about("export default 'en' translations as JSON")
)
.subcommand(
Command::new("reset")
.about("reset i18n data file")
)
)

.subcommand(
Command::new("cli")
.about("Run kaspa-ng as rusty-kaspa cli wallet")
Expand All @@ -99,6 +105,8 @@ cfg_if! {
Args::I18n { op : I18n::Import }
} else if let Some(_matches) = matches.subcommand_matches("export") {
Args::I18n { op : I18n::Export }
} else if let Some(_matches) = matches.subcommand_matches("reset") {
Args::I18n { op : I18n::Reset }
} else {
println!();
println!("please specify a valid i18n subcommand");
Expand All @@ -119,9 +127,6 @@ 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 {
Expand Down Expand Up @@ -209,7 +214,7 @@ cfg_if! {
.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()),
.with_icon(svg_to_icon_data(KASPA_NG_ICON_SVG, FitTo::Size(256,256))),
..Default::default()
};
eframe::run_native(
Expand Down Expand Up @@ -308,6 +313,12 @@ cfg_if! {
cfg_if! {
if #[cfg(not(target_arch = "wasm32"))] {
fn manage_i18n(op : I18n) -> Result<()> {
if matches!(op, I18n::Reset) {
println!("resetting i18n data file");
i18n::create(i18n_storage_file()?)?;
return Ok(());
}

let i18n_json_file = i18n_storage_file()?;
let i18n_json_file_store = i18n_storage_file()?;
i18n::Builder::new("en", "en")
Expand Down Expand Up @@ -338,6 +349,7 @@ cfg_if! {
Ok(fs::write(&target_folder, json_data)?)
})?;
}
_ => unreachable!()
}

Ok(())
Expand Down
119 changes: 76 additions & 43 deletions core/src/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use kaspa_wallet_core::api::TransactionDataGetResponse;
use kaspa_wallet_core::events::Events as CoreWallet;
use kaspa_wallet_core::storage::{Binding, Hint, PrvKeyDataInfo};
use std::borrow::Cow;
#[allow(unused_imports)]
use workflow_i18n::*;

pub enum Exception {
Expand Down Expand Up @@ -42,6 +43,7 @@ pub struct Core {
pub prv_key_data_map: HashMap<PrvKeyDataId, Arc<PrvKeyDataInfo>>,
pub account_collection: Option<AccountCollection>,
// pub selected_account: Option<Account>,
pub release: Option<Release>,
}

impl Core {
Expand Down Expand Up @@ -92,6 +94,12 @@ impl Core {
egui::FontId::new(18.0, egui::FontFamily::Proportional),
);

apply_theme_by_name(
&cc.egui_ctx,
settings.user_interface.theme_color.as_str(),
settings.user_interface.theme_style.as_str(),
);

// cc.egui_ctx.set_style(style);

// This is also where you can customize the look and feel of egui using
Expand Down Expand Up @@ -162,6 +170,8 @@ impl Core {
hint: None,
discard_hint: false,
exception: None,

release: None,
};

modules.values().for_each(|module| {
Expand All @@ -170,6 +180,17 @@ impl Core {

this.wallet_update_list();

#[cfg(not(target_arch = "wasm32"))]
spawn(async move {
use workflow_core::task::sleep;

loop {
println!("Checking version...");
let _ = check_version().await;
sleep(Duration::from_secs(60 * 60 * 6)).await;
}
});

this
}

Expand Down Expand Up @@ -322,24 +343,21 @@ impl eframe::App for Core {
}
});

// ctx.set_visuals(self.default_style.clone());
let mut current_visuals = ctx.style().visuals.clone(); //.widgets.noninteractive;
// - TODO - TOAST BACKGROUND
// ---
let current_visuals = ctx.style().visuals.clone(); //.widgets.noninteractive;
let mut visuals = current_visuals.clone();
// visuals.widgets.noninteractive.fg_stroke = Stroke::new(1.0, Color32::from_rgb(0, 0, 0));
visuals.widgets.noninteractive.bg_fill = egui::Color32::from_rgb(0, 0, 0);

cfg_if! {
if #[cfg(target_arch = "wasm32")] {
visuals.interact_cursor = Some(CursorIcon::PointingHand);
}
}

// visuals.bg_fill = egui::Color32::from_rgb(0, 0, 0);
ctx.set_visuals(visuals);
self.toasts.show(ctx);

theme().apply(&mut current_visuals);
ctx.set_visuals(current_visuals);
// ---

// cfg_if! {
// if #[cfg(target_arch = "wasm32")] {
// visuals.interact_cursor = Some(CursorIcon::PointingHand);
// }
// }

if !self.settings.initialized {
cfg_if! {
Expand Down Expand Up @@ -443,36 +461,41 @@ impl eframe::App for Core {

#[cfg(not(target_arch = "wasm32"))]
if let Some(screenshot) = self.screenshot.as_ref() {
if let Some(mut path) = rfd::FileDialog::new().save_file() {
path.set_extension("png");
let screen_rect = ctx.screen_rect();
let pixels_per_point = ctx.pixels_per_point();
let screenshot = screenshot.clone();
let sender = self.sender();
std::thread::Builder::new()
.name("screenshot".to_string())
.spawn(move || {
let image = screenshot.region(&screen_rect, Some(pixels_per_point));
image::save_buffer(
&path,
image.as_raw(),
image.width() as u32,
image.height() as u32,
image::ColorType::Rgba8,
)
.unwrap();

sender
.try_send(Events::Notify {
user_notification: UserNotification::success(format!(
"Capture saved to\n{}",
path.to_string_lossy()
)),
})
.unwrap()
})
.expect("Unable to spawn screenshot thread");
self.screenshot.take();
match rfd::FileDialog::new().save_file() {
Some(mut path) => {
path.set_extension("png");
let screen_rect = ctx.screen_rect();
let pixels_per_point = ctx.pixels_per_point();
let screenshot = screenshot.clone();
let sender = self.sender();
std::thread::Builder::new()
.name("screenshot".to_string())
.spawn(move || {
let image = screenshot.region(&screen_rect, Some(pixels_per_point));
image::save_buffer(
&path,
image.as_raw(),
image.width() as u32,
image.height() as u32,
image::ColorType::Rgba8,
)
.unwrap();

sender
.try_send(Events::Notify {
user_notification: UserNotification::success(format!(
"Capture saved to\n{}",
path.to_string_lossy()
)),
})
.unwrap()
})
.expect("Unable to spawn screenshot thread");
self.screenshot.take();
}
None => {
self.screenshot.take();
}
}
}
}
Expand Down Expand Up @@ -505,6 +528,16 @@ impl Core {
_frame: &mut eframe::Frame,
) -> Result<()> {
match event {
Events::ThemeChange => {
if let Some(account_collection) = self.account_collection.as_ref() {
account_collection
.iter()
.for_each(|account| account.update_theme());
}
}
Events::VersionUpdate(release) => {
self.release = Some(release);
}
Events::StoreSettings => {
self.settings_storage_requested = true;
self.last_settings_storage_request = Instant::now();
Expand Down
Loading

0 comments on commit 8bc1cfc

Please sign in to comment.