1
This commit is contained in:
@@ -50,6 +50,19 @@ pub enum FrontendEvent {
|
||||
},
|
||||
}
|
||||
|
||||
fn log_node_event(script_name: &str, level: &str, msg: &str, fields: &Option<Value>) {
|
||||
let extra = fields
|
||||
.as_ref()
|
||||
.map(|f| format!(" {f}"))
|
||||
.unwrap_or_default();
|
||||
let line = format!("[{script_name}] {msg}{extra}");
|
||||
match level {
|
||||
"error" => log::error!(target: "nodejs", "{line}"),
|
||||
"warn" => log::warn!(target: "nodejs", "{line}"),
|
||||
_ => log::info!(target: "nodejs", "{line}"),
|
||||
}
|
||||
}
|
||||
|
||||
fn spawn_event_pump(
|
||||
app: AppHandle,
|
||||
window: Window,
|
||||
@@ -59,17 +72,24 @@ fn spawn_event_pump(
|
||||
let win_label = window.label().to_string();
|
||||
tokio::spawn(async move {
|
||||
while let Some(ev) = rx.recv().await {
|
||||
let payload = match ev {
|
||||
let payload = match &ev {
|
||||
PipelineEvent::Progress(s) => FrontendEvent::Progress {
|
||||
script_name: script_name.clone(),
|
||||
status: s,
|
||||
status: s.clone(),
|
||||
},
|
||||
PipelineEvent::Log { level, msg, fields } => FrontendEvent::Log {
|
||||
script_name: script_name.clone(),
|
||||
PipelineEvent::Log {
|
||||
level,
|
||||
msg,
|
||||
fields,
|
||||
},
|
||||
} => {
|
||||
log_node_event(&script_name, level, msg, fields);
|
||||
FrontendEvent::Log {
|
||||
script_name: script_name.clone(),
|
||||
level: level.clone(),
|
||||
msg: msg.clone(),
|
||||
fields: fields.clone(),
|
||||
}
|
||||
}
|
||||
};
|
||||
let _ = app.emit_to(&win_label, EVENT_NAME, payload);
|
||||
}
|
||||
|
||||
@@ -369,6 +369,13 @@ export async function executeVideoRewrite(store) {
|
||||
const p = e.payload;
|
||||
if (p?.type === "progress" && typeof p.status === "string") {
|
||||
store.rewriteProgress = p.status;
|
||||
} else if (p?.type === "log") {
|
||||
const prefix = `[nodejs/${p.scriptName || PIPELINE_SCRIPT}]`;
|
||||
const text =
|
||||
p.fields != null ? `${p.msg} ${JSON.stringify(p.fields)}` : p.msg;
|
||||
if (p.level === "error") console.error(prefix, text);
|
||||
else if (p.level === "warn") console.warn(prefix, text);
|
||||
else console.info(prefix, text);
|
||||
}
|
||||
});
|
||||
} catch {
|
||||
|
||||
Reference in New Issue
Block a user