refactor: 移除添加监听时对Mac的特殊判断 移除了缺少监听器的报错通知

This commit is contained in:
ZiuChen 2022-11-02 23:16:22 +08:00
parent 18cbab4bda
commit bb83b2c4ff
3 changed files with 13 additions and 16 deletions

View File

@ -12,7 +12,8 @@ class ClipboardEventListener extends EventEmitter {
startListening(dbPath) {
const targetMap = {
win32: 'clipboard-event-handler-win32.exe',
linux: 'clipboard-event-handler-linux'
linux: 'clipboard-event-handler-linux',
darwin: 'clipboard-event-handler-mac'
}
const { platform } = process
const target = path.resolve(
@ -25,7 +26,7 @@ class ClipboardEventListener extends EventEmitter {
}
if (platform === 'win32') {
this.child = execFile(target)
} else if (platform === 'linux') {
} else if (platform === 'linux' || platform === 'darwin') {
chmodSync(target, 0o755)
this.child = execFile(target)
} else {

View File

@ -217,8 +217,8 @@ export default function initPlugin() {
utools.outPlugin()
}
const errorHandler = (error) => {
const info = '请到设置页检查剪贴板监听程序状态'
utools.showNotification('启动剪贴板监听程序启动出错: ' + error + info)
// const info = '请到设置页检查剪贴板监听程序状态'
// utools.showNotification('启动剪贴板监听程序启动出错: ' + error + info)
addCommonListener()
}
listener
@ -228,17 +228,13 @@ export default function initPlugin() {
.on('error', (error) => errorHandler(error))
}
if (!utools.isMacOs()) {
// 首次启动插件 即开启监听
// 如果监听程序异常退出 则会在errorHandler中开启常规监听
registerClipEvent(listener)
listener.startListening(setting.database.path[nativeId])
} else {
// macos 由于无法执行 clipboard-event-handler-mac 所以使用旧方法
addCommonListener()
}
utools.onPluginEnter(() => {
if (!listener.listening && !utools.isMacOs()) {
if (!listener.listening) {
// 进入插件后 如果监听已关闭 则重新开启监听
registerClipEvent(listener)
listener.startListening(setting.database.path[nativeId])

View File

@ -226,14 +226,14 @@ onMounted(() => {
updateShowList(activeTab.value)
//
if (!utools.isMacOs() && window.listener.listening) {
// macOS
if (window.listener.listening) {
//
window.listener.on('change', () => {
list.value = window.db.dataBase.data
updateShowList(activeTab.value)
})
} else {
// macOS
//
let prev = {}
setInterval(() => {
const now = window.db.dataBase.data[0]