1 Star 0 Fork 0

王英伟/test_audioWaveform

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
main.js 2.02 KB
一键复制 编辑 原始数据 按行查看 历史
王英伟 提交于 2024-06-12 17:07 . add multi-thread
const { app, BrowserWindow, ipcMain } = require('electron');
const { spawn } = require('child_process');
const path = require('path');
const { Worker } = require('worker_threads');
// app.disableHardwareAcceleration();
let mainWindow;
function createWindow() {
mainWindow = new BrowserWindow({
width: 2400,
height: 1200,
webPreferences: {
nodeIntegration: true,
contextIsolation: false,
},
});
const startUrl = app.isPackaged
? `file://${path.join(process.resourcesPath, 'index.html')}`
: `file://${path.join(__dirname, 'index.html')}`;
mainWindow.loadURL(startUrl);
mainWindow.webContents.openDevTools();
}
app.whenReady().then(() => {
createWindow();
const scriptPath = app.isPackaged
? path.join(process.resourcesPath, 'random_number_generator.py')
: path.join(__dirname, 'random_number_generator.py');
const pythonProcess = spawn('python3', [scriptPath]);
pythonProcess.stdout.on('data', (data) => {
const randomNumber = parseInt(data.toString().trim(), 10);
mainWindow.webContents.send('random-number', randomNumber);
});
pythonProcess.stderr.on('data', (data) => {
console.error(`Python script error: ${data}`);
});
pythonProcess.on('close', (code) => {
console.log(`Python script exited with code ${code}`);
});
});
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit();
}
});
app.on('activate', () => {
if (BrowserWindow.getAllWindows().length === 0) {
createWindow();
}
});
// const workerCount = 6;
// let workers = [];
// for (let i = 0; i < workerCount; i++) {
// const worker = new Worker(path.join(__dirname, 'worker.js'), {
// workerData: { index: i }
// });
// worker.on('message', (data) => {
// mainWindow.webContents.send('render-frame', data);
// });
// workers.push(worker);
// }
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
JavaScript
1
https://gitee.com/Dr_tree/test_audio-waveform.git
git@gitee.com:Dr_tree/test_audio-waveform.git
Dr_tree
test_audio-waveform
test_audioWaveform
master

搜索帮助