diff --git a/src/main/events/picgoCoreIPC.ts b/src/main/events/picgoCoreIPC.ts index 42d2fd4..8d0335f 100644 --- a/src/main/events/picgoCoreIPC.ts +++ b/src/main/events/picgoCoreIPC.ts @@ -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() diff --git a/src/renderer/pages/Plugin.vue b/src/renderer/pages/Plugin.vue index 67fc17b..944d51e 100644 --- a/src/renderer/pages/Plugin.vue +++ b/src/renderer/pages/Plugin.vue @@ -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')