From eca119a8a98d940f96e9baee15972bc9938390c1 Mon Sep 17 00:00:00 2001 From: muwoo <2424880409@qq.com> Date: Wed, 7 Jul 2021 20:08:42 +0800 Subject: [PATCH] =?UTF-8?q?bugfix:=20=E4=BF=AE=E5=A4=8D=20iohook=20?= =?UTF-8?q?=E5=8D=A1=E9=A1=BF=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/common/common.js | 56 ++++++++++++++++++++------------------- 1 file changed, 29 insertions(+), 27 deletions(-) diff --git a/src/main/common/common.js b/src/main/common/common.js index 702a209..c1e246f 100644 --- a/src/main/common/common.js +++ b/src/main/common/common.js @@ -155,32 +155,13 @@ export default function init(mainWindow) { // 拾色器 ipcMain.on('start-picker', () => { // 开启输入侦测 - ioHook.start(false) + ioHook.start(false); + ioHook.load(); picker.init(); picker.getWindow().on('close', () => { ioHook.stop(); - }); - - - ioHook.on('mousemove', e => { - let x = e.x - let y = e.y - if (!picker.getWindow()) return; - let color = "#" + robot.getPixelColor(parseInt(x), parseInt(y)); - picker.getWindow().setPosition(parseInt(x) - 50, parseInt(y) - 50); - picker.getWindow().webContents.send("updatePicker", color); - }) - - ioHook.on('mouseup', e => { - if (e.button === 1) { - let x = e.x - let y = e.y - const color = "#" + robot.getPixelColor(parseInt(x), parseInt(y)); - clipboard.writeText("#" + robot.getPixelColor(parseInt(x), parseInt(y))); - new Notification({ title: 'Rubick 通知', body: `${color} 已保存到剪切板` }).show(); - closePicker(); - } + ioHook.unload(); }); let pos = robot.getMousePos(); @@ -196,12 +177,33 @@ export default function init(mainWindow) { ); ipcMain.on("closePicker", closePicker); - ioHook.on('mouseup', e => { - if (e.button === 3) { - closePicker() - } - }); + }); + + ioHook.on('mousemove', e => { + let x = e.x + let y = e.y + if (!picker.getWindow()) return; + let color = "#" + robot.getPixelColor(parseInt(x), parseInt(y)); + picker.getWindow().setPosition(parseInt(x) - 50, parseInt(y) - 50); + picker.getWindow().webContents.send("updatePicker", color); }) + + ioHook.on('mouseup', e => { + if (e.button === 1) { + let x = e.x + let y = e.y + const color = "#" + robot.getPixelColor(parseInt(x), parseInt(y)); + clipboard.writeText("#" + robot.getPixelColor(parseInt(x), parseInt(y))); + new Notification({ title: 'Rubick 通知', body: `${color} 已保存到剪切板` }).show(); + closePicker(); + } + }); + + ioHook.on('mouseup', e => { + if (e.button === 3) { + closePicker() + } + }); }