python decoder workaround

This commit is contained in:
Martin Kavík 2024-07-05 02:09:26 +02:00
parent e01752ecec
commit 95450ce52a
5 changed files with 109 additions and 122 deletions

View file

@ -23,5 +23,9 @@ serde = { version = "1.0", features = ["derive"] }
tauri = { version = "=2.0.0-beta.22", features = ["macos-private-api", "linux-ipc-protocol"] }
tauri-plugin-window-state = "=2.0.0-beta.9"
tauri-plugin-dialog = "=2.0.0-beta.9"
wasmtime = "22.0.0"
wasmtime-wasi = "22.0.0"
# wasmtime = "22.0.0"
# wasmtime-wasi = "22.0.0"
# ~23.0.0
wasmtime = { git = "https://github.com/bytecodealliance/wasmtime", rev = "842fa767acdc26f096ac108605353b8b71e23169" }
wasmtime-wasi = { git = "https://github.com/bytecodealliance/wasmtime", rev = "842fa767acdc26f096ac108605353b8b71e23169" }

View file

@ -16,19 +16,23 @@ impl WasiView for State {
}
impl component::decoder::host::Host for State {
fn log(&mut self, message: String) -> () {
fn log(&mut self, message: String) {
println!("Decoder: {message}");
}
}
// @TODO Remove / improve comments below
// Testing
// FW.add_decoders(["../test_files/components/rust_decoder/rust_decoder.wasm"])
// FW.add_decoders(["../test_files/components/javascript_decoder/javascript_decoder.wasm"])
// FW.add_decoders(["../test_files/components/python_decoder/python_decoder.wasm"])
pub fn add_decoders(decoder_paths: Vec<DecoderPath>) -> AddedDecodersCount {
println!("decoders in Tauri: {decoder_paths:#?}");
println!("{:#?}", std::env::current_dir());
println!("Current dir: {:#?}", std::env::current_dir().unwrap());
let decoder_paths_len = decoder_paths.len();
// New thread to prevent panics caused by running runtime in runtime
// @TODO replace with Tokio's spawn_blocking?
std::thread::spawn(move || {
if let Err(error) = add_decoder(&decoder_paths[0]) {
eprintln!("add_decoders error: {error:?}");
@ -52,8 +56,9 @@ fn add_decoder(path: &str) -> wasmtime::Result<()> {
table: ResourceTable::new(),
});
let (component, _instance) = Component::instantiate(&mut store, &wasmtime_component, &linker)?;
let component = Component::instantiate(&mut store, &wasmtime_component, &linker)?;
println!("Decoder name: {}", component.component_decoder_decoder().call_name(&mut store)?);
component.component_decoder_decoder().call_init(&mut store)?;
Ok(())