// Disposable native-provider fixture, launched only on an isolated desktop. const { app, BrowserWindow, ipcMain } = require('electron') const fs = require('node:fs') const path = require('node:path') const dir = process.env.BENCH_STATE_DIR const instance = process.env.BENCH_INSTANCE process.on('uncaughtException', (error) => { console.error(error) app.exit(1) }) if (process.env.ORCA_COMPUTER_BENCH_ISOLATED !== '1') { process.exit(1) } app.whenReady().then(() => { const w = new BrowserWindow({ x: 60, y: 60, width: 760, height: 560, title: 'BenchElectron', webPreferences: { nodeIntegration: true, contextIsolation: false, backgroundThrottling: false } }) const nativeWindowId = process.platform === 'linux' ? w.getNativeWindowHandle().readUInt32LE() : null ipcMain.on('st', (_event, state) => { const data = JSON.stringify({ ...state, instance, activeForm: w.isFocused(), pid: process.pid, nativeWindowId }) try { fs.writeFileSync(path.join(dir, 'state.json.tmp'), data) fs.renameSync(path.join(dir, 'state.json.tmp'), path.join(dir, 'state.json')) } catch (error) { // Windows readers can briefly deny replacement; the next state tick retries. if (!['EACCES', 'EPERM', 'EBUSY'].includes(error.code)) { throw error } } }) w.loadURL( `data:text/html,${encodeURIComponent(`BenchElectron `)}` ) if (process.env.BENCH_FOCUS_SIBLING === '1') { const sibling = new BrowserWindow({ x: 400, y: 300, width: 300, height: 200, title: 'BenchSibling' }) sibling.loadURL('data:text/html,BenchSibling') w.on('closed', () => sibling.close()) } setInterval(() => { const cmdPath = path.join(dir, 'cmd') if (!fs.existsSync(cmdPath)) { return } const raw = fs.readFileSync(cmdPath, 'utf8').trim() if (raw) { const cmd = JSON.parse(raw) fs.unlinkSync(cmdPath) if (cmd.instance === instance) { w.webContents.send('cmd', cmd) } } }, 30) })