From 905838235cff6fd226335d7d6e2b955f23508ba4 Mon Sep 17 00:00:00 2001 From: muwoo <2424880409@qq.com> Date: Fri, 24 Dec 2021 13:50:42 +0800 Subject: [PATCH] =?UTF-8?q?:sparkles:=20=E6=94=AF=E6=8C=81=20Escape=20?= =?UTF-8?q?=E5=9B=9E=E5=88=B0=E4=B8=BB=E7=95=8C=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/common/api.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/main/common/api.ts b/src/main/common/api.ts index 56327de..65e1e05 100644 --- a/src/main/common/api.ts +++ b/src/main/common/api.ts @@ -21,6 +21,15 @@ dbInstance.init(); const API: any = { currentPlugin: null, DBKEY: "RUBICK_DB_DEFAULT", + __EscapeKeyDown: (event, input, window) => { + if (input.type !== "keyDown") return; + if (!(input.meta || input.control || input.shift || input.alt)) { + if (input.key === "Escape") { + API.removePlugin(null, window); + } + return; + } + }, openPlugin({ plugin }, window) { if (API.currentPlugin && API.currentPlugin.name === plugin.name) return; window.setSize(window.getSize()[0], 60); @@ -33,6 +42,9 @@ const API: any = { })})` ); window.show(); + // 按 ESC 退出插件 + window.webContents.on("before-input-event", (event, input) => API.__EscapeKeyDown(event, input, window)); + runnerInstance.getView().webContents.on("before-input-event", (event, input) => API.__EscapeKeyDown(event, input, window)); }, removePlugin(e, window) { API.currentPlugin = null;