const path = require('path'); const { app, BrowserWindow, ipcMain } = require('electron'); const isDev = require('electron-is-dev'); const { spawn } = require('child_process'); const iconv = require('iconv-lite'); function createWindow() { const win = new BrowserWindow({ width: 1920, height: 1080, webPreferences: { preload: path.join(__dirname, 'preload.cjs') } }); win.loadFile(path.join(__dirname, '../dist/index.html')); win.webContents.openDevTools() } app.whenReady().then(createWindow); app.on('window-all-closed', () => { if (process.platform !== 'darwin') app.quit(); }); ipcMain.on('launch-live-talking', () => { // Determine folder and path of LiveTalking.exe const exeFolder = isDev ? path.join(__dirname, '../../Livetalking') : path.join(process.resourcesPath, 'Livetalking'); const exePath = path.join(exeFolder, 'LiveTalking.exe'); console.log('[Main] Launching LiveTalking.exe at:', exePath); // Spawn a new terminal window to run the exe in its own working directory const child = spawn('cmd.exe', ['/c', 'start', '""', `"${exePath}"`], { cwd: exeFolder, windowsVerbatimArguments: true, windowsHide: false, detached: true }); child.unref(); // Decode stderr (GBK) and log child.stderr.on('data', (data) => { console.error(iconv.decode(data, 'gbk')); }); // Handle spawn errors child.on('error', (err) => { console.error('Error spawning LiveTalking:', err); }); // Log exit status child.on('exit', (code, signal) => { console.log(`LiveTalking exited with code ${code}, signal ${signal}`); }); });