🐛 Fix: add plugin install failed notice

This commit is contained in:
PiEgg 2021-04-11 11:11:22 +08:00
parent 992ff35936
commit b05139fc9a
2 changed files with 31 additions and 9 deletions

View File

@ -121,12 +121,21 @@ const handleGetPluginList = () => {
}
const handlePluginInstall = () => {
ipcMain.on('installPlugin', async (event: IpcMainEvent, msg: string) => {
ipcMain.on('installPlugin', async (event: IpcMainEvent, fullName: string) => {
const dispose = handleNPMError()
const res = await picgo.pluginHandler.install([msg])
const res = await picgo.pluginHandler.install([fullName])
event.sender.send('installPlugin', {
success: res.success,
body: fullName,
errMsg: res.success ? '' : res.body
})
if (res.success) {
event.sender.send('installSuccess', res.body[0])
shortKeyHandler.registerPluginShortKey(res.body[0])
} else {
showNotification({
title: '插件安装失败',
body: res.body as string
})
}
event.sender.send('hideLoading')
dispose()
@ -140,6 +149,11 @@ const handlePluginUninstall = () => {
if (res.success) {
event.sender.send('uninstallSuccess', res.body[0])
shortKeyHandler.unregisterPluginShortKey(res.body[0])
} else {
showNotification({
title: '插件卸载失败',
body: res.body as string
})
}
event.sender.send('hideLoading')
dispose()
@ -152,6 +166,11 @@ const handlePluginUpdate = () => {
const res = await picgo.pluginHandler.update([msg])
if (res.success) {
event.sender.send('updateSuccess', res.body[0])
} else {
showNotification({
title: '插件更新失败',
body: res.body as string
})
}
event.sender.send('hideLoading')
dispose()

View File

@ -174,12 +174,15 @@ export default class extends Vue {
this.pluginNameList = list.map(item => item.fullName)
this.loading = false
})
ipcRenderer.on('installSuccess', (evt: IpcRendererEvent, plugin: string) => {
ipcRenderer.on('installPlugin', (evt: IpcRendererEvent, { success, body }: {
success: boolean,
body: string
}) => {
this.loading = false
this.pluginList.forEach(item => {
if (item.fullName === plugin) {
if (item.fullName === body) {
item.ing = false
item.hasInstall = true
item.hasInstall = success
}
})
})
@ -315,13 +318,13 @@ export default class extends Vue {
type: 'warning'
}).then(() => {
item.ing = true
ipcRenderer.send('installPlugin', item.name)
ipcRenderer.send('installPlugin', item.fullName)
}).catch(() => {
console.log('Install canceled')
})
} else {
item.ing = true
ipcRenderer.send('installPlugin', item.name)
ipcRenderer.send('installPlugin', item.fullName)
}
}
uninstallPlugin (val: string) {
@ -479,7 +482,7 @@ export default class extends Vue {
}
beforeDestroy () {
ipcRenderer.removeAllListeners('pluginList')
ipcRenderer.removeAllListeners('installSuccess')
ipcRenderer.removeAllListeners('installPlugin')
ipcRenderer.removeAllListeners('uninstallSuccess')
ipcRenderer.removeAllListeners('updateSuccess')
ipcRenderer.removeAllListeners('hideLoading')