原 Electron 版在这台 Windows 机器上无法启动(0x80000003 崩在 V8 初始化), 整个业务逻辑用 Go 重写,前端界面与协议结论完全保留。 - internal/eh: 协议核心,画廊页分页 -> /s/ -> hath 直链 -> 下载 - internal/core: 并发引擎 / 状态存储 / 目录模板 / 油猴桥口 - app.go: Wails 绑定层,替代 Electron IPC - frontend/js/api.js: 适配层,renderer.js 一行未改 - 37 个测试,含 httptest 模拟 EH 的端到端链路验证 相比 Electron 版:90MB -> 12.4MB,180MB 内存 -> 27MB,构建 90s -> 2s。 顺带修掉原版代理探测的 bug(永远返回第一个端口,从不等连接结果)。
53 lines
1.8 KiB
JavaScript
53 lines
1.8 KiB
JavaScript
// Wails API 适配层
|
|
//
|
|
// 前端业务代码只用 window.eh.*,这里把它接到 Wails 的 Go bindings 上。
|
|
// 这样以后即便换框架,也只要改这一个文件。
|
|
|
|
const go = () => window.go && window.go.main && window.go.main.App;
|
|
|
|
function requireGo() {
|
|
const g = go();
|
|
if (!g) throw new Error('Wails 后端未就绪');
|
|
return g;
|
|
}
|
|
|
|
window.eh = {
|
|
// ---- 设置 ----
|
|
getSettings: async () => requireGo().GetSettings(),
|
|
setSettings: async (patch) => requireGo().SetSettings(patch),
|
|
previewDir: async (tpl) => requireGo().PreviewDir(tpl),
|
|
placeholders: async () => requireGo().Placeholders(),
|
|
|
|
// ---- 任务 ----
|
|
listTasks: async () => requireGo().ListTasks(),
|
|
addTasks: async (text) => requireGo().AddTasks(text),
|
|
removeTask: async (t) => requireGo().RemoveTask(t.gid, t.token || ''),
|
|
clearFinished: async () => requireGo().ClearFinished(),
|
|
countDone: async () => requireGo().CountDone(),
|
|
clearAll: async (onlySelected) => requireGo().ClearAll(!!onlySelected),
|
|
requeueFailed: async () => requireGo().RequeueFailed(),
|
|
selectAll: async (gids) => requireGo().SelectAll(gids),
|
|
|
|
// ---- 引擎 ----
|
|
status: async () => requireGo().Status(),
|
|
start: async (payload) => {
|
|
const gids = (payload && payload.onlyGids) || [];
|
|
return requireGo().Start(gids);
|
|
},
|
|
stop: async () => requireGo().Stop(),
|
|
|
|
// ---- 系统 ----
|
|
pickDir: async () => requireGo().PickDir(),
|
|
exportFailed: async (gid) => {
|
|
const path = await requireGo().ExportFailed(gid);
|
|
return path ? { ok: true, filePath: path } : { ok: false };
|
|
},
|
|
openPath: async (p) => requireGo().OpenPath(p),
|
|
showItem: async (p) => requireGo().ShowItem(p),
|
|
|
|
// ---- 事件 ----
|
|
onTaskUpdate: (cb) => window.runtime.EventsOn('task:update', cb),
|
|
onLog: (cb) => window.runtime.EventsOn('log', cb),
|
|
onDone: (cb) => window.runtime.EventsOn('engine:done', cb),
|
|
};
|