From f65d2d2df425ffc52e92ad68cc74005a84a9f68c Mon Sep 17 00:00:00 2001 From: Molunerfinn Date: Tue, 2 Apr 2019 17:11:01 +0800 Subject: [PATCH] Fixed: npm ENOENT bug && mini window display -> false by default --- src/main/index.js | 2 +- src/main/utils/picgoCoreIPC.js | 33 ++++++++++++++++++++++++++++----- 2 files changed, 29 insertions(+), 6 deletions(-) diff --git a/src/main/index.js b/src/main/index.js index 353684b4..eb98adbf 100644 --- a/src/main/index.js +++ b/src/main/index.js @@ -219,7 +219,7 @@ const createMiniWidow = () => { let obj = { height: 64, width: 64, - show: true, + show: false, frame: false, fullscreenable: false, skipTaskbar: true, diff --git a/src/main/utils/picgoCoreIPC.js b/src/main/utils/picgoCoreIPC.js index 80281b31..89190b2d 100644 --- a/src/main/utils/picgoCoreIPC.js +++ b/src/main/utils/picgoCoreIPC.js @@ -1,5 +1,6 @@ import path from 'path' import GuiApi from './guiApi' +import { dialog, shell } from 'electron' // eslint-disable-next-line const requireFunc = typeof __webpack_require__ === 'function' ? __non_webpack_require__ : require @@ -89,41 +90,63 @@ const handleGetPluginList = (ipcMain, STORE_PATH, CONFIG_PATH) => { } const handlePluginInstall = (ipcMain, CONFIG_PATH) => { - ipcMain.on('installPlugin', (event, msg) => { + ipcMain.on('installPlugin', async (event, msg) => { const picgo = new PicGo(CONFIG_PATH) const pluginHandler = new PluginHandler(picgo) picgo.on('installSuccess', notice => { event.sender.send('installSuccess', notice.body[0].replace(/picgo-plugin-/, '')) }) + picgo.on('failed', () => { + handleNPMError() + }) + await pluginHandler.uninstall([msg]) pluginHandler.install([msg]) picgo.cmd.program.removeAllListeners() }) } const handlePluginUninstall = (ipcMain, CONFIG_PATH) => { - ipcMain.on('uninstallPlugin', (event, msg) => { + ipcMain.on('uninstallPlugin', async (event, msg) => { const picgo = new PicGo(CONFIG_PATH) const pluginHandler = new PluginHandler(picgo) picgo.on('uninstallSuccess', notice => { event.sender.send('uninstallSuccess', notice.body[0].replace(/picgo-plugin-/, '')) }) - pluginHandler.uninstall([msg]) + picgo.on('failed', () => { + handleNPMError() + }) + await pluginHandler.uninstall([msg]) picgo.cmd.program.removeAllListeners() }) } const handlePluginUpdate = (ipcMain, CONFIG_PATH) => { - ipcMain.on('updatePlugin', (event, msg) => { + ipcMain.on('updatePlugin', async (event, msg) => { const picgo = new PicGo(CONFIG_PATH) const pluginHandler = new PluginHandler(picgo) picgo.on('updateSuccess', notice => { event.sender.send('updateSuccess', notice.body[0].replace(/picgo-plugin-/, '')) }) - pluginHandler.update([msg]) + picgo.on('failed', () => { + handleNPMError() + }) + await pluginHandler.update([msg]) picgo.cmd.program.removeAllListeners() }) } +const handleNPMError = () => { + dialog.showMessageBox({ + title: '发生错误', + message: '请安装Node.js并重启PicGo再继续操作', + buttons: ['Yes'] + }, (res) => { + if (res === 0) { + shell.openExternal('https://nodejs.org/') + } + }) +} + const handleGetPicBedConfig = (ipcMain, CONFIG_PATH) => { ipcMain.on('getPicBedConfig', (event, type) => { const picgo = new PicGo(CONFIG_PATH)