From dade771985ca8c453414b3f1bb161c54bf54e48f Mon Sep 17 00:00:00 2001 From: muwoo <2424880409@qq.com> Date: Fri, 30 Jul 2021 18:01:54 +0800 Subject: [PATCH] suport win --- package.json | 3 +++ src/main/common/config.js | 1 - src/main/common/listener.js | 23 +++++++++++++++-------- src/renderer/App.vue | 2 +- static/preload.js | 2 +- 5 files changed, 20 insertions(+), 11 deletions(-) diff --git a/package.json b/package.json index 25eca93..114f002 100644 --- a/package.json +++ b/package.json @@ -88,6 +88,9 @@ "vuex": "^3.0.1", "vuex-electron": "^1.0.0" }, + "optionalDependencies": { + "win-mouse": "git+https://github.com/Toinane/win-mouse" +}, "devDependencies": { "ajv": "^6.5.0", "babel-core": "^6.26.3", diff --git a/src/main/common/config.js b/src/main/common/config.js index f5ea2dc..9e827e3 100644 --- a/src/main/common/config.js +++ b/src/main/common/config.js @@ -57,7 +57,6 @@ global.opConfig = { config: null, get() { const platform = os.type(); - console.log(platform); try { if (!opConfig.config) { opConfig.config = JSON.parse(fs.readFileSync(configPath) || JSON.stringify(defaultConfig[platform])); diff --git a/src/main/common/listener.js b/src/main/common/listener.js index 65a4cfe..2af3b43 100644 --- a/src/main/common/listener.js +++ b/src/main/common/listener.js @@ -11,6 +11,7 @@ const {picker, separator, superPanel} = browsers; class Listener { constructor() { this.optionPlugin = {}; + this.isWin = process.platform === 'win32'; } getSelectedContent() { @@ -31,7 +32,6 @@ class Listener { // 延时一定时间才能从剪切板内读取到内容 const text = clipboard.readText('clipboard') || '' const fileUrl = clipboard.read('public.file-url'); - // 如果之前是文案,则回填 clipboard.writeText(lastText); @@ -103,15 +103,15 @@ class Listener { ipcMain.on('start-picker', () => { // 开启输入侦测 ioHook.start(false); - ioHook.load(); + !this.isWin && ioHook.load(); picker.init(); picker.getWindow().on('close', () => { ioHook.stop(); - ioHook.unload(); + !this.isWin && ioHook.unload(); }); - let pos = robot.getMousePos(); + let pos = this.getPos(robot.getMousePos()); picker .getWindow() .setPosition(parseInt(pos.x) + 10, parseInt(pos.y) + 10); @@ -139,8 +139,7 @@ class Listener { }); }); ioHook.on('mousemove', e => { - let x = e.x - let y = e.y + let {x, y} = this.getPos(e); if (!picker.getWindow()) return; picker.getWindow().setPosition(parseInt(x) + 10, parseInt(y) + 10); this.fn(e, picker); @@ -192,6 +191,7 @@ class Listener { superPanel(mainWindow) { // 长按右击呼起超级面板 ipcMain.on('right-down', async () => { + const copyResult = await this.getSelectedContent(); let win = superPanel.getWindow(); @@ -211,12 +211,16 @@ class Listener { }); }); } - const pos = robot.getMousePos(); + const pos = this.getPos(robot.getMousePos()); win.setPosition(parseInt(pos.x), parseInt(pos.y)); win.show(); }); } + getPos(point) { + return this.isWin ? screen.screenToDipPoint({x: point.x, y: point.y}) : point; + } + reRegisterShortCut(mainWindow) { ipcMain.on('re-register', (event, arg) => { this.registerShortCut(mainWindow); @@ -257,7 +261,10 @@ class Listener { initCapture() { ipcMain.on('capture-screen', () => { - spawn('/usr/sbin/screencapture', ["-c", "-i", "-r"], {detached: !0}); + if (process.platform === 'darwin') { + spawn('/usr/sbin/screencapture', ["-c", "-i", "-r"], {detached: !0}); + } + // todo win }); } } diff --git a/src/renderer/App.vue b/src/renderer/App.vue index c4cbbdc..42ff63c 100644 --- a/src/renderer/App.vue +++ b/src/renderer/App.vue @@ -1,6 +1,6 @@