From 89c61035fa908a40263de78f28b1737807633ff5 Mon Sep 17 00:00:00 2001 From: whiteying <12877816+whiteying@user.noreply.gitee.com> Date: Tue, 24 Oct 2023 11:37:34 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=89=93=E5=BC=80=E7=9B=B8?= =?UTF-8?q?=E5=90=8C=E5=BA=94=E7=94=A8=E7=A8=8B=E5=BA=8Fjs=E6=8A=A5?= =?UTF-8?q?=E9=94=99=E9=97=AE=E9=A2=98=EF=BC=8C=E4=BF=AE=E5=A4=8D=E9=9A=90?= =?UTF-8?q?=E8=97=8F=E7=AA=97=E5=8F=A3=E5=90=8E=E5=8D=95=E5=87=BB=E6=97=A0?= =?UTF-8?q?=E6=B3=95=E6=81=A2=E5=A4=8D=E7=AA=97=E5=8F=A3=EF=BC=8C=E6=89=98?= =?UTF-8?q?=E7=9B=98=E8=8F=9C=E5=8D=95=E5=A2=9E=E5=8A=A0=E6=98=BE=E7=A4=BA?= =?UTF-8?q?=E4=B8=BB=E7=95=8C=E9=9D=A2=E9=80=89=E9=A1=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.js | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/main.js b/main.js index ca964b5..984a14e 100644 --- a/main.js +++ b/main.js @@ -58,11 +58,14 @@ async function initialize() { const gotTheLock = app.requestSingleInstanceLock(); if (!gotTheLock) { helper.appQuit(); + // return阻止运行后面的代码导致报错 + return; } app.on("second-instance", (event) => { if (MAIN_WINDOW) { - if (MAIN_WINDOW.isMinimized()) { + if (MAIN_WINDOW.isMinimized() || !MAIN_WINDOW.isVisible()) { MAIN_WINDOW.restore(); + MAIN_WINDOW.setSkipTaskbar(false); // 打开任务栏 } MAIN_WINDOW.focus(); } @@ -192,6 +195,16 @@ async function initTray() { APP_TRAY.setToolTip("hiprint"); // 托盘标题 // 托盘菜单 let trayMenuTemplate = [ + { + label: "主界面", + click: () => { + if (MAIN_WINDOW.isMinimized() || !MAIN_WINDOW.isVisible()) { + MAIN_WINDOW.restore(); + MAIN_WINDOW.setSkipTaskbar(false); // 打开任务栏 + } + MAIN_WINDOW.focus(); + }, + }, { label: "退出", click: () => { @@ -204,14 +217,12 @@ async function initTray() { const contextMenu = Menu.buildFromTemplate(trayMenuTemplate); APP_TRAY.setContextMenu(contextMenu); // 监听点击事件 - APP_TRAY.on("click", function() { - if (MAIN_WINDOW.isMinimized()) { + APP_TRAY.on("click", function () { + if (MAIN_WINDOW.isMinimized() || !MAIN_WINDOW.isVisible()) { MAIN_WINDOW.restore(); + MAIN_WINDOW.setSkipTaskbar(false); // 打开任务栏 } - if (!MAIN_WINDOW.isVisible()) { - MAIN_WINDOW.show(); - MAIN_WINDOW.setSkipTaskbar(true); - } + MAIN_WINDOW.focus(); }); return APP_TRAY; } -- Gitee