11
This commit is contained in:
@@ -1,21 +1,15 @@
|
||||
//! Generic Tauri commands for invoking any JS script registered in the
|
||||
//! embedded QuickJS runtime. Replaces the per-pipeline command so adding a
|
||||
//! new flow only requires:
|
||||
//! QuickJS 流水线命令:脚本由后端 `/api/v1/quickjs-scripts` 下发,
|
||||
//! 运行时注入 `__native` 后 eval,并调用 `globalThis.__quickjsMain(params)`。
|
||||
//!
|
||||
//! 1. Drop a new `.js` file into `src-tauri/js/`.
|
||||
//! 2. Add it to `js_runtime::SCRIPT_FILES`.
|
||||
//! 3. Inside the JS file, register one or more entries on
|
||||
//! `globalThis.__scripts[<scriptName>]`.
|
||||
//! 前端用法示例:
|
||||
//!
|
||||
//! Frontend usage:
|
||||
//!
|
||||
//! ```ts
|
||||
//! ```ignore
|
||||
//! import { invoke } from "@tauri-apps/api/core";
|
||||
//! import { listen } from "@tauri-apps/api/event";
|
||||
//!
|
||||
//! const off = await listen("quickjs:event", (e) => console.log(e.payload));
|
||||
//! const result = await invoke("run_quickjs_script", {
|
||||
//! scriptName: "process_douyin_share",
|
||||
//! scriptName: "douyin_pipeline.js",
|
||||
//! params: { shareText: "...", modelConfig: {...}, ... },
|
||||
//! });
|
||||
//! off();
|
||||
@@ -48,11 +42,6 @@ pub enum FrontendEvent {
|
||||
|
||||
const EVENT_NAME: &str = "quickjs:event";
|
||||
|
||||
/// Run an arbitrary registered QuickJS script by name.
|
||||
///
|
||||
/// `script_name` must already be registered on `globalThis.__scripts` by
|
||||
/// one of the bundled `js/*.js` files. `params` is forwarded as-is to the
|
||||
/// script entry function.
|
||||
#[tauri::command]
|
||||
pub async fn run_quickjs_script(
|
||||
app: AppHandle,
|
||||
@@ -62,7 +51,6 @@ pub async fn run_quickjs_script(
|
||||
) -> Result<Value, String> {
|
||||
let (tx, mut rx) = mpsc::unbounded_channel::<PipelineEvent>();
|
||||
|
||||
// Forward script events to the frontend window.
|
||||
let app_for_emit = app.clone();
|
||||
let win_label = window.label().to_string();
|
||||
let script_for_emit = script_name.clone();
|
||||
@@ -92,7 +80,7 @@ pub async fn run_quickjs_script(
|
||||
Ok(result)
|
||||
}
|
||||
|
||||
/// Diagnostic helper — returns the list of registered script names.
|
||||
/// 列出后端 `scripts/quickjs` 目录中的 `.js` 文件名。
|
||||
#[tauri::command]
|
||||
pub async fn list_quickjs_scripts() -> Result<Vec<String>, String> {
|
||||
js_runtime::list_scripts().await.map_err(|e| e.to_string())
|
||||
|
||||
Reference in New Issue
Block a user