fix: use chmodSync modify file permission dynamically

This commit is contained in:
ZiuChen 2022-09-19 23:49:20 +08:00
parent 87d56fa2f3
commit 19f6d1867d
2 changed files with 14 additions and 4 deletions

View File

@ -1,3 +1,4 @@
const { chmodSync } = require('fs');
const { EventEmitter } = require('events'); const { EventEmitter } = require('events');
const path = require('path'); const path = require('path');
const { execFile } = require('child_process'); const { execFile } = require('child_process');
@ -9,11 +10,20 @@ class ClipboardEventListener extends EventEmitter {
} }
startListening() { startListening() {
const { platform } = process; const { platform } = process;
const file = `platform/clipboard-event-handler-${platform}${platform === 'win32' ? '.exe' : ''}` if (platform === 'win32') {
if(platform !== 'win32' && platform !== 'darwin' && platform !== 'linux') { this.child = execFile(path.join(__dirname, 'platform/clipboard-event-handler-win32.exe'));
throw new Error(`ClipboardEventListener is not supported on ${platform}`); }
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) => { this.child.stdout.on('data', (data) => {
if (data.trim() === 'CLIPBOARD_CHANGE') { if (data.trim() === 'CLIPBOARD_CHANGE') {
this.emit('change'); this.emit('change');