Merge branch 'v1.4.3'

This commit is contained in:
ZiuChen
2022-09-27 00:13:55 +08:00
13 changed files with 229 additions and 71 deletions

56
public/listener.js Normal file
View File

@@ -0,0 +1,56 @@
const { chmodSync, existsSync } = require('fs')
const { EventEmitter } = require('events')
const path = require('path')
const { execFile } = require('child_process')
class ClipboardEventListener extends EventEmitter {
constructor() {
super()
this.child = null
this.listening = false
}
startListening(dbPath) {
const targetMap = {
win32: 'clipboard-event-handler-win32.exe',
linux: 'clipboard-event-handler-linux'
}
const { platform } = process
const target = path.resolve(
dbPath.split('_utools_clipboard_manager_storage')[0],
targetMap[platform]
)
if (!existsSync(target)) {
this.emit('error', '剪贴板监听程序不存在')
return
}
if (platform === 'win32') {
this.child = execFile(target)
} else if (platform === 'linux') {
chmodSync(target, 0o755)
this.child = execFile(target)
} else {
throw 'Not yet supported'
}
this.child.stdout.on('data', (data) => {
if (data.trim() === 'CLIPBOARD_CHANGE') {
this.emit('change')
}
})
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
}
}
module.exports = new ClipboardEventListener()

View File

@@ -1,5 +1,5 @@
{
"version": "1.4.2",
"version": "1.4.3",
"pluginName": "超级剪贴板",
"description": "强大的剪贴板管理工具",
"author": "ZiuChen",

View File

@@ -1,5 +1,6 @@
const { existsSync, readFileSync, writeFileSync, mkdirSync } = require('fs')
const crypto = require('crypto')
const listener = require('./listener')
const { clipboard } = require('electron')
const time = require('./time')
@@ -11,5 +12,6 @@ window.exports = {
mkdirSync,
crypto,
clipboard,
time
time,
Buffer
}