mirror of
https://github.com/ZiuChen/ClipboardManager.git
synced 2025-09-27 13:53:21 +08:00
fix: linux用户改用不同的监听机制 监听异常时抛出错误
This commit is contained in:
16
public/node_modules/clipboard-event/index.js
generated
vendored
16
public/node_modules/clipboard-event/index.js
generated
vendored
@@ -1,7 +1,6 @@
|
||||
const { chmodSync } = require('fs');
|
||||
const { EventEmitter } = require('events');
|
||||
const path = require('path');
|
||||
const { execFile } = require('child_process');
|
||||
const { execFile, exec } = require('child_process');
|
||||
|
||||
class ClipboardEventListener extends EventEmitter {
|
||||
constructor() {
|
||||
@@ -11,12 +10,11 @@ class ClipboardEventListener extends EventEmitter {
|
||||
startListening() {
|
||||
const { platform } = process;
|
||||
if (platform === 'win32') {
|
||||
this.child = execFile(path.join(__dirname, 'platform/clipboard-event-handler-win32.exe'));
|
||||
this.child = execFile(path.join(__dirname, 'platform/clipboard-event-handler-mac'));
|
||||
}
|
||||
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(p);
|
||||
// manually install clipboard-event-handler-linux to /usr/local/bin
|
||||
this.child = exec('clipboard-event-handler-linux')
|
||||
}
|
||||
else if (platform === 'darwin') {
|
||||
this.child = execFile(path.join(__dirname, 'platform/clipboard-event-handler-mac'));
|
||||
@@ -29,6 +27,12 @@ class ClipboardEventListener extends EventEmitter {
|
||||
this.emit('change');
|
||||
}
|
||||
});
|
||||
this.child.stdout.on('close', (code) => {
|
||||
this.emit('close', code);
|
||||
});
|
||||
this.child.stdout.on('exit', (code) => {
|
||||
this.emit('exit', code);
|
||||
});
|
||||
}
|
||||
stopListening() {
|
||||
const res = this.child.kill();
|
||||
|
Reference in New Issue
Block a user