component_manager, strict_eval.js
This commit is contained in:
parent
ae4c76ed41
commit
3778469de9
11 changed files with 119 additions and 14 deletions
|
@ -241,8 +241,10 @@ impl HeaderPanel {
|
|||
if raw_event.shift_key() {
|
||||
// @TODO move `prevent_default` to MZ API (next to the `pass_to_parent` method?)
|
||||
raw_event.prevent_default();
|
||||
let result = script_bridge::strict_eval(&script.lock_ref());
|
||||
command_result.set(Some(result));
|
||||
Task::start(clone!((script, command_result) async move {
|
||||
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 JavascriptCode = String;
|
||||
type AddedDecodersCount = usize;
|
||||
type DecoderPath = String;
|
||||
|
||||
pub async fn show_window() {
|
||||
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) {
|
||||
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 std::sync::Mutex;
|
||||
use wellen::simple::Waveform;
|
||||
use zoon::*;
|
||||
use zoon::{*, eprintln};
|
||||
|
||||
#[derive(Default)]
|
||||
struct BrowserPlatformStore {
|
||||
|
@ -120,3 +120,11 @@ pub(super) async fn unload_signal(signal_ref: wellen::SignalRef) {
|
|||
let waveform = waveform_lock.as_mut().unwrap_throw();
|
||||
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()
|
||||
}
|
||||
|
||||
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 {
|
||||
use zoon::*;
|
||||
|
||||
|
@ -86,5 +93,10 @@ mod tauri_glue {
|
|||
|
||||
#[wasm_bindgen(catch)]
|
||||
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 zoon::*;
|
||||
|
||||
type FullVarName = String;
|
||||
type AddedDecodersCount = usize;
|
||||
type DecoderPath = String;
|
||||
|
||||
#[wasm_bindgen(
|
||||
inline_js = r#"export function strict_eval(code) { "use strict"; return eval?.(`${code}`) }"#
|
||||
)]
|
||||
#[wasm_bindgen(module = "/typescript/bundles/strict_eval.js")]
|
||||
extern "C" {
|
||||
#[wasm_bindgen(catch)]
|
||||
pub fn strict_eval(code: &str) -> Result<JsValue, JsValue>;
|
||||
pub async fn strict_eval(code: &str) -> Result<JsValue, JsValue>;
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
|
@ -70,8 +69,7 @@ impl FW {
|
|||
}
|
||||
|
||||
/// JS: `FW.add_decoders(["test_files/components/rust_decoder/rust_decoder.wasm"])` -> `1`
|
||||
pub fn add_decoders(decoder_paths: Vec<DecoderPath>) -> usize {
|
||||
zoon::println!("decoders: {decoder_paths:#?}");
|
||||
0
|
||||
}
|
||||
pub async fn add_decoders(decoder_paths: Vec<DecoderPath>) -> AddedDecodersCount {
|
||||
platform::add_decoders(decoder_paths).await
|
||||
}
|
||||
}
|
||||
|
|
|
@ -96,7 +96,7 @@ impl WaveformPanel {
|
|||
if let Some(javascript_code) =
|
||||
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) => {
|
||||
zoon::println!("File with selected vars loaded: {js_value:?}")
|
||||
}
|
||||
|
@ -153,7 +153,7 @@ impl WaveformPanel {
|
|||
if let Some(javascript_code) =
|
||||
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!(
|
||||
"File with selected vars loaded: {js_value:?}"
|
||||
),
|
||||
|
|
Reference in a new issue