ipc Livetalking

戴潇逸 1 month ago
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
});

29
package-lock.json generated

@ -1,12 +1,12 @@
{
"name": "live-digital-avatar",
"version": "1.0.0",
"version": "0.1.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "live-digital-avatar",
"version": "1.0.0",
"version": "0.1.0",
"hasInstallScript": true,
"license": "MIT",
"dependencies": {
@ -4031,9 +4031,10 @@
},
"node_modules/@iconify/types": {
"version": "2.0.0",
"resolved": "https://registry.npmmirror.com/@iconify/types/-/types-2.0.0.tgz",
"resolved": "http://mirrors.cloud.tencent.com/npm/@iconify/types/-/types-2.0.0.tgz",
"integrity": "sha512-+wluvCrRhXrhyOmRDJ3q8mux9JkKy5SJ/v8ol2tu4FVjyYvtEzkc/3pK15ET6RKg4b4w4BmTk1+gsCUhf21Ykg==",
"dev": true
"dev": true,
"license": "MIT"
},
"node_modules/@iconify/vue": {
"version": "4.3.0",
@ -5925,15 +5926,17 @@
},
"node_modules/@types/estree": {
"version": "1.0.8",
"resolved": "https://registry.npmmirror.com/@types/estree/-/estree-1.0.8.tgz",
"resolved": "http://mirrors.cloud.tencent.com/npm/@types/estree/-/estree-1.0.8.tgz",
"integrity": "sha512-dWHzHa2WqEXI/O1E9OjrocMTKJl2mSrEolh1Iomrv6U+JuNwaHXsXx9bLu5gG7BUWFIN0skIQJQ/L1rIex4X6w==",
"devOptional": true
"devOptional": true,
"license": "MIT"
},
"node_modules/@types/http-cache-semantics": {
"version": "4.0.4",
"resolved": "https://registry.npmmirror.com/@types/http-cache-semantics/-/http-cache-semantics-4.0.4.tgz",
"resolved": "http://mirrors.cloud.tencent.com/npm/@types/http-cache-semantics/-/http-cache-semantics-4.0.4.tgz",
"integrity": "sha512-1m0bIFVc7eJWyve9S0RnuRgcQqF/Xd5QsUZAZeQFr1Q3/p9JWoQQEqmVy+DPTNpGXwhgIetAoYF8JSc33q29QA==",
"dev": true
"dev": true,
"license": "MIT"
},
"node_modules/@types/js-cookie": {
"version": "3.0.6",
@ -5943,9 +5946,10 @@
},
"node_modules/@types/json-schema": {
"version": "7.0.15",
"resolved": "https://registry.npmmirror.com/@types/json-schema/-/json-schema-7.0.15.tgz",
"resolved": "http://mirrors.cloud.tencent.com/npm/@types/json-schema/-/json-schema-7.0.15.tgz",
"integrity": "sha512-5+fP8P8MFNC+AyZCDxrB2pkZFPGzqQWUzpSeuuVLvm8VMcorNYavBqoFcxK8bQz4Qsbn4oUEEem4wDLfcysGHA==",
"dev": true
"dev": true,
"license": "MIT"
},
"node_modules/@types/mockjs": {
"version": "1.0.10",
@ -5955,9 +5959,10 @@
},
"node_modules/@types/ms": {
"version": "2.1.0",
"resolved": "https://registry.npmmirror.com/@types/ms/-/ms-2.1.0.tgz",
"resolved": "http://mirrors.cloud.tencent.com/npm/@types/ms/-/ms-2.1.0.tgz",
"integrity": "sha512-GsCCIZDE/p3i96vtEqx+7dBUGXrc7zeSK3wwPHIaRThS+9OhWIXRqzs4d6k1SVU8g91DrNRWxWUGhp5KXQb2VA==",
"dev": true
"dev": true,
"license": "MIT"
},
"node_modules/@types/node": {
"version": "20.19.9",

@ -1,14 +1,17 @@
{
"name": "live-digital-avatar",
"version": "1.0.0",
"version": "0.1.0",
"type": "commonjs",
"main": "electron/main.js",
"description": "直播数字人",
"author": "SST",
"main": "electron/electron-main.cjs",
"private": true,
"scripts": {
"dev": "NODE_OPTIONS=--max-old-space-size=4096 vite",
"serve": "pnpm dev",
"build": "vite build",
"build:staging": "rimraf dist && vite build --mode staging",
"package": "npm run build:ui && electron-builder build --win",
"report": "rimraf dist && vite build",
"preview": "vite preview",
"preview:build": "pnpm build && vite preview",
@ -28,34 +31,42 @@
"electron:build": "vite build && electron-builder"
},
"build": {
"appId": "com.example.myapp",
"productName": "My Electron App",
"directories": {
"output": "dist-electron"
"electronDownload": {
"mirror": "https://npmmirror.com/mirrors/electron/"
},
"appId": "live.digital.avatar.web",
"productName": "LiveDigitalAvatar",
"asar": true,
"files": [
"dist/**/*",
"electron/**/*",
"node_modules/**/*",
"dist/**",
"electron/electron-main.cjs",
"electron/preload.cjs",
"package.json"
],
"extraResources": [
{
"from": "Livetalking/",
"to": "Livetalking/",
"filter": [
"**/*"
]
}
],
"win": {
"target": [
"nsis",
"portable"
{
"target": "zip",
"arch": [
"x64"
]
}
],
"icon": "public/icon.ico",
"verifyUpdateCodeSignature": false,
"signAndEditExecutable": false,
"requestedExecutionLevel": "asInvoker"
"icon": "public/icon.ico"
},
"nsis": {
"oneClick": false,
"allowToChangeInstallationDirectory": true,
"installerIcon": "public/icon1.ico",
"uninstallerIcon": "public/icon2.ico",
"createDesktopShortcut": true,
"createStartMenuShortcut": true
"perMachine": false
}
},
"browserslist": [
@ -76,6 +87,7 @@
"axios": "^1.4.0",
"buffer": "^6.0.3",
"dayjs": "^1.11.8",
"electron-is-dev": "^3.0.1",
"element-plus": "2.3.6",
"fetch-event-source": "1.0.0-alpha.2",
"hls.js": "^1.6.7",

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…
Cancel
Save