platform
This commit is contained in:
parent
645e03ea86
commit
ea38f61058
14 changed files with 123 additions and 19 deletions
58
frontend/src/platform/browser.rs
Normal file
58
frontend/src/platform/browser.rs
Normal file
|
@ -0,0 +1,58 @@
|
|||
use zoon::*;
|
||||
use std::sync::Mutex;
|
||||
use wellen::simple::Waveform;
|
||||
use shared::wellen_helpers;
|
||||
|
||||
#[derive(Default)]
|
||||
struct Store {
|
||||
waveform: Mutex<Option<Waveform>>,
|
||||
}
|
||||
|
||||
static STORE: Lazy<Store> = lazy::default();
|
||||
|
||||
pub(super) async fn show_window() {}
|
||||
|
||||
pub(super) async fn load_waveform(test_file_name: &'static str) {
|
||||
static SIMPLE_VCD: &'static [u8; 311] = include_bytes!("../../../test_files/simple.vcd");
|
||||
// static WAVE_27_FST: &'static [u8; 28860652] = include_bytes!("../../../test_files/wave_27.fst");
|
||||
let chosen_file = match test_file_name {
|
||||
"simple.vcd" => SIMPLE_VCD.to_vec(),
|
||||
// "wave_27.fst" => WAVE_27_FST.to_vec(),
|
||||
test_file_name => todo!("add {test_file_name} to the `test_files` folder"),
|
||||
};
|
||||
let waveform = wellen_helpers::read_from_bytes(chosen_file);
|
||||
let Ok(waveform) = waveform else {
|
||||
panic!("VCD file reading failed")
|
||||
};
|
||||
*STORE.waveform.lock().unwrap_throw() = Some(waveform);
|
||||
}
|
||||
|
||||
pub(super) async fn get_hierarchy() -> wellen::Hierarchy {
|
||||
let waveform = STORE.waveform.lock().unwrap_throw();
|
||||
let hierarchy = waveform.as_ref().unwrap_throw().hierarchy();
|
||||
// @TODO Wrap `hierarchy` in `Waveform` with `Rc/Arc` or add the method `take` / `clone` or refactor?
|
||||
serde_json::from_value(serde_json::to_value(hierarchy).unwrap_throw()).unwrap_throw()
|
||||
}
|
||||
|
||||
pub(super) async fn get_time_table() -> wellen::TimeTable {
|
||||
let waveform = STORE.waveform.lock().unwrap_throw();
|
||||
let time_table = waveform.as_ref().unwrap_throw().time_table();
|
||||
// @TODO Wrap `time_table` in `Waveform` with `Rc/Arc` or add the method `take` / `clone` or refactor?
|
||||
serde_json::from_value(serde_json::to_value(time_table).unwrap_throw()).unwrap_throw()
|
||||
}
|
||||
|
||||
pub(super) async fn load_and_get_signal(signal_ref: wellen::SignalRef) -> wellen::Signal {
|
||||
let mut waveform_lock = STORE.waveform.lock().unwrap_throw();
|
||||
let waveform = waveform_lock.as_mut().unwrap_throw();
|
||||
// @TODO maybe run it in a thread to not block the main one and then
|
||||
waveform.load_signals(&[signal_ref]);
|
||||
let signal = waveform.get_signal(signal_ref).unwrap_throw();
|
||||
// @TODO `clone` / `Rc/Arc` / refactor?
|
||||
serde_json::from_value(serde_json::to_value(signal).unwrap_throw()).unwrap_throw()
|
||||
}
|
||||
|
||||
pub(super) async fn unload_signal(signal_ref: wellen::SignalRef) {
|
||||
let mut waveform_lock = STORE.waveform.lock().unwrap_throw();
|
||||
let waveform = waveform_lock.as_mut().unwrap_throw();
|
||||
waveform.unload_signals(&[signal_ref]);
|
||||
}
|
46
frontend/src/platform/tauri.rs
Normal file
46
frontend/src/platform/tauri.rs
Normal file
|
@ -0,0 +1,46 @@
|
|||
use zoon::*;
|
||||
|
||||
pub(super) async fn show_window() {
|
||||
tauri_glue::show_window().await
|
||||
}
|
||||
|
||||
pub(super) async fn load_waveform(test_file_name: &'static str) {
|
||||
tauri_glue::load_waveform(test_file_name).await
|
||||
}
|
||||
|
||||
pub(super) async fn get_hierarchy() -> wellen::Hierarchy {
|
||||
serde_wasm_bindgen::from_value(tauri_glue::get_hierarchy().await).unwrap_throw()
|
||||
}
|
||||
|
||||
pub(super) async fn get_time_table() -> wellen::TimeTable {
|
||||
serde_wasm_bindgen::from_value(tauri_glue::get_time_table().await).unwrap_throw()
|
||||
}
|
||||
|
||||
pub(super) async fn load_and_get_signal(signal_ref: wellen::SignalRef) -> wellen::Signal {
|
||||
serde_wasm_bindgen::from_value(tauri_glue::load_and_get_signal(signal_ref.index()).await)
|
||||
.unwrap_throw()
|
||||
}
|
||||
|
||||
pub(super) async fn unload_signal(signal_ref: wellen::SignalRef) {
|
||||
tauri_glue::unload_signal(signal_ref.index()).await
|
||||
}
|
||||
|
||||
mod tauri_glue {
|
||||
use zoon::*;
|
||||
|
||||
// Note: Add all corresponding methods to `frontend/typescript/tauri_glue/tauri_glue.ts`
|
||||
#[wasm_bindgen(module = "/typescript/bundles/tauri_glue.js")]
|
||||
extern "C" {
|
||||
pub async fn show_window();
|
||||
|
||||
pub async fn load_waveform(test_file_name: &str);
|
||||
|
||||
pub async fn get_hierarchy() -> JsValue;
|
||||
|
||||
pub async fn get_time_table() -> JsValue;
|
||||
|
||||
pub async fn load_and_get_signal(signal_ref_index: usize) -> JsValue;
|
||||
|
||||
pub async fn unload_signal(signal_ref_index: usize);
|
||||
}
|
||||
}
|
Reference in a new issue