💥 feat(断路器): 调整侧边菜单样式、默认选中菜单、添加应用程序退出关闭后端服务及插件
This commit is contained in:
parent
9bb8ff8942
commit
7b98fca398
|
@ -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()
|
||||
}
|
||||
})
|
||||
|
|
|
@ -13,11 +13,11 @@ const settings = defineProps({
|
|||
<el-aside :width="settings.width">
|
||||
<el-scrollbar>
|
||||
<el-menu
|
||||
:default-openeds="['1']"
|
||||
default-active="/switch"
|
||||
:collapse="settings.collapse"
|
||||
:router="true"
|
||||
>
|
||||
<el-menu-item index="/switch"><el-icon> <House /> </el-icon>断路器调试</el-menu-item>
|
||||
<el-menu-item index="/switch"><el-icon> <Connection /> </el-icon>断路器调试</el-menu-item>
|
||||
<!-- <el-menu-item index="/about"><el-icon> <Menu /> </el-icon>文章管理列表</el-menu-item>-->
|
||||
<!-- <el-menu-item index="/test"><el-icon> <Menu /> </el-icon>测试</el-menu-item>-->
|
||||
</el-menu>
|
||||
|
@ -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;
|
||||
|
|
|
@ -7,7 +7,7 @@ import Aside from '@renderer/components/Aside.vue'
|
|||
<el-container direction="vertical" style="min-height: 100vh;min-width: 100vw;overflow: hidden;">
|
||||
<Header></Header>
|
||||
<el-container >
|
||||
<Aside width="120"></Aside>
|
||||
<Aside width="160px"></Aside>
|
||||
<el-main>
|
||||
<router-view/>
|
||||
</el-main>
|
||||
|
|
Loading…
Reference in New Issue