|
1 | 1 | import path from 'path'
|
2 | 2 | import GuiApi from './guiApi'
|
| 3 | +import { dialog, shell } from 'electron' |
3 | 4 |
|
4 | 5 | // eslint-disable-next-line
|
5 | 6 | const requireFunc = typeof __webpack_require__ === 'function' ? __non_webpack_require__ : require
|
@@ -89,41 +90,63 @@ const handleGetPluginList = (ipcMain, STORE_PATH, CONFIG_PATH) => {
|
89 | 90 | }
|
90 | 91 |
|
91 | 92 | const handlePluginInstall = (ipcMain, CONFIG_PATH) => {
|
92 |
| - ipcMain.on('installPlugin', (event, msg) => { |
| 93 | + ipcMain.on('installPlugin', async (event, msg) => { |
93 | 94 | const picgo = new PicGo(CONFIG_PATH)
|
94 | 95 | const pluginHandler = new PluginHandler(picgo)
|
95 | 96 | picgo.on('installSuccess', notice => {
|
96 | 97 | event.sender.send('installSuccess', notice.body[0].replace(/picgo-plugin-/, ''))
|
97 | 98 | })
|
| 99 | + picgo.on('failed', () => { |
| 100 | + handleNPMError() |
| 101 | + }) |
| 102 | + await pluginHandler.uninstall([msg]) |
98 | 103 | pluginHandler.install([msg])
|
99 | 104 | picgo.cmd.program.removeAllListeners()
|
100 | 105 | })
|
101 | 106 | }
|
102 | 107 |
|
103 | 108 | const handlePluginUninstall = (ipcMain, CONFIG_PATH) => {
|
104 |
| - ipcMain.on('uninstallPlugin', (event, msg) => { |
| 109 | + ipcMain.on('uninstallPlugin', async (event, msg) => { |
105 | 110 | const picgo = new PicGo(CONFIG_PATH)
|
106 | 111 | const pluginHandler = new PluginHandler(picgo)
|
107 | 112 | picgo.on('uninstallSuccess', notice => {
|
108 | 113 | event.sender.send('uninstallSuccess', notice.body[0].replace(/picgo-plugin-/, ''))
|
109 | 114 | })
|
110 |
| - pluginHandler.uninstall([msg]) |
| 115 | + picgo.on('failed', () => { |
| 116 | + handleNPMError() |
| 117 | + }) |
| 118 | + await pluginHandler.uninstall([msg]) |
111 | 119 | picgo.cmd.program.removeAllListeners()
|
112 | 120 | })
|
113 | 121 | }
|
114 | 122 |
|
115 | 123 | const handlePluginUpdate = (ipcMain, CONFIG_PATH) => {
|
116 |
| - ipcMain.on('updatePlugin', (event, msg) => { |
| 124 | + ipcMain.on('updatePlugin', async (event, msg) => { |
117 | 125 | const picgo = new PicGo(CONFIG_PATH)
|
118 | 126 | const pluginHandler = new PluginHandler(picgo)
|
119 | 127 | picgo.on('updateSuccess', notice => {
|
120 | 128 | event.sender.send('updateSuccess', notice.body[0].replace(/picgo-plugin-/, ''))
|
121 | 129 | })
|
122 |
| - pluginHandler.update([msg]) |
| 130 | + picgo.on('failed', () => { |
| 131 | + handleNPMError() |
| 132 | + }) |
| 133 | + await pluginHandler.update([msg]) |
123 | 134 | picgo.cmd.program.removeAllListeners()
|
124 | 135 | })
|
125 | 136 | }
|
126 | 137 |
|
| 138 | +const handleNPMError = () => { |
| 139 | + dialog.showMessageBox({ |
| 140 | + title: '发生错误', |
| 141 | + message: '请安装Node.js并重启PicGo再继续操作', |
| 142 | + buttons: ['Yes'] |
| 143 | + }, (res) => { |
| 144 | + if (res === 0) { |
| 145 | + shell.openExternal('https://nodejs.org/') |
| 146 | + } |
| 147 | + }) |
| 148 | +} |
| 149 | + |
127 | 150 | const handleGetPicBedConfig = (ipcMain, CONFIG_PATH) => {
|
128 | 151 | ipcMain.on('getPicBedConfig', (event, type) => {
|
129 | 152 | const picgo = new PicGo(CONFIG_PATH)
|
|
0 commit comments