component_manager, strict_eval.js
This commit is contained in:
parent
d97f98485b
commit
6b52067a95
|
@ -241,8 +241,10 @@ impl HeaderPanel {
|
||||||
if raw_event.shift_key() {
|
if raw_event.shift_key() {
|
||||||
// @TODO move `prevent_default` to MZ API (next to the `pass_to_parent` method?)
|
// @TODO move `prevent_default` to MZ API (next to the `pass_to_parent` method?)
|
||||||
raw_event.prevent_default();
|
raw_event.prevent_default();
|
||||||
let result = script_bridge::strict_eval(&script.lock_ref());
|
Task::start(clone!((script, command_result) async move {
|
||||||
command_result.set(Some(result));
|
let result = script_bridge::strict_eval(&script.lock_ref()).await;
|
||||||
|
command_result.set(Some(result));
|
||||||
|
}));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
|
@ -15,6 +15,8 @@ use browser as platform;
|
||||||
|
|
||||||
type Filename = String;
|
type Filename = String;
|
||||||
type JavascriptCode = String;
|
type JavascriptCode = String;
|
||||||
|
type AddedDecodersCount = usize;
|
||||||
|
type DecoderPath = String;
|
||||||
|
|
||||||
pub async fn show_window() {
|
pub async fn show_window() {
|
||||||
platform::show_window().await
|
platform::show_window().await
|
||||||
|
@ -58,3 +60,7 @@ pub async fn load_signal_and_get_timeline(
|
||||||
pub async fn unload_signal(signal_ref: wellen::SignalRef) {
|
pub async fn unload_signal(signal_ref: wellen::SignalRef) {
|
||||||
platform::unload_signal(signal_ref).await
|
platform::unload_signal(signal_ref).await
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub async fn add_decoders(decoder_paths: Vec<DecoderPath>) -> AddedDecodersCount {
|
||||||
|
platform::add_decoders(decoder_paths).await
|
||||||
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
use shared::wellen_helpers;
|
use shared::wellen_helpers;
|
||||||
use std::sync::Mutex;
|
use std::sync::Mutex;
|
||||||
use wellen::simple::Waveform;
|
use wellen::simple::Waveform;
|
||||||
use zoon::*;
|
use zoon::{*, eprintln};
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
struct BrowserPlatformStore {
|
struct BrowserPlatformStore {
|
||||||
|
@ -120,3 +120,11 @@ pub(super) async fn unload_signal(signal_ref: wellen::SignalRef) {
|
||||||
let waveform = waveform_lock.as_mut().unwrap_throw();
|
let waveform = waveform_lock.as_mut().unwrap_throw();
|
||||||
waveform.unload_signals(&[signal_ref]);
|
waveform.unload_signals(&[signal_ref]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub(super) async fn add_decoders(
|
||||||
|
_decoder_paths: Vec<super::DecoderPath>,
|
||||||
|
) -> super::AddedDecodersCount {
|
||||||
|
// @TODO error message for user
|
||||||
|
eprintln!("Adding decoders is not supported in the browser.");
|
||||||
|
0
|
||||||
|
}
|
||||||
|
|
|
@ -56,6 +56,13 @@ pub(super) async fn unload_signal(signal_ref: wellen::SignalRef) {
|
||||||
.unwrap_throw()
|
.unwrap_throw()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub(super) async fn add_decoders(
|
||||||
|
decoder_paths: Vec<super::DecoderPath>,
|
||||||
|
) -> super::AddedDecodersCount {
|
||||||
|
serde_wasm_bindgen::from_value(tauri_glue::add_decoders(decoder_paths).await.unwrap_throw())
|
||||||
|
.unwrap_throw()
|
||||||
|
}
|
||||||
|
|
||||||
mod tauri_glue {
|
mod tauri_glue {
|
||||||
use zoon::*;
|
use zoon::*;
|
||||||
|
|
||||||
|
@ -86,5 +93,10 @@ mod tauri_glue {
|
||||||
|
|
||||||
#[wasm_bindgen(catch)]
|
#[wasm_bindgen(catch)]
|
||||||
pub async fn unload_signal(signal_ref_index: usize) -> Result<(), JsValue>;
|
pub async fn unload_signal(signal_ref_index: usize) -> Result<(), JsValue>;
|
||||||
|
|
||||||
|
#[wasm_bindgen(catch)]
|
||||||
|
pub async fn add_decoders(
|
||||||
|
decoder_paths: Vec<super::super::DecoderPath>,
|
||||||
|
) -> Result<JsValue, JsValue>;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,16 +1,15 @@
|
||||||
use crate::STORE;
|
use crate::{platform, STORE};
|
||||||
use wellen::GetItem;
|
use wellen::GetItem;
|
||||||
use zoon::*;
|
use zoon::*;
|
||||||
|
|
||||||
type FullVarName = String;
|
type FullVarName = String;
|
||||||
|
type AddedDecodersCount = usize;
|
||||||
type DecoderPath = String;
|
type DecoderPath = String;
|
||||||
|
|
||||||
#[wasm_bindgen(
|
#[wasm_bindgen(module = "/typescript/bundles/strict_eval.js")]
|
||||||
inline_js = r#"export function strict_eval(code) { "use strict"; return eval?.(`${code}`) }"#
|
|
||||||
)]
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#[wasm_bindgen(catch)]
|
#[wasm_bindgen(catch)]
|
||||||
pub fn strict_eval(code: &str) -> Result<JsValue, JsValue>;
|
pub async fn strict_eval(code: &str) -> Result<JsValue, JsValue>;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[wasm_bindgen]
|
#[wasm_bindgen]
|
||||||
|
@ -70,8 +69,7 @@ impl FW {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// JS: `FW.add_decoders(["test_files/components/rust_decoder/rust_decoder.wasm"])` -> `1`
|
/// JS: `FW.add_decoders(["test_files/components/rust_decoder/rust_decoder.wasm"])` -> `1`
|
||||||
pub fn add_decoders(decoder_paths: Vec<DecoderPath>) -> usize {
|
pub async fn add_decoders(decoder_paths: Vec<DecoderPath>) -> AddedDecodersCount {
|
||||||
zoon::println!("decoders: {decoder_paths:#?}");
|
platform::add_decoders(decoder_paths).await
|
||||||
0
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -96,7 +96,7 @@ impl WaveformPanel {
|
||||||
if let Some(javascript_code) =
|
if let Some(javascript_code) =
|
||||||
platform::load_file_with_selected_vars(None).await
|
platform::load_file_with_selected_vars(None).await
|
||||||
{
|
{
|
||||||
match script_bridge::strict_eval(&javascript_code) {
|
match script_bridge::strict_eval(&javascript_code).await {
|
||||||
Ok(js_value) => {
|
Ok(js_value) => {
|
||||||
zoon::println!("File with selected vars loaded: {js_value:?}")
|
zoon::println!("File with selected vars loaded: {js_value:?}")
|
||||||
}
|
}
|
||||||
|
@ -153,7 +153,7 @@ impl WaveformPanel {
|
||||||
if let Some(javascript_code) =
|
if let Some(javascript_code) =
|
||||||
platform::load_file_with_selected_vars(Some(file)).await
|
platform::load_file_with_selected_vars(Some(file)).await
|
||||||
{
|
{
|
||||||
match script_bridge::strict_eval(&javascript_code) {
|
match script_bridge::strict_eval(&javascript_code).await {
|
||||||
Ok(js_value) => zoon::println!(
|
Ok(js_value) => zoon::println!(
|
||||||
"File with selected vars loaded: {js_value:?}"
|
"File with selected vars loaded: {js_value:?}"
|
||||||
),
|
),
|
||||||
|
|
5
frontend/typescript/bundles/strict_eval.js
Normal file
5
frontend/typescript/bundles/strict_eval.js
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
export async function strict_eval(code) {
|
||||||
|
return await eval(code)
|
||||||
|
}
|
|
@ -2536,7 +2536,11 @@ async function load_signal_and_get_timeline(signal_ref_index, timeline_zoom, tim
|
||||||
async function unload_signal(signal_ref_index) {
|
async function unload_signal(signal_ref_index) {
|
||||||
return await invoke2("unload_signal", { signal_ref_index });
|
return await invoke2("unload_signal", { signal_ref_index });
|
||||||
}
|
}
|
||||||
|
async function add_decoders(decoder_paths) {
|
||||||
|
return await invoke2("add_decoders", { decoder_paths });
|
||||||
|
}
|
||||||
export {
|
export {
|
||||||
|
add_decoders,
|
||||||
get_hierarchy,
|
get_hierarchy,
|
||||||
load_file_with_selected_vars,
|
load_file_with_selected_vars,
|
||||||
load_signal_and_get_timeline,
|
load_signal_and_get_timeline,
|
||||||
|
|
|
@ -9,6 +9,8 @@ type JavascriptCode = string;
|
||||||
type WellenHierarchy = unknown;
|
type WellenHierarchy = unknown;
|
||||||
type Timeline = unknown;
|
type Timeline = unknown;
|
||||||
type VarFormat = unknown;
|
type VarFormat = unknown;
|
||||||
|
type AddedDecodersCount = number;
|
||||||
|
type DecoderPath = string;
|
||||||
|
|
||||||
export async function show_window(): Promise<void> {
|
export async function show_window(): Promise<void> {
|
||||||
return await invoke("show_window");
|
return await invoke("show_window");
|
||||||
|
@ -47,3 +49,7 @@ export async function load_signal_and_get_timeline(
|
||||||
export async function unload_signal(signal_ref_index: number): Promise<void> {
|
export async function unload_signal(signal_ref_index: number): Promise<void> {
|
||||||
return await invoke("unload_signal", { signal_ref_index });
|
return await invoke("unload_signal", { signal_ref_index });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function add_decoders(decoder_paths: Array<DecoderPath>): Promise<AddedDecodersCount> {
|
||||||
|
return await invoke("add_decoders", { decoder_paths });
|
||||||
|
}
|
||||||
|
|
54
src-tauri/src/component_manager.rs
Normal file
54
src-tauri/src/component_manager.rs
Normal file
|
@ -0,0 +1,54 @@
|
||||||
|
use crate::{AddedDecodersCount, DecoderPath};
|
||||||
|
use wasmtime::*;
|
||||||
|
|
||||||
|
pub fn add_decoders(decoder_paths: Vec<DecoderPath>) -> AddedDecodersCount {
|
||||||
|
println!("decoders in Tauri: {decoder_paths:#?}");
|
||||||
|
|
||||||
|
wasmtime_test().unwrap();
|
||||||
|
|
||||||
|
decoder_paths.len()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn wasmtime_test() -> wasmtime::Result<()> {
|
||||||
|
let engine = Engine::default();
|
||||||
|
|
||||||
|
// Modules can be compiled through either the text or binary format
|
||||||
|
let wat = r#"
|
||||||
|
(module
|
||||||
|
(import "host" "host_func" (func $host_hello (param i32)))
|
||||||
|
|
||||||
|
(func (export "hello")
|
||||||
|
i32.const 3
|
||||||
|
call $host_hello)
|
||||||
|
)
|
||||||
|
"#;
|
||||||
|
let module = Module::new(&engine, wat)?;
|
||||||
|
|
||||||
|
// Host functionality can be arbitrary Rust functions and is provided
|
||||||
|
// to guests through a `Linker`.
|
||||||
|
let mut linker = Linker::new(&engine);
|
||||||
|
linker.func_wrap(
|
||||||
|
"host",
|
||||||
|
"host_func",
|
||||||
|
|caller: Caller<'_, u32>, param: i32| {
|
||||||
|
println!("Got {} from WebAssembly", param);
|
||||||
|
println!("my host state is: {}", caller.data());
|
||||||
|
},
|
||||||
|
)?;
|
||||||
|
|
||||||
|
// All wasm objects operate within the context of a "store". Each
|
||||||
|
// `Store` has a type parameter to store host-specific data, which in
|
||||||
|
// this case we're using `4` for.
|
||||||
|
let mut store: Store<u32> = Store::new(&engine, 4);
|
||||||
|
|
||||||
|
// Instantiation of a module requires specifying its imports and then
|
||||||
|
// afterwards we can fetch exports by name, as well as asserting the
|
||||||
|
// type signature of the function with `get_typed_func`.
|
||||||
|
let instance = linker.instantiate(&mut store, &module)?;
|
||||||
|
let hello = instance.get_typed_func::<(), ()>(&mut store, "hello")?;
|
||||||
|
|
||||||
|
// And finally we can call the wasm!
|
||||||
|
hello.call(&mut store, ())?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
|
@ -5,6 +5,10 @@ use wellen::simple::Waveform;
|
||||||
|
|
||||||
type Filename = String;
|
type Filename = String;
|
||||||
type JavascriptCode = String;
|
type JavascriptCode = String;
|
||||||
|
type AddedDecodersCount = usize;
|
||||||
|
type DecoderPath = String;
|
||||||
|
|
||||||
|
mod component_manager;
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
struct Store {
|
struct Store {
|
||||||
|
@ -91,6 +95,11 @@ async fn unload_signal(signal_ref_index: usize, store: tauri::State<'_, Store>)
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[tauri::command(rename_all = "snake_case")]
|
||||||
|
async fn add_decoders(decoder_paths: Vec<DecoderPath>) -> Result<AddedDecodersCount, ()> {
|
||||||
|
Ok(component_manager::add_decoders(decoder_paths))
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg_attr(mobile, tauri::mobile_entry_point)]
|
#[cfg_attr(mobile, tauri::mobile_entry_point)]
|
||||||
pub fn run() {
|
pub fn run() {
|
||||||
// https://github.com/tauri-apps/tauri/issues/8462
|
// https://github.com/tauri-apps/tauri/issues/8462
|
||||||
|
@ -109,6 +118,7 @@ pub fn run() {
|
||||||
get_hierarchy,
|
get_hierarchy,
|
||||||
load_signal_and_get_timeline,
|
load_signal_and_get_timeline,
|
||||||
unload_signal,
|
unload_signal,
|
||||||
|
add_decoders,
|
||||||
])
|
])
|
||||||
.run(tauri::generate_context!())
|
.run(tauri::generate_context!())
|
||||||
.expect("error while running tauri application");
|
.expect("error while running tauri application");
|
||||||
|
|
Loading…
Reference in a new issue