ipc Livetalking
parent
7184f4c2ae
commit
201922b2cc
@ -0,0 +1,56 @@
|
||||
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}`);
|
||||
});
|
||||
});
|
@ -0,0 +1,6 @@
|
||||
const { contextBridge, ipcRenderer } = require("electron");
|
||||
|
||||
// 安全地暴露 API 给渲染进程
|
||||
contextBridge.exposeInMainWorld("electronAPI", {
|
||||
launchLiveTalking: () => ipcRenderer.send("launch-live-talking")
|
||||
});
|
@ -1,6 +0,0 @@
|
||||
import { contextBridge } from "electron";
|
||||
|
||||
// 安全地暴露 API 给渲染进程
|
||||
contextBridge.exposeInMainWorld("electronAPI", {
|
||||
// 可以在这里添加需要暴露的 API
|
||||
});
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,6 @@
|
||||
// src/electron-api.d.ts
|
||||
interface Window {
|
||||
electronAPI: {
|
||||
launchLiveTalking: () => void;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue