remove_all_decoders

This commit is contained in:
Martin Kavík 2024-07-07 14:53:30 +02:00
parent deef698f8d
commit b2055ff22d
8 changed files with 46 additions and 1 deletions

View file

@ -16,6 +16,7 @@ use browser as platform;
type Filename = String; type Filename = String;
type JavascriptCode = String; type JavascriptCode = String;
type AddedDecodersCount = usize; type AddedDecodersCount = usize;
type RemovedDecodersCount = usize;
type DecoderPath = String; type DecoderPath = String;
pub async fn show_window() { pub async fn show_window() {
@ -64,3 +65,7 @@ pub async fn unload_signal(signal_ref: wellen::SignalRef) {
pub async fn add_decoders(decoder_paths: Vec<DecoderPath>) -> AddedDecodersCount { pub async fn add_decoders(decoder_paths: Vec<DecoderPath>) -> AddedDecodersCount {
platform::add_decoders(decoder_paths).await platform::add_decoders(decoder_paths).await
} }
pub async fn remove_all_decoders() -> RemovedDecodersCount {
platform::remove_all_decoders().await
}

View file

@ -128,3 +128,9 @@ pub(super) async fn add_decoders(
eprintln!("Adding decoders is not supported in the browser."); eprintln!("Adding decoders is not supported in the browser.");
0 0
} }
pub(super) async fn remove_all_decoders() -> super::RemovedDecodersCount {
// @TODO error message for user
eprintln!("Removing decoders is not supported in the browser.");
0
}

View file

@ -63,6 +63,11 @@ pub(super) async fn add_decoders(
.unwrap_throw() .unwrap_throw()
} }
pub(super) async fn remove_all_decoders() -> super::RemovedDecodersCount {
serde_wasm_bindgen::from_value(tauri_glue::remove_all_decoders().await.unwrap_throw())
.unwrap_throw()
}
mod tauri_glue { mod tauri_glue {
use zoon::*; use zoon::*;
@ -98,5 +103,8 @@ mod tauri_glue {
pub async fn add_decoders( pub async fn add_decoders(
decoder_paths: Vec<super::super::DecoderPath>, decoder_paths: Vec<super::super::DecoderPath>,
) -> Result<JsValue, JsValue>; ) -> Result<JsValue, JsValue>;
#[wasm_bindgen(catch)]
pub async fn remove_all_decoders() -> Result<JsValue, JsValue>;
} }
} }

View file

@ -4,6 +4,7 @@ use zoon::*;
type FullVarName = String; type FullVarName = String;
type AddedDecodersCount = usize; type AddedDecodersCount = usize;
type RemovedDecodersCount = usize;
type DecoderPath = String; type DecoderPath = String;
#[wasm_bindgen(module = "/typescript/bundles/strict_eval.js")] #[wasm_bindgen(module = "/typescript/bundles/strict_eval.js")]
@ -72,4 +73,9 @@ impl FW {
pub async fn add_decoders(decoder_paths: Vec<DecoderPath>) -> AddedDecodersCount { pub async fn add_decoders(decoder_paths: Vec<DecoderPath>) -> AddedDecodersCount {
platform::add_decoders(decoder_paths).await platform::add_decoders(decoder_paths).await
} }
/// JS: `FW.remove_all_decoders()` -> `5`
pub async fn remove_all_decoders() -> RemovedDecodersCount {
platform::remove_all_decoders().await
}
} }

View file

@ -2539,12 +2539,16 @@ async function unload_signal(signal_ref_index) {
async function add_decoders(decoder_paths) { async function add_decoders(decoder_paths) {
return await invoke2("add_decoders", { decoder_paths }); return await invoke2("add_decoders", { decoder_paths });
} }
async function remove_all_decoders() {
return await invoke2("remove_all_decoders");
}
export { export {
add_decoders, 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,
pick_and_load_waveform, pick_and_load_waveform,
remove_all_decoders,
show_window, show_window,
unload_signal unload_signal
}; };

View file

@ -10,6 +10,7 @@ type WellenHierarchy = unknown;
type Timeline = unknown; type Timeline = unknown;
type VarFormat = unknown; type VarFormat = unknown;
type AddedDecodersCount = number; type AddedDecodersCount = number;
type RemovedDecodersCount = number;
type DecoderPath = string; type DecoderPath = string;
export async function show_window(): Promise<void> { export async function show_window(): Promise<void> {
@ -53,3 +54,7 @@ export async function unload_signal(signal_ref_index: number): Promise<void> {
export async function add_decoders(decoder_paths: Array<DecoderPath>): Promise<AddedDecodersCount> { export async function add_decoders(decoder_paths: Array<DecoderPath>): Promise<AddedDecodersCount> {
return await invoke("add_decoders", { decoder_paths }); return await invoke("add_decoders", { decoder_paths });
} }
export async function remove_all_decoders(): Promise<RemovedDecodersCount> {
return await invoke("remove_all_decoders");
}

View file

@ -1,4 +1,4 @@
use crate::{AddedDecodersCount, DecoderPath}; use crate::{AddedDecodersCount, DecoderPath, RemovedDecodersCount};
use wasmtime::component::{Component as WasmtimeComponent, *}; use wasmtime::component::{Component as WasmtimeComponent, *};
use wasmtime::{Engine, Store}; use wasmtime::{Engine, Store};
use wasmtime_wasi::{WasiCtx, WasiView}; use wasmtime_wasi::{WasiCtx, WasiView};
@ -25,6 +25,10 @@ impl component::decoder::host::Host for State {
} }
} }
pub fn remove_all_decoders() -> RemovedDecodersCount {
156
}
// @TODO Make println work on Windows? // @TODO Make println work on Windows?
// https://github.com/tauri-apps/tauri/discussions/8626 // https://github.com/tauri-apps/tauri/discussions/8626

View file

@ -6,6 +6,7 @@ use wellen::simple::Waveform;
type Filename = String; type Filename = String;
type JavascriptCode = String; type JavascriptCode = String;
type AddedDecodersCount = usize; type AddedDecodersCount = usize;
type RemovedDecodersCount = usize;
type DecoderPath = String; type DecoderPath = String;
mod component_manager; mod component_manager;
@ -100,6 +101,11 @@ async fn add_decoders(decoder_paths: Vec<DecoderPath>) -> Result<AddedDecodersCo
Ok(component_manager::add_decoders(decoder_paths)) Ok(component_manager::add_decoders(decoder_paths))
} }
#[tauri::command(rename_all = "snake_case")]
async fn remove_all_decoders() -> Result<RemovedDecodersCount, ()> {
Ok(component_manager::remove_all_decoders())
}
#[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
@ -119,6 +125,7 @@ pub fn run() {
load_signal_and_get_timeline, load_signal_and_get_timeline,
unload_signal, unload_signal,
add_decoders, add_decoders,
remove_all_decoders,
]) ])
.run(tauri::generate_context!()) .run(tauri::generate_context!())
.expect("error while running tauri application"); .expect("error while running tauri application");