This commit is contained in:
2025-12-05 13:13:03 -05:00
parent c9eff77dff
commit 63bd73e444
8 changed files with 46 additions and 226 deletions

View File

@@ -1,18 +1,4 @@
use const_format::formatc;
use epaint::Color32;
use shadow_rs::shadow;
shadow!(build);
/// Constant string that has a string containing information about the build.
pub const BUILD_INFO: &str = formatc!(
"Commit: {} ({})\nBuild Date: {}\nPackage Version: {}\nRust Channel: {}\nRust Version: {}",
&build::SHORT_COMMIT,
&build::BRANCH,
&build::BUILD_TIME,
&build::PKG_VERSION,
&build::RUST_CHANNEL,
&build::RUST_VERSION,
);
pub const FONT_SIZE: f32 = 14.0;

View File

@@ -14,8 +14,8 @@ pub use crate::{
function_entry::{FunctionEntry, Riemann},
math_app::AppSettings,
misc::{
EguiHelper, HashBytes, hashed_storage_create, hashed_storage_read, newtons_method,
option_vec_printer, step_helper,
hashed_storage_create, hashed_storage_read, newtons_method, option_vec_printer,
step_helper, EguiHelper,
},
unicode_helper::{to_chars_array, to_unicode_hash},
};

View File

@@ -1,5 +1,5 @@
use crate::{
consts::{BUILD_INFO, COLORS, DEFAULT_INTEGRAL_NUM, DEFAULT_MAX_X, DEFAULT_MIN_X, build},
consts::{COLORS, DEFAULT_INTEGRAL_NUM, DEFAULT_MAX_X, DEFAULT_MIN_X},
function_entry::Riemann,
function_manager::FunctionManager,
misc::option_vec_printer,
@@ -138,8 +138,6 @@ impl MathApp {
#[cfg(not(threading))]
tracing::info!("Threading: Disabled");
tracing::info!("commit: {}", build::SHORT_COMMIT);
tracing::info!("Initializing...");
let start = Instant::now();
@@ -150,26 +148,24 @@ impl MathApp {
fn get_storage_decompressed() -> Option<Vec<u8>> {
let data = get_localstorage().get_item(DATA_NAME).ok()??;
let (commit, cached_data) = crate::misc::hashed_storage_read(&data)?;
let cached_data = crate::misc::hashed_storage_read(&data)?;
tracing::info!("Reading decompression cache. Bytes: {}", cached_data.len());
return Some(cached_data);
if commit == unsafe { std::mem::transmute::<&str, crate::misc::HashBytes>(build::SHORT_COMMIT) } {
tracing::info!("Reading decompression cache. Bytes: {}", cached_data.len());
return Some(cached_data);
} else {
None
}
}
fn load_functions() -> Option<FunctionManager> {
let data = get_localstorage().get_item(FUNC_NAME).ok()??;
let (commit, func_data) = crate::misc::hashed_storage_read(&data)?;
let func_data = crate::misc::hashed_storage_read(&data)?;
if commit == unsafe { std::mem::transmute::<&str, &[u8]>(build::SHORT_COMMIT) } {
tracing::info!("Reading previous function data");
let function_manager: FunctionManager = bincode::deserialize(&func_data).ok()?;
tracing::info!("Reading previous function data");
if let Ok(Some(function_manager)) = bincode::deserialize(&func_data) {
return Some(function_manager);
} else {
None
tracing::info!("Unable to load functionManager instance");
return None;
}
}
@@ -191,12 +187,8 @@ impl MathApp {
#[cfg(target = "wasm32")]
{
tracing::info!("Setting decompression cache");
let commit: crate::misc::HashBytes = const {
unsafe {
std::mem::transmute::<&str, crate::misc::HashBytes>(build::SHORT_COMMIT)
}
};
let saved_data = commit.hashed_storage_create(data);
let saved_data = hashed_storage_create(data);
tracing::info!("Bytes: {}", saved_data.len());
get_localstorage()
.set_item(DATA_NAME, saved_data)
@@ -362,11 +354,9 @@ impl MathApp {
#[cfg(target_arch = "wasm32")]
{
tracing::info!("Saving function data");
use crate::misc::{HashBytes, hashed_storage_create};
let hash: HashBytes =
unsafe { std::mem::transmute::<&str, HashBytes>(build::SHORT_COMMIT) };
use crate::misc::hashed_storage_create;
let saved_data = hashed_storage_create(
hash,
&bincode::serialize(&self.functions)
.expect("unable to deserialize functions"),
);
@@ -520,8 +510,6 @@ impl App for MathApp {
.resizable(false)
.collapsible(false)
.show(ctx, |ui| {
ui.add(egui::Label::new(BUILD_INFO));
if let Some(ref took) = self.last_info.1 {
ui.label(took);
}

View File

@@ -1,4 +1,5 @@
use base64::{Engine as _, engine::general_purpose};
use base64::engine::general_purpose;
use base64::Engine;
use egui_plot::{Line, PlotPoint, PlotPoints, Points};
use emath::Pos2;
use itertools::Itertools;
@@ -150,34 +151,14 @@ pub fn step_helper(max_i: usize, min_x: f64, step: f64) -> Vec<f64> {
.collect()
}
pub const HASH_LENGTH: usize = 8;
/// Represents bytes used to represent hash info
pub type HashBytes = [u8; HASH_LENGTH];
#[allow(dead_code)]
pub fn hashed_storage_create(hashbytes: HashBytes, data: &[u8]) -> String {
let combined_data = [hashbytes.to_vec(), data.to_vec()].concat();
general_purpose::STANDARD.encode(combined_data)
pub fn hashed_storage_create(data: &[u8]) -> String {
general_purpose::STANDARD.encode(data)
}
#[allow(dead_code)]
pub fn hashed_storage_read(data: &str) -> Option<(HashBytes, Vec<u8>)> {
// Decode base64 data
let decoded_bytes = general_purpose::STANDARD.decode(data).ok()?;
// Make sure data is long enough to decode
if HASH_LENGTH > decoded_bytes.len() {
return None;
}
// Split hash and data
let (hash_bytes, data_bytes) = decoded_bytes.split_at(HASH_LENGTH);
// Convert hash bytes to HashBytes
let hash: HashBytes = hash_bytes.try_into().ok()?;
Some((hash, data_bytes.to_vec()))
pub fn hashed_storage_read(data: &str) -> Option<Vec<u8>> {
general_purpose::STANDARD.decode(data).ok()
}
include!(concat!(env!("OUT_DIR"), "/valid_chars.rs"));