progress
This commit is contained in:
parent
7e1fe54d59
commit
3d0d3ef7a3
42
src/lib.rs
42
src/lib.rs
@ -45,16 +45,48 @@ cfg_if::cfg_if! {
|
|||||||
#[global_allocator]
|
#[global_allocator]
|
||||||
static ALLOCATOR: LockedAllocator<FreeListAllocator> = LockedAllocator::new(FreeListAllocator::new());
|
static ALLOCATOR: LockedAllocator<FreeListAllocator> = LockedAllocator::new(FreeListAllocator::new());
|
||||||
|
|
||||||
|
use eframe::WebRunner;
|
||||||
|
use tracing::metadata::LevelFilter;
|
||||||
|
#[derive(Clone)]
|
||||||
|
#[wasm_bindgen]
|
||||||
|
pub struct WebHandle {
|
||||||
|
runner: WebRunner,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[wasm_bindgen]
|
||||||
|
impl WebHandle {
|
||||||
|
/// Installs a panic hook, then returns.
|
||||||
|
#[allow(clippy::new_without_default)]
|
||||||
|
#[wasm_bindgen(constructor)]
|
||||||
|
pub fn new() -> Self {
|
||||||
|
// eframe::WebLogger::init(LevelFilter::Debug).ok();
|
||||||
|
tracing_wasm::set_as_global_default();
|
||||||
|
|
||||||
|
Self {
|
||||||
|
runner: WebRunner::new(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Call this once from JavaScript to start your app.
|
||||||
|
#[wasm_bindgen]
|
||||||
|
pub async fn start(&self, canvas_id: &str) -> Result<(), wasm_bindgen::JsValue> {
|
||||||
|
self.runner
|
||||||
|
.start(
|
||||||
|
canvas_id,
|
||||||
|
eframe::WebOptions::default(),
|
||||||
|
Box::new(|cc| Box::new(math_app::MathApp::new(cc))),
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[wasm_bindgen(start)]
|
#[wasm_bindgen(start)]
|
||||||
pub async fn start() {
|
pub async fn start() {
|
||||||
tracing::info!("Starting...");
|
tracing::info!("Starting...");
|
||||||
|
|
||||||
// Used in order to hook into `panic!()` to log in the browser's console
|
|
||||||
tracing_wasm::set_as_global_default();
|
|
||||||
|
|
||||||
|
let web_handle = WebHandle::new();
|
||||||
eframe::start_web("canvas", eframe::WebOptions::default(),
|
web_handle.start("canvas").await.unwrap()
|
||||||
Box::new(|cc| Box::new(math_app::MathApp::new(cc)))).await.unwrap();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -383,10 +383,11 @@ impl MathApp {
|
|||||||
#[cfg(target_arch = "wasm32")]
|
#[cfg(target_arch = "wasm32")]
|
||||||
{
|
{
|
||||||
tracing::info!("Saving function data");
|
tracing::info!("Saving function data");
|
||||||
use crate::misc::{HashBytes, HashBytesHelper};
|
use crate::misc::{hashed_storage_create, HashBytes};
|
||||||
let hash: HashBytes =
|
let hash: HashBytes =
|
||||||
unsafe { std::mem::transmute::<&str, HashBytes>(build::SHORT_COMMIT) };
|
unsafe { std::mem::transmute::<&str, HashBytes>(build::SHORT_COMMIT) };
|
||||||
let saved_data = hash.hashed_storage_create(
|
let saved_data = hashed_storage_create(
|
||||||
|
hash,
|
||||||
&bincode::serialize(&self.functions)
|
&bincode::serialize(&self.functions)
|
||||||
.expect("unable to deserialize functions"),
|
.expect("unable to deserialize functions"),
|
||||||
);
|
);
|
||||||
|
|||||||
@ -164,8 +164,8 @@ pub const HASH_LENGTH: usize = 8;
|
|||||||
pub type HashBytes = [u8; HASH_LENGTH];
|
pub type HashBytes = [u8; HASH_LENGTH];
|
||||||
|
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
pub fn hashed_storage_create(hashbytes: &HashBytes, data: &[u8]) -> String {
|
pub fn hashed_storage_create(hashbytes: HashBytes, data: &[u8]) -> String {
|
||||||
unsafe { std::mem::transmute::<Vec<u8>, String>([hashbytes, data].concat()) }
|
unsafe { std::mem::transmute::<Vec<u8>, String>([hashbytes.to_vec(), data.to_vec()].concat()) }
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
|
|||||||
0
start-server.sh
Normal file → Executable file
0
start-server.sh
Normal file → Executable file
@ -73,7 +73,7 @@ fn hashed_storage() {
|
|||||||
.as_slice()
|
.as_slice()
|
||||||
.try_into()
|
.try_into()
|
||||||
.expect("cannot turn into [u8; 8]");
|
.expect("cannot turn into [u8; 8]");
|
||||||
let storage = hashed_storage_create(&storage_tmp, data.as_slice());
|
let storage = hashed_storage_create(storage_tmp, data.as_slice());
|
||||||
|
|
||||||
let read = hashed_storage_read(&storage);
|
let read = hashed_storage_read(&storage);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user