// 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), };