diff --git a/src/main/index.js b/src/main/index.js index 2ce4c67..ac2ef6e 100644 --- a/src/main/index.js +++ b/src/main/index.js @@ -3,7 +3,22 @@ import { join } from 'path' import { electronApp, optimizer, is } from '@electron-toolkit/utils' import icon from '../../resources/icon.png?asset' -app.commandLine.appendSwitch('disable-web-security'); +//关闭exe命令 +function killProcessByName(processName) { + const command = `taskkill /IM ${processName} /F` + const { exec } = require('child_process') + + exec(command, (error, stdout, stderr) => { + if (error) { + console.error(`执行的错误: ${error}`) + return + } + console.log(`stdout: ${stdout}`) + console.error(`stderr: ${stderr}`) + }) +} + +app.commandLine.appendSwitch('disable-web-security') function createWindow() { // Create the browser window. const mainWindow = new BrowserWindow({ @@ -11,7 +26,6 @@ function createWindow() { height: 700, show: false, autoHideMenuBar: true, - // ...(process.platform === 'linux' ? { icon } : {}), icon, webPreferences: { preload: join(__dirname, '../preload/index.js'), @@ -60,38 +74,47 @@ if (!gotTheLock) { app.quit() } else { // 如果检测到有同样的该程序正在试图启动... - app.on( - 'second-instance', - (event, commandLine, workingDirectory, additionalData) => { - if (myWindow) { - // 弹出系统提示对话框 - dialog.showMessageBox({ - message: '此程序已经正在运行', - }) - // 如果该程序窗口处于最小化状态,则恢复窗口 - if (myWindow.isMinimized()) myWindow.restore() - // 将该程序窗口置为当前聚焦态 - myWindow.focus() - } + app.on('second-instance', () => { + if (myWindow) { + // 弹出系统提示对话框 + dialog.showMessageBox({ + message: '此程序已经正在运行' + }) + // 如果该程序窗口处于最小化状态,则恢复窗口 + if (myWindow.isMinimized()) myWindow.restore() + // 将该程序窗口置为当前聚焦态 + myWindow.focus() } - ) + }) // This method will be called when Electron has finished // initialization and is ready to create browser windows. // Some APIs can only be used after this event occurs. + const { spawn } = require('child_process') + let child = null + let exePluginsExeList = [] app.whenReady().then(() => { - - const { spawn } = require('child_process') const fs = require('fs') const path = require('path') const logStream = fs.createWriteStream('app.log', { flags: 'a' }) // 日志文件 let exePath = path.resolve('./resources/app.asar.unpacked/resources/plugin-test') + let exePluginsPath = path.resolve('./resources/app.asar.unpacked/resources/plugin-test/plugins') if (process.env.NODE_ENV === 'development') { exePath = path.resolve('./resources/plugin-test') + exePluginsPath = path.resolve('./resources/plugin-test/plugins') } - const child = spawn('./main.exe', [], { cwd: exePath, stdio: ['ignore', 'pipe', 'pipe'] }) + //查询所有插件目录下的exe文件 + fs.readdir(exePluginsPath, (err, files) => { + if (err) { + return console.log('Unable to scan directory: ' + err) + } + // 筛选出以.exe结尾的文件 + exePluginsExeList = files.filter((file) => path.extname(file).toLowerCase() === '.exe') + }) + + child = spawn('./main.exe', [], { cwd: exePath, stdio: ['ignore', 'pipe', 'pipe'] }) child.stdout.on('data', (data) => { console.log('stdout:', data.toString()) @@ -108,6 +131,11 @@ if (!gotTheLock) { logStream.end() }) + child.on('exit', (code, signal) => { + console.log(`子进程已退出,退出码 ${code},信号: ${signal}`) + logStream.write(`子进程已退出,退出码 ${code},信号: ${signal}`) + logStream.end() + }) // Set app user model id for windows electronApp.setAppUserModelId('com.electron') @@ -124,7 +152,7 @@ if (!gotTheLock) { myWindow = createWindow() - app.on('activate', function() { + app.on('activate', function () { // On macOS it's common to re-create a window in the app when the // dock icon is clicked and there are no other windows open. if (BrowserWindow.getAllWindows().length === 0) createWindow() @@ -136,6 +164,14 @@ if (!gotTheLock) { // explicitly with Cmd + Q. app.on('window-all-closed', () => { if (process.platform !== 'darwin') { + // 循环关闭插件 EXE 列表 + exePluginsExeList.forEach((exe) => { + killProcessByName(exe) + }) + // child.kill('SIGTERM'); // 或者使用 'SIGKILL' 来强制关闭 + // killProcessByName('gateway.exe'); + // 循环关闭后端服务 + killProcessByName('main.exe') app.quit() } }) diff --git a/src/renderer/src/components/Aside.vue b/src/renderer/src/components/Aside.vue index 78a549e..d18e082 100644 --- a/src/renderer/src/components/Aside.vue +++ b/src/renderer/src/components/Aside.vue @@ -13,11 +13,11 @@ const settings = defineProps({ - 断路器调试 + 断路器调试 @@ -35,10 +35,11 @@ const settings = defineProps({ } .el-menu{ background: #f6f6f6; + padding: 0 10px; } .el-menu-item{ - padding: 0 10px; border-radius: 10px; + /*padding-left: 5px !important;*/ } .el-menu-item.is-active{ background: #c8cde4; diff --git a/src/renderer/src/views/HomeView.vue b/src/renderer/src/views/HomeView.vue index 724c6d3..33334fc 100644 --- a/src/renderer/src/views/HomeView.vue +++ b/src/renderer/src/views/HomeView.vue @@ -7,7 +7,7 @@ import Aside from '@renderer/components/Aside.vue'
- +