mirror of
https://github.com/ZiuChen/ClipboardManager.git
synced 2025-06-08 14:24:03 +08:00
chore: 移除了插件内的二进制文件 恢复旧的监听机制 性能问题有待解决
This commit is contained in:
parent
b4dc9f803b
commit
8ee1572ea6
21
public/node_modules/clipboard-event/LICENSE
generated
vendored
21
public/node_modules/clipboard-event/LICENSE
generated
vendored
@ -1,21 +0,0 @@
|
|||||||
MIT License
|
|
||||||
|
|
||||||
Copyright (c) 2020 Sudhakar R
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
|
||||||
copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
SOFTWARE.
|
|
62
public/node_modules/clipboard-event/index.js
generated
vendored
62
public/node_modules/clipboard-event/index.js
generated
vendored
@ -1,62 +0,0 @@
|
|||||||
const { chmodSync, existsSync, mkdirSync, copyFileSync } = require('fs')
|
|
||||||
const { EventEmitter } = require('events')
|
|
||||||
const path = require('path')
|
|
||||||
const { execFile } = require('child_process')
|
|
||||||
const homeDir = require('os').homedir()
|
|
||||||
|
|
||||||
class ClipboardEventListener extends EventEmitter {
|
|
||||||
constructor() {
|
|
||||||
super()
|
|
||||||
this.child = null
|
|
||||||
this.listening = false
|
|
||||||
}
|
|
||||||
startListening() {
|
|
||||||
const { platform } = process
|
|
||||||
if (platform === 'win32') {
|
|
||||||
this.child = execFile(path.join(__dirname, 'platform/clipboard-event-handler-win32.exe'))
|
|
||||||
} else if (platform === 'linux') {
|
|
||||||
// linux: cant execFile without chmod, and cant chmod in app.asar
|
|
||||||
// so we need to copy the file to /usr/bin
|
|
||||||
const targetPath = path.resolve(homeDir, '.local', 'bin')
|
|
||||||
const target = path.resolve(targetPath, 'clipboard-event-handler-linux')
|
|
||||||
const p = path.join(__dirname, 'platform/clipboard-event-handler-linux')
|
|
||||||
try {
|
|
||||||
if (!existsSync(targetPath)) {
|
|
||||||
// bin dir doesnt exist, create it
|
|
||||||
mkdirSync(targetPath)
|
|
||||||
}
|
|
||||||
if (!existsSync(target)) {
|
|
||||||
// copy the file
|
|
||||||
copyFileSync(p, target)
|
|
||||||
chmodSync(target, 0o755)
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
this.emit('error', error)
|
|
||||||
}
|
|
||||||
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()
|
|
BIN
public/node_modules/clipboard-event/platform/clipboard-event-handler-linux
generated
vendored
BIN
public/node_modules/clipboard-event/platform/clipboard-event-handler-linux
generated
vendored
Binary file not shown.
BIN
public/node_modules/clipboard-event/platform/clipboard-event-handler-win32.exe
generated
vendored
BIN
public/node_modules/clipboard-event/platform/clipboard-event-handler-win32.exe
generated
vendored
Binary file not shown.
@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"version": "1.4.0",
|
"version": "1.4.2",
|
||||||
"pluginName": "超级剪贴板",
|
"pluginName": "超级剪贴板",
|
||||||
"description": "强大的剪贴板管理工具",
|
"description": "强大的剪贴板管理工具",
|
||||||
"author": "ZiuChen",
|
"author": "ZiuChen",
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
const { existsSync, readFileSync, writeFileSync, mkdirSync } = require('fs')
|
const { existsSync, readFileSync, writeFileSync, mkdirSync } = require('fs')
|
||||||
const crypto = require('crypto')
|
const crypto = require('crypto')
|
||||||
const listener = require('clipboard-event')
|
|
||||||
const { clipboard } = require('electron')
|
const { clipboard } = require('electron')
|
||||||
const time = require('./time')
|
const time = require('./time')
|
||||||
|
|
||||||
@ -11,7 +10,6 @@ window.exports = {
|
|||||||
writeFileSync,
|
writeFileSync,
|
||||||
mkdirSync,
|
mkdirSync,
|
||||||
crypto,
|
crypto,
|
||||||
listener,
|
|
||||||
clipboard,
|
clipboard,
|
||||||
time
|
time
|
||||||
}
|
}
|
||||||
|
@ -1,14 +1,5 @@
|
|||||||
const {
|
const { utools, existsSync, readFileSync, writeFileSync, mkdirSync, crypto, clipboard, time } =
|
||||||
utools,
|
window.exports
|
||||||
existsSync,
|
|
||||||
readFileSync,
|
|
||||||
writeFileSync,
|
|
||||||
mkdirSync,
|
|
||||||
crypto,
|
|
||||||
listener,
|
|
||||||
clipboard,
|
|
||||||
time
|
|
||||||
} = window.exports
|
|
||||||
import setting from './readSetting'
|
import setting from './readSetting'
|
||||||
|
|
||||||
export default function initPlugin() {
|
export default function initPlugin() {
|
||||||
@ -214,31 +205,6 @@ export default function initPlugin() {
|
|||||||
db.addItem(item)
|
db.addItem(item)
|
||||||
}
|
}
|
||||||
|
|
||||||
const registerClipEvent = (listener) => {
|
|
||||||
const exitHandler = () => {
|
|
||||||
utools.showNotification('剪贴板监听异常退出 请重启插件以开启监听')
|
|
||||||
utools.outPlugin()
|
|
||||||
}
|
|
||||||
const errorHandler = (error) => {
|
|
||||||
const info = '请手动安装 clipboard-event-handler-linux 到 ~/.local/bin'
|
|
||||||
const site = 'https://ziuchen.gitee.io/project/ClipboardManager/guide/'
|
|
||||||
utools.showNotification('启动剪贴板监听出错: ' + error + info)
|
|
||||||
utools.shellOpenExternal(site)
|
|
||||||
utools.outPlugin()
|
|
||||||
}
|
|
||||||
listener
|
|
||||||
.on('change', handleClipboardChange)
|
|
||||||
.on('close', exitHandler)
|
|
||||||
.on('exit', exitHandler)
|
|
||||||
.on('error', (error) => errorHandler(error))
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!utools.isMacOs()) {
|
|
||||||
// 首次启动插件 即开启监听
|
|
||||||
registerClipEvent(listener)
|
|
||||||
listener.startListening()
|
|
||||||
} else {
|
|
||||||
// macos 由于无法执行 clipboard-event-handler-mac 所以使用旧方法
|
|
||||||
let prev = db.dataBase.data[0] || {}
|
let prev = db.dataBase.data[0] || {}
|
||||||
function loop() {
|
function loop() {
|
||||||
time.sleep(300).then(loop)
|
time.sleep(300).then(loop)
|
||||||
@ -254,25 +220,12 @@ export default function initPlugin() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
loop()
|
loop()
|
||||||
}
|
|
||||||
|
|
||||||
utools.onPluginEnter(() => {
|
utools.onPluginEnter(() => {
|
||||||
if (!listener.listening && !utools.isMacOs()) {
|
|
||||||
// 进入插件后 如果监听已关闭 则重新开启监听
|
|
||||||
registerClipEvent(listener)
|
|
||||||
listener.startListening()
|
|
||||||
}
|
|
||||||
toTop()
|
toTop()
|
||||||
resetNav()
|
resetNav()
|
||||||
})
|
})
|
||||||
|
|
||||||
utools.onPluginOut((processExit) => {
|
|
||||||
if (processExit && !utools.isMacOs()) {
|
|
||||||
utools.showNotification('剪贴板监听异常退出 请重启插件以开启监听')
|
|
||||||
listener.stopListening()
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
window.db = db
|
window.db = db
|
||||||
window.copy = copy
|
window.copy = copy
|
||||||
window.paste = paste
|
window.paste = paste
|
||||||
@ -280,5 +233,4 @@ export default function initPlugin() {
|
|||||||
window.createFile = createFile
|
window.createFile = createFile
|
||||||
window.focus = focus
|
window.focus = focus
|
||||||
window.toTop = toTop
|
window.toTop = toTop
|
||||||
window.listener = listener
|
|
||||||
}
|
}
|
||||||
|
@ -226,13 +226,6 @@ onMounted(() => {
|
|||||||
updateShowList(activeTab.value)
|
updateShowList(activeTab.value)
|
||||||
|
|
||||||
// 定期检查更新
|
// 定期检查更新
|
||||||
if (!utools.isMacOs) {
|
|
||||||
window.listener.on('change', () => {
|
|
||||||
list.value = window.db.dataBase.data
|
|
||||||
updateShowList(activeTab.value)
|
|
||||||
})
|
|
||||||
} else {
|
|
||||||
// macos
|
|
||||||
let prev = {}
|
let prev = {}
|
||||||
setInterval(() => {
|
setInterval(() => {
|
||||||
const now = window.db.dataBase.data[0]
|
const now = window.db.dataBase.data[0]
|
||||||
@ -244,7 +237,6 @@ onMounted(() => {
|
|||||||
prev = now
|
prev = now
|
||||||
}
|
}
|
||||||
}, 800)
|
}, 800)
|
||||||
}
|
|
||||||
|
|
||||||
// 监听搜索框
|
// 监听搜索框
|
||||||
watch(filterText, (val) => updateShowList(activeTab.value))
|
watch(filterText, (val) => updateShowList(activeTab.value))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user