mirror of
https://github.com/Kuingsmile/PicList.git
synced 2026-05-22 00:30:33 +08:00
@@ -4,13 +4,17 @@ import { EventEmitter } from 'node:events'
|
|||||||
import logger from '@core/picgo/logger'
|
import logger from '@core/picgo/logger'
|
||||||
import { clipboard, NativeImage } from 'electron'
|
import { clipboard, NativeImage } from 'electron'
|
||||||
|
|
||||||
|
import { getClipboardFilePath } from '~/utils/common'
|
||||||
|
|
||||||
class ClipboardWatcher extends EventEmitter {
|
class ClipboardWatcher extends EventEmitter {
|
||||||
timer: NodeJS.Timeout | null
|
timer: NodeJS.Timeout | null
|
||||||
lastImageHash: string | null
|
lastImageHash: string | null
|
||||||
|
lastImagePath: string | null
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
super()
|
super()
|
||||||
this.lastImageHash = null
|
this.lastImageHash = null
|
||||||
|
this.lastImagePath = null
|
||||||
this.timer = null
|
this.timer = null
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -18,6 +22,13 @@ class ClipboardWatcher extends EventEmitter {
|
|||||||
this.stopListening(false)
|
this.stopListening(false)
|
||||||
|
|
||||||
this.timer = setInterval(() => {
|
this.timer = setInterval(() => {
|
||||||
|
const imgPath = getClipboardFilePath()
|
||||||
|
if (imgPath) {
|
||||||
|
if (this.lastImagePath === imgPath) return
|
||||||
|
this.lastImagePath = imgPath
|
||||||
|
this.emit('change')
|
||||||
|
return
|
||||||
|
}
|
||||||
const image = clipboard.readImage()
|
const image = clipboard.readImage()
|
||||||
if (image.isEmpty()) return
|
if (image.isEmpty()) return
|
||||||
|
|
||||||
@@ -38,6 +49,7 @@ class ClipboardWatcher extends EventEmitter {
|
|||||||
clearInterval(this.timer)
|
clearInterval(this.timer)
|
||||||
this.timer = null
|
this.timer = null
|
||||||
this.lastImageHash = null
|
this.lastImageHash = null
|
||||||
|
this.lastImagePath = null
|
||||||
}
|
}
|
||||||
isLog && logger.info('Stop to watch clipboard')
|
isLog && logger.info('Stop to watch clipboard')
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user