From 19f6d1867dba87f6b8859918ce735eee21b84e50 Mon Sep 17 00:00:00 2001 From: ZiuChen <457353192@qq.com> Date: Mon, 19 Sep 2022 23:49:20 +0800 Subject: [PATCH] fix: use chmodSync modify file permission dynamically --- public/node_modules/clipboard-event/index.js | 18 ++++++++++++++---- ...ler-darwin => clipboard-event-handler-mac} | Bin 2 files changed, 14 insertions(+), 4 deletions(-) rename public/node_modules/clipboard-event/platform/{clipboard-event-handler-darwin => clipboard-event-handler-mac} (100%) diff --git a/public/node_modules/clipboard-event/index.js b/public/node_modules/clipboard-event/index.js index ebf9448..1954cd7 100644 --- a/public/node_modules/clipboard-event/index.js +++ b/public/node_modules/clipboard-event/index.js @@ -1,3 +1,4 @@ +const { chmodSync } = require('fs'); const { EventEmitter } = require('events'); const path = require('path'); const { execFile } = require('child_process'); @@ -9,11 +10,20 @@ class ClipboardEventListener extends EventEmitter { } startListening() { const { platform } = process; - const file = `platform/clipboard-event-handler-${platform}${platform === 'win32' ? '.exe' : ''}` - if(platform !== 'win32' && platform !== 'darwin' && platform !== 'linux') { - throw new Error(`ClipboardEventListener is not supported on ${platform}`); + if (platform === 'win32') { + this.child = execFile(path.join(__dirname, 'platform/clipboard-event-handler-win32.exe')); + } + else if (platform === 'linux') { + const p = path.join(__dirname, 'platform/clipboard-event-handler-linux'); + chmodSync(p, 0o111); // modify file permission: everyone can execute, or it will fail + this.child = execFile(); + } + else if (platform === 'darwin') { + this.child = execFile(path.join(__dirname, 'platform/clipboard-event-handler-mac')); + } + else { + throw 'Not yet supported'; } - this.child = execFile(path.join(__dirname, file)); this.child.stdout.on('data', (data) => { if (data.trim() === 'CLIPBOARD_CHANGE') { this.emit('change'); diff --git a/public/node_modules/clipboard-event/platform/clipboard-event-handler-darwin b/public/node_modules/clipboard-event/platform/clipboard-event-handler-mac similarity index 100% rename from public/node_modules/clipboard-event/platform/clipboard-event-handler-darwin rename to public/node_modules/clipboard-event/platform/clipboard-event-handler-mac