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

4
src-tauri/.gitignore vendored Normal file
View file

@ -0,0 +1,4 @@
# Generated by Cargo
# will have compiled files and executables
/target/
/gen/schemas

23
src-tauri/Cargo.toml Normal file
View file

@ -0,0 +1,23 @@
[package]
name = "fastwave"
version = "0.1.0"
authors = ["FastWave authors"]
repository = "https://github.com/JoyOfHardware/FastWave2.0"
edition = "2021"
rust-version = "1.70"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[lib]
name = "app_lib"
crate-type = ["staticlib", "cdylib", "rlib"]
[build-dependencies]
tauri-build = { version = "=2.0.0-beta.15", features = [] }
[dependencies]
wellen.workspace = true
serde_json = "1.0"
serde = { version = "1.0", features = ["derive"] }
tauri = { version = "=2.0.0-beta.19", features = ["macos-private-api", "linux-ipc-protocol"] }
tauri-plugin-window-state = "=2.0.0-beta.7"

3
src-tauri/build.rs Normal file
View file

@ -0,0 +1,3 @@
fn main() {
tauri_build::build()
}

View file

@ -0,0 +1,17 @@
{
"$schema": "../gen/schemas/desktop-schema.json",
"identifier": "default",
"description": "enables the default permissions",
"windows": ["main"],
"permissions": [
"path:default",
"event:default",
"window:default",
"webview:default",
"app:default",
"resources:default",
"image:default",
"menu:default",
"tray:default"
]
}

BIN
src-tauri/icons/128x128.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

BIN
src-tauri/icons/32x32.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 25 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 28 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.9 KiB

BIN
src-tauri/icons/icon.icns Normal file

Binary file not shown.

BIN
src-tauri/icons/icon.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 37 KiB

BIN
src-tauri/icons/icon.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 49 KiB

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,
))
}

40
src-tauri/tauri.conf.json Normal file
View file

@ -0,0 +1,40 @@
{
"productName": "FastWave",
"version": "0.1.0",
"identifier": "com.fastwave",
"build": {
"frontendDist": "../frontend_dist",
"devUrl": "http://localhost:8080",
"beforeDevCommand": "makers mzoon start",
"beforeBuildCommand": "makers mzoon build -r -f"
},
"app": {
"macOSPrivateApi": true,
"withGlobalTauri": true,
"windows": [
{
"title": "FastWave",
"width": 800,
"height": 600,
"resizable": true,
"fullscreen": false,
"center": true,
"visible": false
}
],
"security": {
"csp": null
}
},
"bundle": {
"active": true,
"targets": "all",
"icon": [
"icons/32x32.png",
"icons/128x128.png",
"icons/128x128@2x.png",
"icons/icon.icns",
"icons/icon.ico"
]
}
}