mirror of
https://github.com/ZiuChen/ClipboardManager.git
synced 2025-12-22 18:22:46 +08:00
refactor: 改善剪贴板监听性能 修复大图卡顿与CPU高占用的问题
This commit is contained in:
29
public/node_modules/clipboard-event/index.js
generated
vendored
Normal file
29
public/node_modules/clipboard-event/index.js
generated
vendored
Normal file
@@ -0,0 +1,29 @@
|
||||
const { EventEmitter } = require('events');
|
||||
const path = require('path');
|
||||
const { execFile } = require('child_process');
|
||||
|
||||
class ClipboardEventListener extends EventEmitter {
|
||||
constructor() {
|
||||
super();
|
||||
this.child = null;
|
||||
}
|
||||
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}`);
|
||||
}
|
||||
this.child = execFile(path.join(__dirname, file));
|
||||
this.child.stdout.on('data', (data) => {
|
||||
if (data.trim() === 'CLIPBOARD_CHANGE') {
|
||||
this.emit('change');
|
||||
}
|
||||
});
|
||||
}
|
||||
stopListening() {
|
||||
const res = this.child.kill();
|
||||
return res;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = new ClipboardEventListener();
|
||||
Reference in New Issue
Block a user