platform
This commit is contained in:
parent
645e03ea86
commit
ea38f61058
5
Cargo.lock
generated
5
Cargo.lock
generated
|
@ -1182,6 +1182,7 @@ version = "0.1.0"
|
|||
dependencies = [
|
||||
"serde",
|
||||
"serde_json",
|
||||
"shared",
|
||||
"tauri",
|
||||
"tauri-build",
|
||||
"tauri-plugin-window-state",
|
||||
|
@ -1263,6 +1264,7 @@ dependencies = [
|
|||
name = "frontend"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"shared",
|
||||
"wasm-bindgen-test",
|
||||
"wellen",
|
||||
"zoon",
|
||||
|
@ -3753,6 +3755,9 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "shared"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"wellen",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "signal-hook-registry"
|
||||
|
|
|
@ -16,6 +16,7 @@ readme = "../README.md"
|
|||
publish = false
|
||||
|
||||
[workspace.dependencies]
|
||||
shared = { path = "./shared" }
|
||||
# wellen = { version = "0.9.9", features = ["serde1"] }
|
||||
# wellen = { path = "../wellen/wellen", features = ["serde1"] }
|
||||
wellen = { git = "https://github.com/MartinKavik/wellen", features = ["serde1"], branch = "new_pub_types" }
|
||||
|
|
|
@ -11,6 +11,11 @@ publish.workspace = true
|
|||
wasm-bindgen-test = "0.3.19"
|
||||
|
||||
[dependencies]
|
||||
shared.workspace = true
|
||||
zoon.workspace = true
|
||||
wellen.workspace = true
|
||||
|
||||
[features]
|
||||
platform_browser = []
|
||||
platform_tauri = []
|
||||
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
use crate::tauri_bridge;
|
||||
use crate::{HierarchyAndTimeTable, Layout};
|
||||
use crate::{platform, HierarchyAndTimeTable, Layout};
|
||||
use futures_util::join;
|
||||
use std::mem;
|
||||
use std::ops::Not;
|
||||
|
@ -143,10 +142,10 @@ impl ControlsPanel {
|
|||
drop(hierarchy_and_time_table_lock);
|
||||
let hierarchy_and_time_table = hierarchy_and_time_table.clone();
|
||||
Task::start(async move {
|
||||
tauri_bridge::load_waveform(test_file_name).await;
|
||||
platform::load_waveform(test_file_name).await;
|
||||
let (hierarchy, time_table) = join!(
|
||||
tauri_bridge::get_hierarchy(),
|
||||
tauri_bridge::get_time_table()
|
||||
platform::get_hierarchy(),
|
||||
platform::get_time_table()
|
||||
);
|
||||
hierarchy_and_time_table.set(Some((Rc::new(hierarchy), Rc::new(time_table))))
|
||||
})
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use std::rc::Rc;
|
||||
use zoon::*;
|
||||
|
||||
mod tauri_bridge;
|
||||
mod platform;
|
||||
|
||||
mod controls_panel;
|
||||
use controls_panel::ControlsPanel;
|
||||
|
@ -23,7 +23,7 @@ fn main() {
|
|||
Task::start(async {
|
||||
// https://github.com/tauri-apps/tauri/issues/5170
|
||||
Timer::sleep(100).await;
|
||||
tauri_bridge::show_window().await;
|
||||
platform::show_window().await;
|
||||
});
|
||||
}
|
||||
|
||||
|
|
33
frontend/src/platform.rs
Normal file
33
frontend/src/platform.rs
Normal file
|
@ -0,0 +1,33 @@
|
|||
#[cfg(feature = "platform_tauri")]
|
||||
mod tauri;
|
||||
#[cfg(feature = "platform_tauri")]
|
||||
use tauri as platform;
|
||||
|
||||
#[cfg(feature = "platform_browser")]
|
||||
mod browser;
|
||||
#[cfg(feature = "platform_browser")]
|
||||
use browser as platform;
|
||||
|
||||
pub async fn show_window() {
|
||||
platform::show_window().await
|
||||
}
|
||||
|
||||
pub async fn load_waveform(test_file_name: &'static str) {
|
||||
platform::load_waveform(test_file_name).await
|
||||
}
|
||||
|
||||
pub async fn get_hierarchy() -> wellen::Hierarchy {
|
||||
platform::get_hierarchy().await
|
||||
}
|
||||
|
||||
pub async fn get_time_table() -> wellen::TimeTable {
|
||||
platform::get_time_table().await
|
||||
}
|
||||
|
||||
pub async fn load_and_get_signal(signal_ref: wellen::SignalRef) -> wellen::Signal {
|
||||
platform::load_and_get_signal(signal_ref).await
|
||||
}
|
||||
|
||||
pub async fn unload_signal(signal_ref: wellen::SignalRef) {
|
||||
platform::unload_signal(signal_ref).await
|
||||
}
|
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]);
|
||||
}
|
|
@ -1,27 +1,27 @@
|
|||
use zoon::*;
|
||||
|
||||
pub async fn show_window() {
|
||||
pub(super) async fn show_window() {
|
||||
tauri_glue::show_window().await
|
||||
}
|
||||
|
||||
pub async fn load_waveform(test_file_name: &'static str) {
|
||||
pub(super) async fn load_waveform(test_file_name: &'static str) {
|
||||
tauri_glue::load_waveform(test_file_name).await
|
||||
}
|
||||
|
||||
pub async fn get_hierarchy() -> wellen::Hierarchy {
|
||||
pub(super) async fn get_hierarchy() -> wellen::Hierarchy {
|
||||
serde_wasm_bindgen::from_value(tauri_glue::get_hierarchy().await).unwrap_throw()
|
||||
}
|
||||
|
||||
pub async fn get_time_table() -> wellen::TimeTable {
|
||||
pub(super) async fn get_time_table() -> wellen::TimeTable {
|
||||
serde_wasm_bindgen::from_value(tauri_glue::get_time_table().await).unwrap_throw()
|
||||
}
|
||||
|
||||
pub async fn load_and_get_signal(signal_ref: wellen::SignalRef) -> wellen::Signal {
|
||||
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 async fn unload_signal(signal_ref: wellen::SignalRef) {
|
||||
pub(super) async fn unload_signal(signal_ref: wellen::SignalRef) {
|
||||
tauri_glue::unload_signal(signal_ref.index()).await
|
||||
}
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
use crate::{tauri_bridge, HierarchyAndTimeTable};
|
||||
use crate::{platform, HierarchyAndTimeTable};
|
||||
use wellen::GetItem;
|
||||
use zoon::{eprintln, *};
|
||||
|
||||
|
@ -61,7 +61,7 @@ impl WaveformPanel {
|
|||
selected_var_refs.signal_vec().delay_remove(clone!((hierarchy_and_time_table) move |var_ref| {
|
||||
clone!((var_ref, hierarchy_and_time_table) async move {
|
||||
if let Some(hierarchy_and_time_table) = hierarchy_and_time_table.get_cloned() {
|
||||
tauri_bridge::unload_signal(hierarchy_and_time_table.0.get(var_ref).signal_ref()).await;
|
||||
platform::unload_signal(hierarchy_and_time_table.0.get(var_ref).signal_ref()).await;
|
||||
}
|
||||
})
|
||||
})).for_each(clone!((controller, hierarchy_and_time_table) move |vec_diff| {
|
||||
|
@ -117,7 +117,7 @@ impl WaveformPanel {
|
|||
|
||||
let var = hierarchy.get(var_ref);
|
||||
let signal_ref = var.signal_ref();
|
||||
let signal = tauri_bridge::load_and_get_signal(signal_ref).await;
|
||||
let signal = platform::load_and_get_signal(signal_ref).await;
|
||||
|
||||
let timescale = hierarchy.timescale();
|
||||
// @TODO remove
|
||||
|
|
|
@ -6,3 +6,6 @@ repository.workspace = true
|
|||
authors.workspace = true
|
||||
readme.workspace = true
|
||||
publish.workspace = true
|
||||
|
||||
[dependencies]
|
||||
wellen.workspace = true
|
||||
|
|
|
@ -1 +1 @@
|
|||
|
||||
pub mod wellen_helpers;
|
||||
|
|
|
@ -16,6 +16,7 @@ crate-type = ["staticlib", "cdylib", "rlib"]
|
|||
tauri-build = { version = "=2.0.0-beta.15", features = [] }
|
||||
|
||||
[dependencies]
|
||||
shared.workspace = true
|
||||
wellen.workspace = true
|
||||
serde_json = "1.0"
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
use std::rc::Rc;
|
||||
use std::sync::Mutex;
|
||||
use wellen::simple::Waveform;
|
||||
|
||||
mod wellen_helpers;
|
||||
use shared::wellen_helpers;
|
||||
|
||||
#[derive(Default)]
|
||||
struct Store {
|
||||
|
|
Loading…
Reference in a new issue