// 无头测试用的 electron 桩: 只提供 src/main 里真正用到的 API // (app.getPath / app.getVersion / BrowserWindow / ipcMain / shell ...) const os = require('node:os') const path = require('node:path') const fs = require('node:fs') const root = process.env.LNM_SELFTEST_HOME || path.join(os.tmpdir(), 'lnm-selftest') fs.mkdirSync(root, { recursive: true }) function ensure(p) { fs.mkdirSync(p, { recursive: true }) return p } module.exports = { app: { isPackaged: false, getPath(name) { if (name === 'userData') return ensure(path.join(root, 'userData')) if (name === 'documents') return ensure(path.join(root, 'documents')) if (name === 'downloads') return ensure(path.join(root, 'downloads')) if (name === 'home') return os.homedir() return ensure(path.join(root, name)) }, getVersion: () => '0.1.0', getName: () => 'local-net-msg', getAppPath: () => process.cwd(), on: () => {}, once: () => {}, whenReady: async () => {}, quit: () => {}, }, BrowserWindow: class BrowserWindow { static getAllWindows() { return [] } static getFocusedWindow() { return null } isMinimized() { return false } restore() {} show() {} focus() {} webContents = { send: () => {} } }, // 注意: 故意不提供 ipcRenderer —— electron-store 见到它会以为是渲染进程 ipcMain: { on: () => {}, once: () => {}, handle: () => {}, removeHandler: () => {} }, contextBridge: { exposeInMainWorld: () => {} }, dialog: { showErrorBox: () => {}, showOpenDialog: async () => ({ canceled: true, filePaths: [] }) }, shell: { openPath: async () => '', showItemInFolder: () => {} }, Notification: class { static isSupported() { return false } constructor() {} show() {} }, }