mirror of
https://github.com/QYG2297248353/IYUUPlus-Windows.git
synced 2025-03-04 11:44:24 +08:00
系统托盘
This commit is contained in:
parent
7d2e569fd8
commit
0982fdd16e
@ -4,30 +4,38 @@ const { FuseV1Options, FuseVersion } = require('@electron/fuses');
|
|||||||
module.exports = {
|
module.exports = {
|
||||||
packagerConfig: {
|
packagerConfig: {
|
||||||
asar: true,
|
asar: true,
|
||||||
icon: 'iyuu.png',
|
icon: 'iyuu',
|
||||||
extraResource: [
|
extraResource: [
|
||||||
'run/',
|
'run/',
|
||||||
'iyuu/',
|
'iyuu/',
|
||||||
"run.bat"
|
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
rebuildConfig: {},
|
rebuildConfig: {},
|
||||||
makers: [
|
makers: [
|
||||||
{
|
{
|
||||||
name: '@electron-forge/maker-squirrel',
|
name: '@electron-forge/maker-squirrel',
|
||||||
config: {},
|
config: {
|
||||||
|
setupIcon: 'iyuu.ico',
|
||||||
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: '@electron-forge/maker-zip',
|
name: '@electron-forge/maker-zip',
|
||||||
platforms: ['darwin'],
|
platforms: ['darwin'],
|
||||||
|
config: {
|
||||||
|
icon: 'iyuu.icns',
|
||||||
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: '@electron-forge/maker-deb',
|
name: '@electron-forge/maker-deb',
|
||||||
config: {},
|
config: {
|
||||||
|
icon: 'iyuu.png',
|
||||||
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: '@electron-forge/maker-rpm',
|
name: '@electron-forge/maker-rpm',
|
||||||
config: {},
|
config: {
|
||||||
|
icon: 'iyuu.png',
|
||||||
|
},
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
plugins: [
|
plugins: [
|
||||||
|
49
main.js
49
main.js
@ -15,13 +15,34 @@ const createWindow = () => {
|
|||||||
webPreferences: {
|
webPreferences: {
|
||||||
nodeIntegration: true,
|
nodeIntegration: true,
|
||||||
contextIsolation: false,
|
contextIsolation: false,
|
||||||
|
devTools: false,
|
||||||
|
webSecurity: false,
|
||||||
|
allowRunningInsecureContent: true,
|
||||||
preload: path.join(__dirname, 'preload.js')
|
preload: path.join(__dirname, 'preload.js')
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
require("./menu/menu.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(() => {
|
app.whenReady().then(() => {
|
||||||
@ -35,17 +56,31 @@ app.whenReady().then(() => {
|
|||||||
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
createWindow()
|
createWindow()
|
||||||
app.on('activate', () => {
|
|
||||||
if (BrowserWindow.getAllWindows().length === 0) createWindow()
|
|
||||||
})
|
|
||||||
}, 5000)
|
}, 5000)
|
||||||
})
|
})
|
||||||
|
|
||||||
app.on('window-all-closed', () => {
|
app.on('activate', () => {
|
||||||
server.stopServer()
|
if (BrowserWindow.getAllWindows().length === 0) {
|
||||||
if (process.platform !== 'darwin') app.quit()
|
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) => {
|
process.on('uncaughtException', (error) => {
|
||||||
log.error('Uncaught Exception:', error);
|
log.error('Uncaught Exception:', error);
|
||||||
|
43
menu/menu.js
43
menu/menu.js
@ -5,6 +5,14 @@ let template = [
|
|||||||
{
|
{
|
||||||
label: "IYUU",
|
label: "IYUU",
|
||||||
submenu: [
|
submenu: [
|
||||||
|
{
|
||||||
|
label: "刷新",
|
||||||
|
click: () => {
|
||||||
|
BrowserWindow.getAllWindows().forEach(win => {
|
||||||
|
win.reload()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
},
|
||||||
{
|
{
|
||||||
label: "重启服务",
|
label: "重启服务",
|
||||||
click: () => {
|
click: () => {
|
||||||
@ -13,7 +21,7 @@ let template = [
|
|||||||
BrowserWindow.getAllWindows().forEach(win => {
|
BrowserWindow.getAllWindows().forEach(win => {
|
||||||
win.reload()
|
win.reload()
|
||||||
})
|
})
|
||||||
}, 1000)
|
}, 2000)
|
||||||
}
|
}
|
||||||
|
|
||||||
},
|
},
|
||||||
@ -39,6 +47,23 @@ let template = [
|
|||||||
{
|
{
|
||||||
label: "帮助",
|
label: "帮助",
|
||||||
submenu: [
|
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: "新疆萌森软件开发工作室提供技术支持",
|
label: "新疆萌森软件开发工作室提供技术支持",
|
||||||
click: () => {
|
click: () => {
|
||||||
@ -57,21 +82,7 @@ let template = [
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: "问题反馈",
|
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;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
43
menu/tray.js
Normal file
43
menu/tray.js
Normal file
@ -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);
|
||||||
|
});
|
@ -28,9 +28,6 @@ function startServer() {
|
|||||||
env.Path = `${phpDir};${env.Path}`;
|
env.Path = `${phpDir};${env.Path}`;
|
||||||
|
|
||||||
const workingDir = path.resolve(path.join(resourcePath, 'iyuu'));
|
const workingDir = path.resolve(path.join(resourcePath, 'iyuu'));
|
||||||
const batFile = path.join('windows.bat');
|
|
||||||
// batFile 父目录
|
|
||||||
|
|
||||||
|
|
||||||
log.info(`[IYUU] 工作目录: ${workingDir}`);
|
log.info(`[IYUU] 工作目录: ${workingDir}`);
|
||||||
|
|
||||||
@ -93,7 +90,6 @@ function startServer() {
|
|||||||
|
|
||||||
serverProcess.on("close", function (code) {
|
serverProcess.on("close", function (code) {
|
||||||
log.info("[IYUU] 服务退出:" + code);
|
log.info("[IYUU] 服务退出:" + code);
|
||||||
restartServer();
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user