fix: 修复了linux上剪贴板监听程序无法正确执行的问题

This commit is contained in:
ZiuChen
2022-09-20 18:15:01 +08:00
parent 9c29b5d2b7
commit f6732f0147
4 changed files with 31 additions and 20 deletions

View File

@@ -1,6 +1,8 @@
const { chmodSync, existsSync, mkdirSync, copyFileSync } = require('fs')
const { EventEmitter } = require('events');
const path = require('path');
const { execFile, exec } = require('child_process');
const { execFile } = require('child_process');
const homeDir = require('os').homedir();
class ClipboardEventListener extends EventEmitter {
constructor() {
@@ -13,8 +15,16 @@ class ClipboardEventListener extends EventEmitter {
this.child = execFile(path.join(__dirname, 'platform/clipboard-event-handler-mac'));
}
else if (platform === 'linux') {
// manually install clipboard-event-handler-linux to /usr/local/bin
this.child = exec('clipboard-event-handler-linux')
// linux: cant execFile without chmod, and cant chmod in app.asar
// so we need to copy the file to /usr/bin
const target = path.resolve(homeDir, '.local', 'bin')
const p = path.join(__dirname, 'platform/clipboard-event-handler-linux')
if(!existsSync(target)) {
mkdirSync(target)
}
copyFileSync(p, path.join(target, 'clipboard-event-handler-linux'))
chmodSync(path.join(target, 'clipboard-event-handler-linux'), 0o755)
this.child = execFile(path.join(target, 'clipboard-event-handler-linux'));
}
else if (platform === 'darwin') {
this.child = execFile(path.join(__dirname, 'platform/clipboard-event-handler-mac'));
@@ -27,11 +37,11 @@ class ClipboardEventListener extends EventEmitter {
this.emit('change');
}
});
this.child.stdout.on('close', (code) => {
this.emit('close', code);
this.child.stdout.on('close', () => {
this.emit('close');
});
this.child.stdout.on('exit', (code) => {
this.emit('exit', code);
this.child.stdout.on('exit', () => {
this.emit('exit');
});
}
stopListening() {

Binary file not shown.