💥 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 { electronApp, optimizer, is } from '@electron-toolkit/utils'
|
||||||
import icon from '../../resources/icon.png?asset'
|
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() {
|
function createWindow() {
|
||||||
// Create the browser window.
|
// Create the browser window.
|
||||||
const mainWindow = new BrowserWindow({
|
const mainWindow = new BrowserWindow({
|
||||||
|
@ -11,7 +26,6 @@ function createWindow() {
|
||||||
height: 700,
|
height: 700,
|
||||||
show: false,
|
show: false,
|
||||||
autoHideMenuBar: true,
|
autoHideMenuBar: true,
|
||||||
// ...(process.platform === 'linux' ? { icon } : {}),
|
|
||||||
icon,
|
icon,
|
||||||
webPreferences: {
|
webPreferences: {
|
||||||
preload: join(__dirname, '../preload/index.js'),
|
preload: join(__dirname, '../preload/index.js'),
|
||||||
|
@ -60,38 +74,47 @@ if (!gotTheLock) {
|
||||||
app.quit()
|
app.quit()
|
||||||
} else {
|
} else {
|
||||||
// 如果检测到有同样的该程序正在试图启动...
|
// 如果检测到有同样的该程序正在试图启动...
|
||||||
app.on(
|
app.on('second-instance', () => {
|
||||||
'second-instance',
|
|
||||||
(event, commandLine, workingDirectory, additionalData) => {
|
|
||||||
if (myWindow) {
|
if (myWindow) {
|
||||||
// 弹出系统提示对话框
|
// 弹出系统提示对话框
|
||||||
dialog.showMessageBox({
|
dialog.showMessageBox({
|
||||||
message: '此程序已经正在运行',
|
message: '此程序已经正在运行'
|
||||||
})
|
})
|
||||||
// 如果该程序窗口处于最小化状态,则恢复窗口
|
// 如果该程序窗口处于最小化状态,则恢复窗口
|
||||||
if (myWindow.isMinimized()) myWindow.restore()
|
if (myWindow.isMinimized()) myWindow.restore()
|
||||||
// 将该程序窗口置为当前聚焦态
|
// 将该程序窗口置为当前聚焦态
|
||||||
myWindow.focus()
|
myWindow.focus()
|
||||||
}
|
}
|
||||||
}
|
})
|
||||||
)
|
|
||||||
|
|
||||||
// This method will be called when Electron has finished
|
// This method will be called when Electron has finished
|
||||||
// initialization and is ready to create browser windows.
|
// initialization and is ready to create browser windows.
|
||||||
// Some APIs can only be used after this event occurs.
|
// Some APIs can only be used after this event occurs.
|
||||||
app.whenReady().then(() => {
|
|
||||||
|
|
||||||
const { spawn } = require('child_process')
|
const { spawn } = require('child_process')
|
||||||
|
let child = null
|
||||||
|
let exePluginsExeList = []
|
||||||
|
app.whenReady().then(() => {
|
||||||
const fs = require('fs')
|
const fs = require('fs')
|
||||||
const path = require('path')
|
const path = require('path')
|
||||||
|
|
||||||
const logStream = fs.createWriteStream('app.log', { flags: 'a' }) // 日志文件
|
const logStream = fs.createWriteStream('app.log', { flags: 'a' }) // 日志文件
|
||||||
let exePath = path.resolve('./resources/app.asar.unpacked/resources/plugin-test')
|
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') {
|
if (process.env.NODE_ENV === 'development') {
|
||||||
exePath = path.resolve('./resources/plugin-test')
|
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) => {
|
child.stdout.on('data', (data) => {
|
||||||
console.log('stdout:', data.toString())
|
console.log('stdout:', data.toString())
|
||||||
|
@ -108,6 +131,11 @@ if (!gotTheLock) {
|
||||||
logStream.end()
|
logStream.end()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
child.on('exit', (code, signal) => {
|
||||||
|
console.log(`子进程已退出,退出码 ${code},信号: ${signal}`)
|
||||||
|
logStream.write(`子进程已退出,退出码 ${code},信号: ${signal}`)
|
||||||
|
logStream.end()
|
||||||
|
})
|
||||||
|
|
||||||
// Set app user model id for windows
|
// Set app user model id for windows
|
||||||
electronApp.setAppUserModelId('com.electron')
|
electronApp.setAppUserModelId('com.electron')
|
||||||
|
@ -136,6 +164,14 @@ if (!gotTheLock) {
|
||||||
// explicitly with Cmd + Q.
|
// explicitly with Cmd + Q.
|
||||||
app.on('window-all-closed', () => {
|
app.on('window-all-closed', () => {
|
||||||
if (process.platform !== 'darwin') {
|
if (process.platform !== 'darwin') {
|
||||||
|
// 循环关闭插件 EXE 列表
|
||||||
|
exePluginsExeList.forEach((exe) => {
|
||||||
|
killProcessByName(exe)
|
||||||
|
})
|
||||||
|
// child.kill('SIGTERM'); // 或者使用 'SIGKILL' 来强制关闭
|
||||||
|
// killProcessByName('gateway.exe');
|
||||||
|
// 循环关闭后端服务
|
||||||
|
killProcessByName('main.exe')
|
||||||
app.quit()
|
app.quit()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
|
@ -13,11 +13,11 @@ const settings = defineProps({
|
||||||
<el-aside :width="settings.width">
|
<el-aside :width="settings.width">
|
||||||
<el-scrollbar>
|
<el-scrollbar>
|
||||||
<el-menu
|
<el-menu
|
||||||
:default-openeds="['1']"
|
default-active="/switch"
|
||||||
:collapse="settings.collapse"
|
:collapse="settings.collapse"
|
||||||
:router="true"
|
: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="/about"><el-icon> <Menu /> </el-icon>文章管理列表</el-menu-item>-->
|
||||||
<!-- <el-menu-item index="/test"><el-icon> <Menu /> </el-icon>测试</el-menu-item>-->
|
<!-- <el-menu-item index="/test"><el-icon> <Menu /> </el-icon>测试</el-menu-item>-->
|
||||||
</el-menu>
|
</el-menu>
|
||||||
|
@ -35,10 +35,11 @@ const settings = defineProps({
|
||||||
}
|
}
|
||||||
.el-menu{
|
.el-menu{
|
||||||
background: #f6f6f6;
|
background: #f6f6f6;
|
||||||
|
padding: 0 10px;
|
||||||
}
|
}
|
||||||
.el-menu-item{
|
.el-menu-item{
|
||||||
padding: 0 10px;
|
|
||||||
border-radius: 10px;
|
border-radius: 10px;
|
||||||
|
/*padding-left: 5px !important;*/
|
||||||
}
|
}
|
||||||
.el-menu-item.is-active{
|
.el-menu-item.is-active{
|
||||||
background: #c8cde4;
|
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;">
|
<el-container direction="vertical" style="min-height: 100vh;min-width: 100vw;overflow: hidden;">
|
||||||
<Header></Header>
|
<Header></Header>
|
||||||
<el-container >
|
<el-container >
|
||||||
<Aside width="120"></Aside>
|
<Aside width="160px"></Aside>
|
||||||
<el-main>
|
<el-main>
|
||||||
<router-view/>
|
<router-view/>
|
||||||
</el-main>
|
</el-main>
|
||||||
|
|
Loading…
Reference in New Issue