electron-vue进程的主线程CPU总是冲高,界面上也没有做任何操作
top看到的结果和src/main/index.js的代码如下,请问究竟是什么地方在耗CPU?
top - 15:03:51 up 9 days, 21:30, 6 users, load average: 1.75, 1.62, 1.62
Threads: 19 total, 1 running, 18 sleeping, 0 stopped, 0 zombie
%Cpu(s): 54.5 us, 14.1 sy, 0.0 ni, 30.8 id, 0.0 wa, 0.0 hi, 0.5 si, 0.0 st
KiB Mem: 1873536 total, 1742908 used, 130628 free, 4536 buffers
KiB Swap: 1776636 total, 385540 used, 1391096 free. 69804 cached Mem
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
2108 desktop+ 20 0 2588888 1.401g 18244 R 99.9 78.4 14094:42 hsr-receiver
2186 desktop+ 20 0 2588888 1.401g 18244 S 3.0 78.4 387:44.34 hsr-receiver
2187 desktop+ 20 0 2588888 1.401g 18244 S 3.0 78.4 387:44.52 hsr-receiver
2184 desktop+ 20 0 2588888 1.401g 18244 S 2.7 78.4 387:43.88 hsr-receiver
2185 desktop+ 20 0 2588888 1.401g 18244 S 2.7 78.4 387:44.94 hsr-receiver
2145 desktop+ 20 0 2588888 1.401g 18244 S 1.0 78.4 91:38.58 hsr-receiver
11627 desktop+ 20 0 2588888 1.401g 18244 S 0.3 78.4 0:02.21 WorkerPool/1162
20349 desktop+ 20 0 2588888 1.401g 18244 S 0.3 78.4 0:00.73 WorkerPool/2034
24633 desktop+ 20 0 2588888 1.401g 18244 S 0.3 78.4 0:00.01 WorkerPool/2463
2115 desktop+ 20 0 2588888 1.401g 18244 S 0.0 78.4 0:00.00 TaskSchedulerSe
2116 desktop+ 20 0 2588888 1.401g 18244 S 0.0 78.4 4:39.01 Chrome_ChildIOT
2117 desktop+ 20 0 2588888 1.401g 18244 S 0.0 78.4 0:23.91 GpuMemoryThread
2126 desktop+ 20 0 2588888 1.401g 18244 S 0.0 78.4 10:13.03 Compositor
2127 desktop+ 20 0 2588888 1.401g 18244 S 0.0 78.4 0:00.00 Renderer::FILE
2128 desktop+ 20 0 2588888 1.401g 18244 S 0.0 78.4 7:52.22 CompositorTileW
2129 desktop+ 30 10 2588888 1.401g 18244 S 0.0 78.4 0:00.00 CompositorTileW
14486 desktop+ 20 0 2588888 1.401g 18244 S 0.0 78.4 0:01.30 WorkerPool/1448
20348 desktop+ 20 0 2588888 1.401g 18244 S 0.0 78.4 0:00.98 WorkerPool/2034
23213 desktop+ 20 0 2588888 1.401g 18244 S 0.0 78.4 0:00.32 WorkerPool/2321
import { app, BrowserWindow, globalShortcut, dialog, ipcMain} from 'electron'
/**
* Set `__static` path to static files in production
* https://simulatedgreg.gitbooks.io/electron-vue/content/en/using-static-assets.html
*/
if (process.env.NODE_ENV !== 'development') {
global.__static = require('path').join(__dirname, '/static').replace(/\\/g, '\\\\')
}
let mainWindow
const winURL = process.env.NODE_ENV === 'development'
? `http://localhost:9080`
: `file://${__dirname}/index.html`
function createWindow () {
/**
* Initial window options
*/
mainWindow = new BrowserWindow({
height: 1080,
width: 1920,
center: true,
// show:false,
useContentSize: true,
fullscreen: true,//是否全屏
fullscreenable: false,//是否允许全屏
frame: false,//标题栏和边框一并隐藏
resizable: false, // 是否允许拉伸大小
webPreferences: {webSecurity: false}, // 可实现跨域
backgroundColor: '#000000'
})
// mainWindow.on('resize', updateReply)
mainWindow.loadURL(winURL)
mainWindow.on('closed', () => {
mainWindow = null
})
// mainWindow.once('ready-to-show', () => {
// mainWindow.show()
// })
}
// function updateReply () {
// const mangageWindowReply = document.getElementById('manage-window-reply')
// const message = `Size: ${mainWindow.getSize()} Position: ${mainWindow.getPosition()}`
// mangageWindowReply.innerText = message
// }
app.on('ready', createWindow)
//拦截系统快捷键
app.on('ready', function() {
globalShortcut.register('shift+enter', function () {
// dialog.showMessageBox({
// type: 'warning',
// message: '确定返回ubuntu系统?',
// defaultId: 0,
// detail: '你按下了一个全局注册的快捷键绑定ctrl+j+m.',
// buttons: ['提交','取消']
// },function(response){
// if(response === 0){
// //最小化
// mainWindow.close()
// }
// console.log(response)
// })
return
});
});
//最小化
ipcMain.on('min-window', () => {
// mainWindow.close();
app.quit();
});
//获取焦点
ipcMain.on('focus-window', () => {
if (mainWindow) {
if (mainWindow.isMinimized()){
mainWindow.restore();
};
mainWindow.focus();
};
});
//释放焦点,让其他窗口可以获得键盘输入
ipcMain.on('refresh-window', () => {
mainWindow.hide();
mainWindow.show();
});
app.on('will-quit', function () {
globalShortcut.unregisterAll()
})
//确保单实例
const shouldQuit = app.makeSingleInstance((commandLine, workingDirectory) => {
if (mainWindow) {
if (mainWindow.isMinimized()){
mainWindow.restore();
};
mainWindow.focus();
};
});
if (shouldQuit) {
app.quit();
};
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit()
}
})
app.on('activate', () => {
if (mainWindow === null) {
createWindow()
}
})
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
electron 新版本开发环境存在cpu100%,打包后是没问题的