feat: 添加监听状态标志 进入插件重启监听 仅在首次运行时执行copy

This commit is contained in:
ZiuChen
2022-09-20 19:22:21 +08:00
parent 4dd5888a7f
commit f3c7d3899b
2 changed files with 54 additions and 35 deletions

View File

@@ -8,6 +8,7 @@ class ClipboardEventListener extends EventEmitter {
constructor() {
super();
this.child = null;
this.listening = false;
}
startListening() {
const { platform } = process;
@@ -17,14 +18,15 @@ class ClipboardEventListener extends EventEmitter {
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 target = path.resolve(homeDir, '.local', '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)) {
mkdirSync(target)
mkdirSync(targetPath)
copyFileSync(p, target)
chmodSync(target, 0o755)
}
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'));
this.child = execFile(target);
}
else if (platform === 'darwin') {
this.child = execFile(path.join(__dirname, 'platform/clipboard-event-handler-mac'));
@@ -39,13 +41,17 @@ class ClipboardEventListener extends EventEmitter {
});
this.child.stdout.on('close', () => {
this.emit('close');
this.listening = false;
});
this.child.stdout.on('exit', () => {
this.emit('exit');
this.listening = false;
});
this.listening = true;
}
stopListening() {
const res = this.child.kill();
this.listening = false;
return res;
}
}