🔨 Refactor: fix macos clipboard poll

This commit is contained in:
萌萌哒赫萝
2023-04-10 19:07:37 +08:00
parent 1d0c8dba53
commit bfa41be2ec
2 changed files with 9 additions and 26 deletions

View File

@@ -12,8 +12,13 @@ class ClipboardWatcher extends EventEmitter {
}
startListening (watchDelay = 500) {
if (this.timer) {
clearInterval(this.timer)
this.stopListening()
console.log('timer', this.timer)
const image = clipboard.readImage()
if (!image.isEmpty()) {
const dataUrl = image.toDataURL()
this.lastImage = nativeImage.createFromDataURL(dataUrl)
}
this.timer = setInterval(() => {
@@ -35,10 +40,12 @@ class ClipboardWatcher extends EventEmitter {
this.lastImage = currentImage
this.emit('change', currentImage)
}, watchDelay)
console.log('start timer', this.timer)
}
stopListening () {
if (this.timer) {
console.log('stop timer')
clearInterval(this.timer)
this.timer = null
}