diff --git a/forge.config.js b/forge.config.js index 65fde88..2f78b2f 100644 --- a/forge.config.js +++ b/forge.config.js @@ -4,30 +4,38 @@ const { FuseV1Options, FuseVersion } = require('@electron/fuses'); module.exports = { packagerConfig: { asar: true, - icon: 'iyuu.png', + icon: 'iyuu', extraResource: [ 'run/', 'iyuu/', - "run.bat" ] }, rebuildConfig: {}, makers: [ { name: '@electron-forge/maker-squirrel', - config: {}, + config: { + setupIcon: 'iyuu.ico', + }, }, { name: '@electron-forge/maker-zip', platforms: ['darwin'], + config: { + icon: 'iyuu.icns', + } }, { name: '@electron-forge/maker-deb', - config: {}, + config: { + icon: 'iyuu.png', + }, }, { name: '@electron-forge/maker-rpm', - config: {}, + config: { + icon: 'iyuu.png', + }, }, ], plugins: [ diff --git a/iyuu.ico b/iyuu.ico new file mode 100644 index 0000000..096f5e6 Binary files /dev/null and b/iyuu.ico differ diff --git a/main.js b/main.js index 8ccf447..9c56267 100644 --- a/main.js +++ b/main.js @@ -15,13 +15,34 @@ const createWindow = () => { webPreferences: { nodeIntegration: true, contextIsolation: false, + devTools: false, + webSecurity: false, + allowRunningInsecureContent: true, preload: path.join(__dirname, 'preload.js') } }) require("./menu/menu.js") + require("./menu/tray.js") - win.loadURL('http://127.0.0.1:8787') + const url = require('url').format({ + protocol: 'http', + slashes: true, + hostname: '127.0.0.1', + port: 8787 + }) + + win.loadURL(url) + + win.on('minimize', (event) => { + event.preventDefault() + win.hide() + }) + + win.on('close', (event) => { + event.preventDefault() + win.hide() + }) } app.whenReady().then(() => { @@ -35,17 +56,31 @@ app.whenReady().then(() => { setTimeout(() => { createWindow() - app.on('activate', () => { - if (BrowserWindow.getAllWindows().length === 0) createWindow() - }) }, 5000) }) -app.on('window-all-closed', () => { - server.stopServer() - if (process.platform !== 'darwin') app.quit() +app.on('activate', () => { + if (BrowserWindow.getAllWindows().length === 0) { + createWindow() + } else { + app.show() + BrowserWindow.getAllWindows().forEach(win => { + win.show() + }) + } }) +app.on('window-all-closed', () => { + BrowserWindow.getAllWindows().forEach(win => { + win.hide() + }) + app.hide() +}) + +app.on('before-quit', () => { + server.stopServer() + log.info('App is quitting...'); +}) process.on('uncaughtException', (error) => { log.error('Uncaught Exception:', error); diff --git a/menu/menu.js b/menu/menu.js index 3063170..a4a1653 100644 --- a/menu/menu.js +++ b/menu/menu.js @@ -5,6 +5,14 @@ let template = [ { label: "IYUU", submenu: [ + { + label: "刷新", + click: () => { + BrowserWindow.getAllWindows().forEach(win => { + win.reload() + }) + } + }, { label: "重启服务", click: () => { @@ -13,7 +21,7 @@ let template = [ BrowserWindow.getAllWindows().forEach(win => { win.reload() }) - }, 1000) + }, 2000) } }, @@ -39,6 +47,23 @@ let template = [ { label: "帮助", submenu: [ + { + 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; + }); + } + }, { label: "新疆萌森软件开发工作室提供技术支持", click: () => { @@ -57,21 +82,7 @@ let template = [ } }, { - 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; - }); - } + label: "关于" } ] } diff --git a/menu/tray.js b/menu/tray.js new file mode 100644 index 0000000..05748a1 --- /dev/null +++ b/menu/tray.js @@ -0,0 +1,43 @@ +const { app, Menu, Tray, BrowserWindow } = require("electron") +const path = require('node:path') +const server = require('../server/server'); + +const tray = new Tray('iyuu.ico'); + +const contextMenu = Menu.buildFromTemplate([{ + label: '打开主窗口', + click: () => { + BrowserWindow.getAllWindows().forEach(win => { + win.show() + }) + } +}, { + label: '重启服务', + click: () => { + BrowserWindow.getAllWindows().forEach(win => { + win.hide() + }) + server.restartServer() + setTimeout(() => { + BrowserWindow.getAllWindows().forEach(win => { + win.show() + win.reload() + }) + }, 1000) + } +}, +{ + label: '退出', + click: () => { + app.quit() + } +} +]); + +tray.setToolTip('IYUU'); +tray.setContextMenu(contextMenu); + +tray.on('double-click', () => { + win.isVisible() ? win.hide() : win.show() + win.isVisible() ? win.setSkipTaskbar(false) : win.setSkipTaskbar(true); +}); \ No newline at end of file diff --git a/server/server.js b/server/server.js index b9114fc..600dba9 100644 --- a/server/server.js +++ b/server/server.js @@ -28,10 +28,7 @@ function startServer() { env.Path = `${phpDir};${env.Path}`; const workingDir = path.resolve(path.join(resourcePath, 'iyuu')); - const batFile = path.join('windows.bat'); - // batFile 父目录 - - + log.info(`[IYUU] 工作目录: ${workingDir}`); // serverProcess = exec(`cmd /c ${batPath}`, { @@ -93,7 +90,6 @@ function startServer() { serverProcess.on("close", function (code) { log.info("[IYUU] 服务退出:" + code); - restartServer(); }); }