🐛 Fix: give a hint when node.js is not installed

This commit is contained in:
Molunerfinn 2020-04-11 20:52:04 +08:00
parent 96cdfea497
commit 7e866185e9
2 changed files with 26 additions and 12 deletions

View File

@ -111,14 +111,16 @@ const handleGetPluginList = () => {
const handlePluginInstall = () => { const handlePluginInstall = () => {
ipcMain.on('installPlugin', async (event: IpcMainEvent, msg: string) => { ipcMain.on('installPlugin', async (event: IpcMainEvent, msg: string) => {
const dispose = handleNPMError()
picgo.once('installSuccess', (notice: PicGoNotice) => { picgo.once('installSuccess', (notice: PicGoNotice) => {
event.sender.send('installSuccess', notice.body[0].replace(/picgo-plugin-/, '')) event.sender.send('installSuccess', notice.body[0].replace(/picgo-plugin-/, ''))
shortKeyHandler.registerPluginShortKey(notice.body[0]) shortKeyHandler.registerPluginShortKey(notice.body[0])
picgo.removeAllListeners('installFailed') picgo.removeAllListeners('installFailed')
dispose()
}) })
picgo.once('installFailed', () => { picgo.once('installFailed', () => {
handleNPMError()
picgo.removeAllListeners('installSuccess') picgo.removeAllListeners('installSuccess')
dispose()
}) })
await picgo.pluginHandler.install([msg]) await picgo.pluginHandler.install([msg])
picgo.cmd.program.removeAllListeners() picgo.cmd.program.removeAllListeners()
@ -127,14 +129,16 @@ const handlePluginInstall = () => {
const handlePluginUninstall = () => { const handlePluginUninstall = () => {
ipcMain.on('uninstallPlugin', async (event: IpcMainEvent, msg: string) => { ipcMain.on('uninstallPlugin', async (event: IpcMainEvent, msg: string) => {
const dispose = handleNPMError()
picgo.once('uninstallSuccess', (notice: PicGoNotice) => { picgo.once('uninstallSuccess', (notice: PicGoNotice) => {
event.sender.send('uninstallSuccess', notice.body[0].replace(/picgo-plugin-/, '')) event.sender.send('uninstallSuccess', notice.body[0].replace(/picgo-plugin-/, ''))
shortKeyHandler.unregisterPluginShortKey(notice.body[0]) shortKeyHandler.unregisterPluginShortKey(notice.body[0])
picgo.removeAllListeners('uninstallFailed') picgo.removeAllListeners('uninstallFailed')
dispose()
}) })
picgo.once('uninstallFailed', () => { picgo.once('uninstallFailed', () => {
handleNPMError()
picgo.removeAllListeners('uninstallSuccess') picgo.removeAllListeners('uninstallSuccess')
dispose()
}) })
await picgo.pluginHandler.uninstall([msg]) await picgo.pluginHandler.uninstall([msg])
picgo.cmd.program.removeAllListeners() picgo.cmd.program.removeAllListeners()
@ -143,29 +147,37 @@ const handlePluginUninstall = () => {
const handlePluginUpdate = () => { const handlePluginUpdate = () => {
ipcMain.on('updatePlugin', async (event: IpcMainEvent, msg: string) => { ipcMain.on('updatePlugin', async (event: IpcMainEvent, msg: string) => {
const dispose = handleNPMError()
picgo.once('updateSuccess', (notice: { body: string[], title: string }) => { picgo.once('updateSuccess', (notice: { body: string[], title: string }) => {
event.sender.send('updateSuccess', notice.body[0].replace(/picgo-plugin-/, '')) event.sender.send('updateSuccess', notice.body[0].replace(/picgo-plugin-/, ''))
picgo.removeAllListeners('updateFailed') picgo.removeAllListeners('updateFailed')
dispose()
}) })
picgo.once('updateFailed', () => { picgo.once('updateFailed', () => {
handleNPMError()
picgo.removeAllListeners('updateSuccess') picgo.removeAllListeners('updateSuccess')
dispose()
}) })
await picgo.pluginHandler.update([msg]) await picgo.pluginHandler.update([msg])
picgo.cmd.program.removeAllListeners() picgo.cmd.program.removeAllListeners()
}) })
} }
const handleNPMError = () => { const handleNPMError = (): IDispose => {
dialog.showMessageBox({ const handler = (msg: string) => {
title: '发生错误', if (msg === 'NPM is not installed') {
message: '请安装Node.js并重启PicGo再继续操作', dialog.showMessageBox({
buttons: ['Yes'] title: '发生错误',
}).then((res) => { message: '请安装Node.js并重启PicGo再继续操作',
if (res.response === 0) { buttons: ['Yes']
shell.openExternal('https://nodejs.org/') }).then((res) => {
if (res.response === 0) {
shell.openExternal('https://nodejs.org/')
}
})
} }
}) }
picgo.once('failed', handler)
return () => picgo.off('failed', handler)
} }
const handleGetPicBedConfig = () => { const handleGetPicBedConfig = () => {

View File

@ -170,6 +170,8 @@ interface INPMSearchResultObject {
} }
} }
type IDispose = () => void
// GuiApi // GuiApi
interface IGuiApi { interface IGuiApi {
showInputBox: (options: IShowInputBoxOption) => Promise<string> showInputBox: (options: IShowInputBoxOption) => Promise<string>