feat(electron-shell): 启动链路修复与执行/配置收口插件侧
- 启动链路 P1-P7 修复:预算对齐、完成事件推送、端口占用提示、前端阶段文案接管 - 静态缓存按 IS_FROZEN 区分开发/打包态,bootPhaseOwned 竞态修复 - 一键执行与参数配置统一收口到插件界面,定时任务引用 config_id - 环境包迁移到 %LOCALAPPDATA%\37duAutomation\python-env,重装零解压 - shell-updater:缓存包 sha256 校验、静默升级后自动拉起新版、自动清理旧安装包 - after-pack 钩子生成 shell.version 修复打包态版本识别 - 插件 xq0031/xq0045 迁移至 plugins/XQ0001-0100/ 号段分桶中文目录
This commit is contained in:
@@ -6,6 +6,8 @@
|
||||
const { spawn } = require("child_process");
|
||||
const readline = require("readline");
|
||||
const crypto = require("crypto");
|
||||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
const config = require("./config");
|
||||
const state = require("./state");
|
||||
const scheduler = require("./scheduler");
|
||||
@@ -121,9 +123,49 @@ function finishRun(runId, plugin, status, error, summary) {
|
||||
|
||||
// 提交一次插件运行(手动 POST /api/runs 与定时任务共用入口);立即返回 run_id。
|
||||
// opts: { trigger: "manual" | "schedule", schedule_id } —— 用于区分"谁触发的",落进运行历史
|
||||
//
|
||||
// 参数收口到插件侧:插件界面保存的配置(plugin_configs/<id>.json,单配置 blob)是参数权威来源。
|
||||
// 插件界面手动执行会显式传全量 fields,原样使用;壳子侧入口(定时任务未选方案等)传空 fields 时
|
||||
// 回退到该配置,避免"界面配置了一套、定时任务用 plugin.fields 默认值跑"的参数漂移。
|
||||
function loadUiSavedFields(pluginId) {
|
||||
try {
|
||||
const raw = fs.readFileSync(path.join(config.PLUGIN_CONFIG_DIR, `${pluginId}.json`), "utf-8");
|
||||
const v = JSON.parse(raw);
|
||||
return v && typeof v === "object" && !Array.isArray(v) ? v : null;
|
||||
} catch (_) {
|
||||
return null; // 无保存配置/损坏:维持空 fields(插件走自身默认值)
|
||||
}
|
||||
}
|
||||
|
||||
// 环境包未就绪时的拒绝提示:环境包正在下载/解压时提示等待,云端有包但未装时引导状态栏安装
|
||||
function throwEnvNotReady() {
|
||||
let msg = "插件执行环境未就绪,暂时无法执行";
|
||||
try {
|
||||
const es = require("./env-sync").status();
|
||||
if (es.dl && (es.dl.status === "downloading" || es.dl.status === "extracting")) {
|
||||
msg = "环境包正在安装中(下载/解压),完成后即可执行,请稍候";
|
||||
} else if (es.cloud_available) {
|
||||
msg = "环境包未安装,请点击状态栏「环境」完成安装后再执行";
|
||||
}
|
||||
} catch (_) { /* env-sync 不可用时忽略 */ }
|
||||
throw new Error(msg);
|
||||
}
|
||||
|
||||
function submitRun(account, plugin, fields, opts) {
|
||||
const o = opts && typeof opts === "object" ? opts : {};
|
||||
const trigger = o.trigger === "schedule" ? "schedule" : "manual";
|
||||
// 环境未就绪预防:提交前校验执行链路(入口脚本/解释器),缺失时直接拒绝并给可读提示,
|
||||
// 避免子进程 spawn ENOENT 后用户只看到"执行进程异常退出(exit=-4058)且未返回结果"。
|
||||
// 打包态无环境包且未显式配置解释器时也拒绝(系统 python 不可依赖)。
|
||||
if (!fs.existsSync(config.runnerScript()) ||
|
||||
(!process.env.PYTHON_EXE && !config.pythonEnvRoot() && config.IS_FROZEN)) {
|
||||
throwEnvNotReady();
|
||||
}
|
||||
let effFields = fields && typeof fields === "object" && !Array.isArray(fields) ? fields : {};
|
||||
if (Object.keys(effFields).length === 0) {
|
||||
const saved = loadUiSavedFields(plugin.id);
|
||||
if (saved) effFields = saved;
|
||||
}
|
||||
const runId = crypto.randomBytes(16).toString("hex");
|
||||
state.registerRun(runId, {
|
||||
status: "running",
|
||||
@@ -148,7 +190,7 @@ function submitRun(account, plugin, fields, opts) {
|
||||
});
|
||||
licensing.report(account, "", plugin.id, plugin.version || "0", "start");
|
||||
|
||||
void runQueued(plugin, fields, runId, account);
|
||||
void runQueued(plugin, effFields, runId, account);
|
||||
return runId;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user