From 7fd79873f3ec68a897b4d8c33a05b7d1c1002cec Mon Sep 17 00:00:00 2001 From: yj <1336058017@qq.com> Date: Fri, 24 Jan 2025 11:11:43 +0800 Subject: [PATCH] =?UTF-8?q?=E8=8F=9C=E5=8D=95=E8=87=AA=E5=AE=9A=E4=B9=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.js | 64 ++++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 41 insertions(+), 23 deletions(-) diff --git a/main.js b/main.js index 4937c19..e6850e9 100644 --- a/main.js +++ b/main.js @@ -29,6 +29,7 @@ let regKey; let connection = null; let envStr; let startNumber = 0; +let isShare = true; powerSaveBlocker.start('prevent-display-sleep') const id = powerSaveBlocker.start('prevent-display-sleep') powerSaveBlocker.stop(id) @@ -66,33 +67,12 @@ class AppWindow extends BrowserWindow { function quit() { app.quit() } - +let tray; function createTray() { const iconPath = `${__dirname}/src/assets/${updateJs.getIcon(envStr)}.png`; const trayIcon = nativeImage.createFromPath(iconPath); - const tray = new Tray(trayIcon); - const contextMenu = Menu.buildFromTemplate([ - { - label: '打开', click: () => { - mainWindow.webContents.send('isOpenWindows'); - }, - // icon: iconPath, - }, - { - label: '最小化到系统托盘', click: () => { - mainWindow.hide(); - }, - // icon: iconPath, - }, - { - label: '退出', click: async () => { - quit() - }, - // icon: iconPath, - }, - ]); + tray = new Tray(trayIcon); tray.setToolTip(updateJs.getTitle(envStr)); - tray.setContextMenu(contextMenu); tray.on('click', () => { mainWindow.webContents.send('isOpenWindows'); }); @@ -101,6 +81,13 @@ function createTray() { function createWindow() { mainWindow = new AppWindow(); mainWindow.focus(); + mainWindow.hookWindowMessage(278, function (e) { + mainWindow.setEnabled(false);//窗口禁用 + setTimeout(() => { + mainWindow.setEnabled(true);//窗口启用 + }, 100); + return true; + }) } const additionalData = { myKey: 'myValue' } app.on('ready', () => { @@ -513,10 +500,34 @@ app.on('ready', () => { // 设置桌面应用基础属性 ipcMain.handle('setMainWindowSize', (event, config) => { if (config.width === 250) { + const contextMenu = Menu.buildFromTemplate([ + { + label: '退出', + click: () => quit(), + }, + ]); + tray.setContextMenu(contextMenu); mainWindow.setSkipTaskbar(true) mainWindow.setResizable(false) mainWindow.setAlwaysOnTop(true, 'screen-saver') + } else { + const contextMenu = Menu.buildFromTemplate([ + { + label: '打开', + click: () => mainWindow.webContents.send('isOpenWindows'), + }, + { + label: '最小化到系统托盘', + click: () => mainWindow.hide(), + }, + { + label: '退出', + click: () => quit(), + }, + ]); + tray.setContextMenu(contextMenu); } + console.log(isShare); // 设置最小窗口尺寸 mainWindow.setMinimumSize(config.width, config.height); // 设置最大尺寸 @@ -580,6 +591,13 @@ app.on('ready', () => { // 测试 | 生产 child.loadURL(`file://${path.join(__dirname, './dist/index.html')}#/${config.key}`); } + child.hookWindowMessage(278, function (e) { + child.setEnabled(false);//窗口禁用 + setTimeout(() => { + child.setEnabled(true);//窗口启用 + }, 100); + return true; + }) childWindow[config.key] = child child.once('ready-to-show', () => { if (config.show) {