From 25957c485e5c8945eac00abf26613f9c38e0d1c7 Mon Sep 17 00:00:00 2001 From: muwoo <2424880409@qq.com> Date: Tue, 10 Aug 2021 14:44:15 +0800 Subject: [PATCH] =?UTF-8?q?bugfix:=20=E4=BF=AE=E5=A4=8D=E6=97=A0=E8=BE=B9?= =?UTF-8?q?=E6=A1=86=E6=8B=96=E6=8B=BD=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/common/listener.js | 75 +++++++++++----- src/renderer/App.vue | 173 ++++++++++++++++++------------------ 2 files changed, 141 insertions(+), 107 deletions(-) diff --git a/src/main/common/listener.js b/src/main/common/listener.js index e1df01d..7b9ab5f 100644 --- a/src/main/common/listener.js +++ b/src/main/common/listener.js @@ -106,6 +106,7 @@ class Listener { this.reRegisterShortCut(mainWindow); this.changeSize(mainWindow); this.msgTrigger(mainWindow); + this.windowMoveInit(mainWindow); } colorPicker() { @@ -118,6 +119,7 @@ class Listener { picker.getWindow().on('close', () => { ioHook.stop(); + ioHook.removeAllListeners(); !this.isWin && ioHook.unload(); }); @@ -147,29 +149,30 @@ class Listener { ipcMain.on("closePicker", () => { this.closePicker(); }); - }); - ioHook.on('mousemove', e => { - let {x, y} = this.getPos(e); - if (!picker.getWindow()) return; - picker.getWindow().setPosition(parseInt(x) + 10, parseInt(y) + 10); - this.fn(e, picker); - }) - 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(); - this.closePicker(); - } - }); + ioHook.on('mousemove', e => { + let {x, y} = this.getPos(e); + if (!picker.getWindow()) return; + picker.getWindow().setPosition(parseInt(x) + 10, parseInt(y) + 10); + this.fn(e, picker); + }) - ioHook.on('mouseup', e => { - if (e.button === 3) { - this.closePicker() - } + 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(); + this.closePicker(); + } + }); + + ioHook.on('mouseup', e => { + if (e.button === 3) { + this.closePicker() + } + }); }); } @@ -288,6 +291,36 @@ class Listener { // todo win }); } + + windowMoveInit(win) { + let hasInit = false; + ipcMain.on('window-move', () => { + if (!hasInit) { + hasInit = true; + ioHook.start(false); + !this.isWin && ioHook.load(); + + const winPosition = win.getPosition(); + const winStartPosition = { x: winPosition[0], y: winPosition[1] }; + const mouseStartPosition = screen.getCursorScreenPoint(); + + ioHook.on('mousedrag', e => { + const cursorPosition = screen.getCursorScreenPoint(); + const dx = winStartPosition.x + cursorPosition.x - mouseStartPosition.x; + const dy = winStartPosition.y + cursorPosition.y - mouseStartPosition.y; + let {x, y} = this.getPos({x: dx, y: dy}); + win.setPosition(parseInt(x), parseInt(y)); + }); + + ioHook.on('mouseup', e => { + hasInit = false; + ioHook.stop(); + ioHook.removeAllListeners(); + !this.isWin && ioHook.unload(); + }); + } + }); + } } export default Listener; diff --git a/src/renderer/App.vue b/src/renderer/App.vue index e32b4ff..3a83b14 100644 --- a/src/renderer/App.vue +++ b/src/renderer/App.vue @@ -1,109 +1,111 @@