IYUUPlus-Windows/menu/tray.js

52 lines
1.1 KiB
JavaScript
Raw Permalink Normal View History

2024-07-01 14:08:06 +08:00
const { app, Menu, Tray } = require("electron")
2024-06-29 00:41:06 +08:00
const path = require('node:path')
2024-07-01 16:50:17 +08:00
const log = require('electron-log')
2024-06-29 00:41:06 +08:00
const server = require('../server/server');
2024-07-01 14:08:06 +08:00
const mainWin = require('../windows/app');
2024-06-29 00:41:06 +08:00
2024-07-01 16:50:17 +08:00
const iconPath = path.join(__dirname, '..', 'iyuu.ico')
const tray = new Tray(iconPath);
2024-06-29 00:41:06 +08:00
2024-07-01 14:08:06 +08:00
const contextMenu = Menu.buildFromTemplate([
{
label: '打开主窗口',
click: () => {
mainWin.showWindows()
}
},
2024-07-01 16:50:17 +08:00
{
label: '通过浏览器打开',
click: () => {
require('electron').shell.openExternal('http://127.0.0.1:8787')
}
},
2024-07-01 14:08:06 +08:00
{
label: '重启服务',
click: () => {
server.restartServer()
}
},
2024-07-01 16:50:17 +08:00
{
label: '强制退出',
click: () => {
app.exit(414)
}
},
2024-07-01 14:08:06 +08:00
{
label: '退出',
click: () => {
app.quit()
}
2024-06-29 00:41:06 +08:00
}
]);
tray.setToolTip('IYUU');
tray.setContextMenu(contextMenu);
tray.on('double-click', () => {
2024-07-01 14:08:06 +08:00
if (mainWin.visibleWindows()) {
mainWin.hideWindows()
2024-07-01 16:50:17 +08:00
} else {
mainWin.showWindows()
2024-07-01 14:08:06 +08:00
}
2024-06-29 00:41:06 +08:00
});