fix: linux文件拷贝错误抛出异常

This commit is contained in:
ZiuChen 2022-09-20 19:35:01 +08:00
parent f3c7d3899b
commit 8e681c7a75
2 changed files with 13 additions and 8 deletions

View File

@ -22,9 +22,13 @@ class ClipboardEventListener extends EventEmitter {
const target = path.resolve(targetPath, 'clipboard-event-handler-linux')
const p = path.join(__dirname, 'platform/clipboard-event-handler-linux')
if(!existsSync(target)) {
mkdirSync(targetPath)
copyFileSync(p, target)
chmodSync(target, 0o755)
try {
mkdirSync(targetPath)
copyFileSync(p, target)
chmodSync(target, 0o755)
} catch (error) {
this.emit('error', error)
}
}
this.child = execFile(target);
}

View File

@ -194,10 +194,7 @@ export default function initPlugin() {
const registerClipEvent = (listener) => {
const errorHandler = () => {
const info = '如监听失效 请手动安装 clipboard-event-handler-linux 到 ~/.local/bin'
utools.showNotification(
'剪贴板监听异常退出 请重启插件以开启监听' + (utools.isLinux() ? info : '')
)
utools.showNotification('剪贴板监听异常退出 请重启插件以开启监听')
utools.outPlugin()
}
listener
@ -217,7 +214,10 @@ export default function initPlugin() {
.on('close', errorHandler)
.on('exit', errorHandler)
.on('error', (error) => {
utools.showNotification('剪贴板监听出错' + 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()
})
}
@ -242,6 +242,7 @@ export default function initPlugin() {
utools.onPluginOut((processExit) => {
if (processExit) {
utools.showNotification('剪贴板监听异常退出 请重启插件以开启监听')
listener.stopListening()
}
})