This commit is contained in:
Martin Kavík 2024-05-27 21:24:46 +02:00
commit 31c9c600b0
59 changed files with 47825 additions and 0 deletions

80
src-tauri/src/lib.rs Normal file
View file

@ -0,0 +1,80 @@
use std::sync::Mutex;
use wellen::simple::Waveform;
mod wellen_helpers;
#[derive(Default)]
struct Store {
waveform: Mutex<Option<Waveform>>,
}
#[tauri::command(rename_all = "snake_case")]
fn show_window(window: tauri::Window) {
window.show().unwrap();
}
#[tauri::command(rename_all = "snake_case")]
fn load_waveform(store: tauri::State<Store>) {
let waveform =
wellen_helpers::read_from_bytes(include_bytes!("../../test_files/simple.vcd").to_vec());
let Ok(waveform) = waveform else {
panic!("VCD file reading failed")
};
*store.waveform.lock().unwrap() = Some(waveform);
}
#[tauri::command(rename_all = "snake_case")]
fn get_hierarchy(store: tauri::State<Store>) -> serde_json::Value {
let waveform = store.waveform.lock().unwrap();
let hierarchy = waveform.as_ref().unwrap().hierarchy();
serde_json::to_value(hierarchy).unwrap()
}
#[tauri::command(rename_all = "snake_case")]
fn get_time_table(store: tauri::State<Store>) -> serde_json::Value {
let waveform = store.waveform.lock().unwrap();
let time_table = waveform.as_ref().unwrap().time_table();
serde_json::to_value(time_table).unwrap()
}
#[tauri::command(rename_all = "snake_case")]
fn load_and_get_signal(signal_ref_index: usize, store: tauri::State<Store>) -> serde_json::Value {
let signal_ref = wellen::SignalRef::from_index(signal_ref_index).unwrap();
let mut waveform_lock = store.waveform.lock().unwrap();
let waveform = waveform_lock.as_mut().unwrap();
// @TODO maybe run it in a thread to not block the main one and then
// make the command async or return the result through a Tauri channel
waveform.load_signals_multi_threaded(&[signal_ref]);
let signal = waveform.get_signal(signal_ref).unwrap();
serde_json::to_value(signal).unwrap()
}
#[tauri::command(rename_all = "snake_case")]
fn unload_signal(signal_ref_index: usize, store: tauri::State<Store>) {
let signal_ref = wellen::SignalRef::from_index(signal_ref_index).unwrap();
let mut waveform_lock = store.waveform.lock().unwrap();
let waveform = waveform_lock.as_mut().unwrap();
waveform.unload_signals(&[signal_ref]);
}
#[cfg_attr(mobile, tauri::mobile_entry_point)]
pub fn run() {
// https://github.com/tauri-apps/tauri/issues/8462
#[cfg(target_os = "linux")]
std::env::set_var("WEBKIT_DISABLE_DMABUF_RENDERER", "1");
tauri::Builder::default()
.manage(Store::default())
.plugin(tauri_plugin_window_state::Builder::default().build())
// Npte: Add all handlers to `frontend/src/tauri_bridge.rs`
.invoke_handler(tauri::generate_handler![
show_window,
load_waveform,
get_hierarchy,
get_time_table,
load_and_get_signal,
unload_signal,
])
.run(tauri::generate_context!())
.expect("error while running tauri application");
}

6
src-tauri/src/main.rs Normal file
View file

@ -0,0 +1,6 @@
// Prevents additional console window on Windows in release, DO NOT REMOVE!!
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
fn main() {
app_lib::run();
}

View file

@ -0,0 +1,15 @@
use wellen::{simple::Waveform, *};
pub fn read_from_bytes(bytes: Vec<u8>) -> Result<Waveform> {
read_from_bytes_with_options(bytes, &LoadOptions::default())
}
pub fn read_from_bytes_with_options(bytes: Vec<u8>, options: &LoadOptions) -> Result<Waveform> {
let header = viewers::read_header_from_bytes(bytes, options)?;
let body = viewers::read_body(header.body, &header.hierarchy, None)?;
Ok(Waveform::new(
header.hierarchy,
body.source,
body.time_table,
))
}