// main.js const { app, BrowserWindow, ipcMain } = require("electron"); const path = require("path"); const { spawn } = require("child_process"); let mainWindow; function createWindow() { mainWindow = new BrowserWindow({ width: 800, height: 600, webPreferences: { nodeIntegration: true, contextIsolation: false, }, }); mainWindow.loadFile("index.html"); } app.whenReady().then(createWindow); ipcMain.on("select-iso", (event) => { dialog .showOpenDialog(mainWindow, { properties: ["openFile"], filters: [{ name: "ISO Files", extensions: ["iso"] }], }) .then((result) => { if (!result.canceled) { const isoPath = result.filePaths[0]; event.reply("iso-selected", isoPath); } }); }); ipcMain.on("create-template", (event, { isoPath, outputPath, size }) => { const qemuImg = spawn("qemu-img", [ "create", "-f", "qcow2", "-b", isoPath, outputPath, size, ]); qemuImg.stdout.on("data", (data) => { console.log(`stdout: ${data}`); }); qemuImg.stderr.on("data", (data) => { console.error(`stderr: ${data}`); }); qemuImg.on("close", (code) => { console.log(`child process exited with code ${code}`); event.reply("template-created", outputPath); }); }); ipcMain.on("join-cluster", (event, clusterConfig) => { // Spawn a QEMU process to run the VM as a Kubernetes node const qemuProcess = spawn("qemu-system-x86_64", [ "-m", clusterConfig.memory, "-smp", clusterConfig.cpus, "-hda", "kubernetes-node.qcow2", // Add more QEMU options as needed ]); // Handle QEMU process events and communicate with the renderer process qemuProcess.stdout.on("data", (data) => { mainWindow.webContents.send("qemu-output", data.toString()); }); qemuProcess.stderr.on("data", (data) => { mainWindow.webContents.send("qemu-error", data.toString()); }); qemuProcess.on("close", (code) => { mainWindow.webContents.send("qemu-exit", code); }); });