From f7a2215b64a05c1454afb0ee2a2c5e773edc96e0 Mon Sep 17 00:00:00 2001 From: ZiuChen <457353192@qq.com> Date: Tue, 20 Sep 2022 20:27:24 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E6=AD=A3linux=E4=B8=8B?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E6=8B=B7=E8=B4=9D=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- public/node_modules/clipboard-event/index.js | 71 ++++++++++---------- 1 file changed, 36 insertions(+), 35 deletions(-) diff --git a/public/node_modules/clipboard-event/index.js b/public/node_modules/clipboard-event/index.js index 71342ef..2439737 100644 --- a/public/node_modules/clipboard-event/index.js +++ b/public/node_modules/clipboard-event/index.js @@ -1,63 +1,64 @@ const { chmodSync, existsSync, mkdirSync, copyFileSync } = require('fs') -const { EventEmitter } = require('events'); -const path = require('path'); -const { execFile } = require('child_process'); -const homeDir = require('os').homedir(); +const { EventEmitter } = require('events') +const path = require('path') +const { execFile } = require('child_process') +const homeDir = require('os').homedir() class ClipboardEventListener extends EventEmitter { constructor() { - super(); - this.child = null; - this.listening = false; + super() + this.child = null + this.listening = false } startListening() { - const { platform } = process; + const { platform } = process if (platform === 'win32') { - this.child = execFile(path.join(__dirname, 'platform/clipboard-event-handler-win32.exe')); - } - else if (platform === 'linux') { + this.child = execFile(path.join(__dirname, 'platform/clipboard-event-handler-win32.exe')) + } else if (platform === 'linux') { // linux: cant execFile without chmod, and cant chmod in app.asar // so we need to copy the file to /usr/bin const targetPath = path.resolve(homeDir, '.local', 'bin') const target = path.resolve(targetPath, 'clipboard-event-handler-linux') const p = path.join(__dirname, 'platform/clipboard-event-handler-linux') - if(!existsSync(target)) { - try { + try { + if (!existsSync(targetPath)) { + // bin dir doesnt exist, create it mkdirSync(targetPath) + } + if (!existsSync(target)) { + // copy the file copyFileSync(p, target) chmodSync(target, 0o755) - } catch (error) { - this.emit('error', error) } + } catch (error) { + this.emit('error', error) } - this.child = execFile(target); - } - else if (platform === 'darwin') { - this.child = execFile(path.join(__dirname, 'platform/clipboard-event-handler-mac')); - } - else { - throw 'Not yet supported'; + this.child = execFile(target) + } else if (platform === 'darwin') { + this.child = execFile(path.join(__dirname, 'platform/clipboard-event-handler-mac')) + } else { + throw 'Not yet supported' } this.child.stdout.on('data', (data) => { if (data.trim() === 'CLIPBOARD_CHANGE') { - this.emit('change'); + this.emit('change') } - }); + }) this.child.stdout.on('close', () => { - this.emit('close'); - this.listening = false; - }); + this.emit('close') + this.listening = false + }) this.child.stdout.on('exit', () => { - this.emit('exit'); - this.listening = false; - }); - this.listening = true; + this.emit('exit') + this.listening = false + }) + this.listening = true } stopListening() { - const res = this.child.kill(); - this.listening = false; - return res; + const res = this.child.kill() + this.listening = false + return res } } -module.exports = new ClipboardEventListener(); \ No newline at end of file +module.exports = new ClipboardEventListener()