diff --git a/src/main/app.ts b/src/main/app.ts index 58877e4..c745e9f 100644 --- a/src/main/app.ts +++ b/src/main/app.ts @@ -1,4 +1,4 @@ -import { ipcMain, app, screen, globalShortcut, BrowserWindow, dialog } from 'electron' +import { ipcMain, app, screen, globalShortcut, BrowserWindow, dialog, crashReporter } from 'electron' import { join } from "path"; const config = require('./config') import './load-serialport' @@ -6,6 +6,7 @@ import { keyword } from './KeyWord' const child_process = require('child_process') const crypto = require('crypto') +const fs = require('fs') function queryPass(passPath: string, passValue: string) { return new Promise(function (resolve, reject) { @@ -67,6 +68,23 @@ async function checkLaunchEnv() { } } +// 记录崩溃信息 +function recordCrash() { + return new Promise(resolve => { + // 崩溃日志请求成功.... + resolve(); + }) +} + +function abnormalLog(txtName: string, txtLog: string) { + fs.writeFile(txtName, txtLog, (ero:any) => { + if(ero){ + console.log(`创建失败:${ero}`); + } + console.log(`创建成功!`); + }); +} + var windows:Array = []; function createWindow(page: string, display: any) { @@ -77,7 +95,8 @@ function createWindow(page: string, display: any) { y: display.bounds.y, webPreferences: { nodeIntegration: true, - preload: join(__dirname, 'preload.js') + preload: join(__dirname, 'preload.js'), + webgl: true } }) @@ -90,6 +109,45 @@ function createWindow(page: string, display: any) { } }) + ipcMain.on("webglcontextlost", (event) => { + abnormalLog(`./resources/webglcontextlost${new Date().getTime()}.txt`, `webglcontextlost: ${new Date()}`); + }) + + ipcMain.on("refresh", (event) => { + abnormalLog(`./resources/refresh${new Date().getTime()}.txt`, `refresh: ${new Date()}`); + }) + + // 监听到软件奔溃时执行 + win.webContents.on('crashed', () => { + console.log('crash'); + // const options = dialog.showMessageBox({ + // type: 'error', + // title: '进程崩溃了', + // message: '这个进程已经崩溃.', + // buttons: ['重载', '退出'], + // }); + recordCrash().then(() => { + abnormalLog(`./resources/crash${new Date().getTime()}.txt`, `crash: ${new Date()}`); + // options.then((index) => { + // if (index.response === 0) { + // if (win.isDestroyed()) { + // app.relaunch(); + // app.exit(0); + // } else { + // BrowserWindow.getAllWindows().forEach((w) => { + // if (w.id !== win.id) w.destroy(); + // }); + // win.reload(); + // } + // } + // else app.quit(); + // }); + }).catch((e) => { + console.log('err', e); + abnormalLog(`./resources/crash${new Date().getTime()}.txt`, `crash: ${new Date()}, err: ${e}`); + }); + }) + if (process.env.NODE_ENV === 'development') { win.loadURL(`http://localhost:3000/${page}.html`) win.webContents.openDevTools() @@ -165,12 +223,25 @@ async function main() { // 异步代码执行完毕后执行的代码 if (checkReault) { launch() + // 模拟软件崩溃 + // setTimeout(() => { + // process.crash(); + // }, 10000); } else { dialog.showErrorBox('系统提示', '软件启动出错,请联系售后技术支持人员') process.exit(1) } } +crashReporter.start({uploadToServer: false}) + +app.commandLine.appendSwitch('ignore-gpu-blacklist') + +app.disableDomainBlockingFor3DAPIs() + +// 禁用GPU加速,此模式下何时刷新canvas不能通过判断webgl上下文丢失实现 +// app.disableHardwareAcceleration() + app.whenReady().then(main) app.on('window-all-closed', () => { diff --git a/src/render/components/Ring.vue b/src/render/components/Ring.vue index f2ce857..750bf3a 100644 --- a/src/render/components/Ring.vue +++ b/src/render/components/Ring.vue @@ -1,5 +1,5 @@