mirror of
https://github.com/Kuingsmile/PicList.git
synced 2025-02-02 19:18:13 -05:00
🔨 Refactor: fix macos clipboard poll
This commit is contained in:
parent
1d0c8dba53
commit
bfa41be2ec
@ -67,9 +67,7 @@ export function setDockMenu () {
|
||||
}
|
||||
|
||||
export function createMenu () {
|
||||
const ClipboardWatcher = process.platform === 'darwin' ? clipboardPoll : clipboardListener
|
||||
const submenu = buildPicBedListMenu()
|
||||
const isListeningClipboard = db.get('settings.isListeningClipboard') || false
|
||||
const appMenu = Menu.buildFromTemplate([
|
||||
{
|
||||
label: 'PicList',
|
||||
@ -85,28 +83,6 @@ export function createMenu () {
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
label: T('START_WATCH_CLIPBOARD'),
|
||||
click () {
|
||||
db.set('settings.isListeningClipboard', true)
|
||||
ClipboardWatcher.startListening()
|
||||
ClipboardWatcher.on('change', () => {
|
||||
picgo.log.info('clipboard changed')
|
||||
uploadClipboardFiles()
|
||||
})
|
||||
createMenu()
|
||||
},
|
||||
enabled: !isListeningClipboard
|
||||
},
|
||||
{
|
||||
label: T('STOP_WATCH_CLIPBOARD'),
|
||||
click () {
|
||||
db.set('settings.isListeningClipboard', false)
|
||||
ClipboardWatcher.stopListening()
|
||||
createMenu()
|
||||
},
|
||||
enabled: isListeningClipboard
|
||||
},
|
||||
{
|
||||
label: T('RELOAD_APP'),
|
||||
click () {
|
||||
|
@ -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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user