From e8aad4690cc2dbc039ec43e43db7ff306c4e80e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=90=8C=E6=A3=AE?= Date: Thu, 27 Jun 2024 18:27:45 +0800 Subject: [PATCH] =?UTF-8?q?feat=20=E8=8F=9C=E5=8D=95=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.js | 4 ++- menu/menu.js | 82 ++++++++++++++++++++++++++++++++++++++++++++++++ server/server.js | 14 +++++++-- 3 files changed, 97 insertions(+), 3 deletions(-) create mode 100644 menu/menu.js diff --git a/main.js b/main.js index c54e0df..43ee731 100644 --- a/main.js +++ b/main.js @@ -1,4 +1,4 @@ -const { app, BrowserWindow } = require('electron') +const { app, BrowserWindow, Menu } = require('electron') const path = require('node:path') const server = require('./server/server'); @@ -11,6 +11,8 @@ const createWindow = () => { } }) + require("./menu/menu.js") + win.loadURL('http://127.0.0.1:8787') } diff --git a/menu/menu.js b/menu/menu.js new file mode 100644 index 0000000..3063170 --- /dev/null +++ b/menu/menu.js @@ -0,0 +1,82 @@ +const { Menu, BrowserWindow } = require("electron") +const server = require('../server/server'); + +let template = [ + { + label: "IYUU", + submenu: [ + { + label: "重启服务", + click: () => { + server.restartServer() + setTimeout(() => { + BrowserWindow.getAllWindows().forEach(win => { + win.reload() + }) + }, 1000) + } + + }, + { + label: "文档中心", + click: () => { + let win = new BrowserWindow({ + width: 800, + height: 600, + webPreferences: { + nodeIntegration: true, + contextIsolation: false, + } + }); + win.loadURL("https://doc.iyuu.cn/"); + win.on("closed", () => { + win = null; + }); + } + }, + ] + }, + { + label: "帮助", + submenu: [ + { + label: "新疆萌森软件开发工作室提供技术支持", + click: () => { + let win = new BrowserWindow({ + width: 800, + height: 600, + webPreferences: { + nodeIntegration: true, + contextIsolation: false, + } + }); + win.loadURL("https://lifebus.top/"); + win.on("closed", () => { + win = null; + }); + } + }, + { + label: "问题反馈", + click: () => { + let win = new BrowserWindow({ + width: 800, + height: 600, + webPreferences: { + nodeIntegration: true, + contextIsolation: false, + } + }); + win.loadURL("https://gitee.com/qyg2297248353/iyuuplus-windows/issues"); + win.on("closed", () => { + win = null; + }); + } + } + ] + } +] + +const m = Menu.buildFromTemplate(template) + +Menu.setApplicationMenu(m) \ No newline at end of file diff --git a/server/server.js b/server/server.js index 931e3aa..9cd9556 100644 --- a/server/server.js +++ b/server/server.js @@ -22,9 +22,14 @@ function startServer() { const args = ['./iyuu/windows.php']; const workingDirectory = path.resolve(__dirname, '..'); + const env = { ...process.env }; + const phpDir = path.dirname(cmdPath); + env.PATH = `${phpDir}${path.delimiter}${env.PATH}`; + serverProcess = spawn(cmdPath, args, { cwd: workingDirectory, - stdio: ['inherit', 'pipe', 'inherit'] + stdio: ['inherit', 'pipe', 'inherit'], + env: env }); serverProcess.stdout.setEncoding('utf8'); @@ -53,4 +58,9 @@ function stopServer() { } } -module.exports = { startServer, stopServer }; \ No newline at end of file +function restartServer() { + stopServer(); + startServer(); +} + +module.exports = { startServer, stopServer, restartServer }; \ No newline at end of file