refactor: 重构执行机架构为 Electron 壳内置 Python 运行时子集
将原 webhost 底座的后端、前端、工具等代码迁移至 electron-shell 目录,构建自包含的 Python 环境包,移除冗余的前端代码、旧的后端模块及相关依赖,更新版本号至 1.0.6,优化平台登录态预检逻辑,统一代码结构为单一真源,避免多副本维护问题。
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
// 37du Electron 壳:配置固化(.env 加载 + 路径 + 常量)
|
||||
// 对齐 Python webhost backend/core/config.py 的语义与路径约定。
|
||||
"use strict";
|
||||
|
||||
const fs = require("fs");
|
||||
@@ -17,9 +16,8 @@ const IS_FROZEN =
|
||||
// 本模块目录:desktop/electron-shell/electron → parents
|
||||
const SHELL_ROOT = path.resolve(__dirname, "..");
|
||||
|
||||
// 仓库根:electron/../.. = 37duAutomation(dev 模式定位 plugins/ 与 webhost 参考实现)
|
||||
// 仓库根:electron/../.. = 37duAutomation(dev 模式定位 plugins/)
|
||||
const REPO_ROOT = path.resolve(SHELL_ROOT, "..", "..");
|
||||
const DESKTOP_ROOT = path.resolve(SHELL_ROOT, "..");
|
||||
|
||||
// ==================== 轻量 .env 加载(仅本模块目录,变量已存在则不覆盖) ====================
|
||||
function loadDotEnv() {
|
||||
@@ -129,14 +127,14 @@ function pythonExe() {
|
||||
return "python";
|
||||
}
|
||||
|
||||
// 运行时根(webhost 包所在目录):环境包模式 = 环境包根;否则 = desktop/(dev,webhost 在仓库内)
|
||||
// 运行时根(webhost 包所在目录):环境包模式 = 环境包根;否则 = 壳内置 python/(vendor 子集)
|
||||
function runtimeRoot() {
|
||||
const envRoot = pythonEnvRoot();
|
||||
if (envRoot) return envRoot;
|
||||
return DESKTOP_ROOT;
|
||||
return path.join(SHELL_ROOT, "python");
|
||||
}
|
||||
|
||||
// 插件执行入口:环境包模式 = 环境包内 plugin_runner.py;打包态 = exe 同级;dev = 仓库 webhost
|
||||
// 插件执行入口:环境包模式 = 环境包内 plugin_runner.py;打包态 = exe 同级;dev = 壳内置 python/
|
||||
function runnerScript() {
|
||||
if (process.env.SHELL_RUNNER_SCRIPT) return process.env.SHELL_RUNNER_SCRIPT;
|
||||
const envRoot = pythonEnvRoot();
|
||||
@@ -144,7 +142,7 @@ function runnerScript() {
|
||||
if (IS_FROZEN) {
|
||||
return path.join(path.dirname(process.execPath), "plugin_runner.py");
|
||||
}
|
||||
return path.join(DESKTOP_ROOT, "webhost", "backend", "core", "plugin_runner.py");
|
||||
return path.join(SHELL_ROOT, "python", "webhost", "backend", "core", "plugin_runner.py");
|
||||
}
|
||||
|
||||
// Job Object 守护(环境包模式启用内存上限 + 整树托管):无环境包返回 ""
|
||||
@@ -154,18 +152,9 @@ function jobGuardScript() {
|
||||
return "";
|
||||
}
|
||||
|
||||
// 前端静态资源:壳自带 renderer/dist(可单独拷贝);dev 兜底复用 webhost 构建产物
|
||||
// 前端静态资源:壳自带 renderer/dist(自包含;缺失时先跑 scripts/copy-renderer.ps1 构建)
|
||||
function frontendDist() {
|
||||
const own = path.join(SHELL_ROOT, "renderer", "dist");
|
||||
if (fs.existsSync(path.join(own, "index.html"))) return own;
|
||||
const legacy = path.join(DESKTOP_ROOT, "webhost", "frontend", "dist");
|
||||
if (fs.existsSync(path.join(legacy, "index.html"))) return legacy;
|
||||
return own;
|
||||
}
|
||||
|
||||
// 平台登录子进程:spawn python <shared 模块>(webhost.backend.shared.hr_login/oa_login)
|
||||
function sharedModule(moduleName) {
|
||||
return path.join(DESKTOP_ROOT, "webhost", "backend", "shared", `${moduleName}.py`);
|
||||
return path.join(SHELL_ROOT, "renderer", "dist");
|
||||
}
|
||||
|
||||
// 敏感凭证中心化下发:进程级覆盖存储(唯一来源:中心机下发 / 本地加密缓存)
|
||||
@@ -185,7 +174,6 @@ function getCred(name) {
|
||||
module.exports = {
|
||||
SHELL_ROOT,
|
||||
REPO_ROOT,
|
||||
DESKTOP_ROOT,
|
||||
PORT,
|
||||
APP_DATA,
|
||||
PLUGIN_CONFIG_DIR,
|
||||
@@ -199,7 +187,6 @@ module.exports = {
|
||||
pluginRoot,
|
||||
runnerScript,
|
||||
frontendDist,
|
||||
sharedModule,
|
||||
runtimeVersion,
|
||||
applyCreds,
|
||||
getCred,
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
// 平台登录态(HR/OA):真实登录/登出/在线校验。
|
||||
// 保持 Python 子进程执行登录自动化(shared/hr_login、oa_login,DrissionPage 滑块),
|
||||
// 保持 Python 子进程执行登录自动化(壳内置 python/webhost/backend/shared 下的
|
||||
// hr_login、oa_login,DrissionPage 滑块;自包含 vendor,不依赖老 webhost 底座),
|
||||
// Node 壳只负责拉起子进程与解析结果。
|
||||
// ★ 按账号隔离:每个登录账号拥有独立的会话目录(.sessions/<账号>/)与独立 HR/OA 账号密码,
|
||||
// 子进程通过 PLATFORM_ACCOUNT 环境变量 + hr_login_username/password 注入各自身份。
|
||||
|
||||
@@ -13,6 +13,7 @@ const state = require("./state");
|
||||
const scheduler = require("./scheduler");
|
||||
const licensing = require("./licensing");
|
||||
const runHistory = require("./run-history");
|
||||
const platformAuth = require("./platform-auth");
|
||||
const { HUB } = require("./hub");
|
||||
const { makeLogger } = require("./logger");
|
||||
|
||||
@@ -66,6 +67,28 @@ function nsKey(account, platform) {
|
||||
return `${account || "anon"}:${platform || "local"}`;
|
||||
}
|
||||
|
||||
// 平台登录态预检(HR/OA):插件执行前检测该账号的平台登录态,
|
||||
// 失效时自动拉起自动登录(platform-auth.login,Python 子进程滑块自动化;
|
||||
// cookies 实际有效时不会弹浏览器)。登录成功继续执行,失败则本次运行报错,
|
||||
// 提示用户去个人中心手动登录(手动登录入口保留,不冲突)。
|
||||
// 在(账号, 平台)命名空间锁内调用,天然避免并发双开登录浏览器。
|
||||
const PLATFORM_LABELS = { hr: "HR 系统", oa: "OA 系统" };
|
||||
async function ensurePlatformSession(plugin, runId, account) {
|
||||
const pid = plugin.platform;
|
||||
if (!pid || !PLATFORM_LABELS[pid]) return; // 无平台要求(或未知平台)直接执行
|
||||
if (await platformAuth.isOnline(pid, account)) return; // 登录态有效,直接执行
|
||||
if (isUserStopped(runId)) throw new Error("用户已取消该排队任务");
|
||||
const label = PLATFORM_LABELS[pid];
|
||||
emitLog(runId, plugin.id, "INFO", `检测到${label}登录态失效,正在自动登录…(如需人工介入请观察弹出的浏览器窗口)`);
|
||||
const r = await platformAuth.login(pid, account);
|
||||
if (isUserStopped(runId)) throw new Error("用户已取消该排队任务"); // 登录期间用户点了停止
|
||||
if (!r || !r.online) {
|
||||
const msg = (r && r.message) || "登录未生效";
|
||||
throw new Error(`${label}自动登录失败:${msg}。请在「个人中心 → 平台账号」手动登录后重试`);
|
||||
}
|
||||
emitLog(runId, plugin.id, "INFO", `${label}自动登录成功,开始执行插件`);
|
||||
}
|
||||
|
||||
// 发布日志事件,并同步累积到"这一次运行"的记录里(结束后随运行历史落盘,供点击回放)
|
||||
function emitLog(runId, pluginId, level, msg) {
|
||||
const text = String(msg === undefined || msg === null ? "" : msg);
|
||||
@@ -206,6 +229,8 @@ async function runQueued(plugin, fields, runId, account) {
|
||||
// 排队期间用户已点停止:不真正拉起插件
|
||||
throw new Error("用户已取消该排队任务");
|
||||
}
|
||||
// 平台登录态预检:HR/OA 失效时自动登录(手动登录入口保留)
|
||||
await ensurePlatformSession(plugin, runId, account);
|
||||
await startChild(plugin, fields, runId, account);
|
||||
return runId;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user