diff --git a/plugins/plugin.ts b/plugins/plugin.ts index 454fcfaf..e139c284 100644 --- a/plugins/plugin.ts +++ b/plugins/plugin.ts @@ -1,3 +1,5 @@ console.log('---------------------------'); console.log('- 👋 Hello from plugin.ts -'); console.log('---------------------------'); + +Deno.core.ops.op_hello('World'); diff --git a/src-tauri/src/runtime.rs b/src-tauri/src/runtime.rs index d1009f59..312c8937 100644 --- a/src-tauri/src/runtime.rs +++ b/src-tauri/src/runtime.rs @@ -1,6 +1,6 @@ use deno_ast::{MediaType, ParseParams, SourceTextInfo}; use deno_core::error::AnyError; -use deno_core::{Extension, JsRuntime, ModuleSource, ModuleType, RuntimeOptions}; +use deno_core::{op, Extension, JsRuntime, ModuleSource, ModuleType, RuntimeOptions}; use std::rc::Rc; use deno_core::futures::FutureExt; @@ -11,7 +11,9 @@ pub fn run_plugin_sync(file_path: &str) -> Result<(), AnyError> { } pub async fn run_plugin(file_path: &str) -> Result<(), AnyError> { - let extension = Extension::builder("pluginjs").ops(vec![]).build(); + let extension = Extension::builder("runtime") + .ops(vec![op_hello::decl()]) + .build(); // Initialize a runtime instance let mut runtime = JsRuntime::new(RuntimeOptions { @@ -31,6 +33,13 @@ pub async fn run_plugin(file_path: &str) -> Result<(), AnyError> { result.await? } +#[op] +async fn op_hello(name: String) -> Result { + let contents = format!("Hello {} from Rust!", name); + println!("{}", contents); + Ok(contents) +} + struct TsModuleLoader; impl deno_core::ModuleLoader for TsModuleLoader { diff --git a/src-tauri/src/runtime.ts b/src-tauri/src/runtime.ts index b15da94f..4a8e686e 100644 --- a/src-tauri/src/runtime.ts +++ b/src-tauri/src/runtime.ts @@ -1,4 +1,6 @@ (function (globalThis) { + Deno.core.initializeAsyncOps(); + function argsToMessage(...args) { return args.map((arg) => JSON.stringify(arg)).join(' '); }