mirror of
https://github.com/Kuingsmile/PicList.git
synced 2026-09-05 23:47:43 +08:00
Fixed: plugin handler require bug
This commit is contained in:
@@ -3,7 +3,7 @@ import path from 'path'
|
|||||||
// eslint-disable-next-line
|
// eslint-disable-next-line
|
||||||
const requireFunc = typeof __webpack_require__ === 'function' ? __non_webpack_require__ : require
|
const requireFunc = typeof __webpack_require__ === 'function' ? __non_webpack_require__ : require
|
||||||
const PicGo = requireFunc('picgo')
|
const PicGo = requireFunc('picgo')
|
||||||
const PluginHandler = requireFunc('picgo/lib/PluginHandler')
|
const PluginHandler = requireFunc('picgo/dist/lib/PluginHandler').default
|
||||||
|
|
||||||
// get uploader or transformer config
|
// get uploader or transformer config
|
||||||
const getConfig = (name, type, ctx) => {
|
const getConfig = (name, type, ctx) => {
|
||||||
@@ -46,7 +46,7 @@ const handleGetPluginList = (ipcMain, STORE_PATH, CONFIG_PATH) => {
|
|||||||
const transformerName = plugin.transformer || ''
|
const transformerName = plugin.transformer || ''
|
||||||
const obj = {
|
const obj = {
|
||||||
name: pluginList[i].replace(/picgo-plugin-/, ''),
|
name: pluginList[i].replace(/picgo-plugin-/, ''),
|
||||||
author: pluginPKG.author,
|
author: pluginPKG.author.name || pluginPKG.author,
|
||||||
description: pluginPKG.description,
|
description: pluginPKG.description,
|
||||||
logo: 'file://' + path.join(pluginPath, 'logo.png').split(path.sep).join('/'),
|
logo: 'file://' + path.join(pluginPath, 'logo.png').split(path.sep).join('/'),
|
||||||
config: {
|
config: {
|
||||||
@@ -83,9 +83,22 @@ const handlePluginInstall = (ipcMain, STORE_PATH, CONFIG_PATH) => {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const handlePluginUninstall = (ipcMain, STORE_PATH, CONFIG_PATH) => {
|
||||||
|
ipcMain.on('uninstallPlugin', (event, msg) => {
|
||||||
|
const picgo = new PicGo(CONFIG_PATH)
|
||||||
|
const pluginHandler = new PluginHandler(picgo)
|
||||||
|
console.log(msg, 123)
|
||||||
|
picgo.on('uninstallSuccess', (plugin) => {
|
||||||
|
console.log(plugin)
|
||||||
|
})
|
||||||
|
pluginHandler.uninstall([`picgo-plugin-${msg}`])
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
export default (app, ipcMain) => {
|
export default (app, ipcMain) => {
|
||||||
const STORE_PATH = app.getPath('userData')
|
const STORE_PATH = app.getPath('userData')
|
||||||
const CONFIG_PATH = path.join(STORE_PATH, '/data.json')
|
const CONFIG_PATH = path.join(STORE_PATH, '/data.json')
|
||||||
handleGetPluginList(ipcMain, STORE_PATH, CONFIG_PATH)
|
handleGetPluginList(ipcMain, STORE_PATH, CONFIG_PATH)
|
||||||
handlePluginInstall(ipcMain, STORE_PATH, CONFIG_PATH)
|
handlePluginInstall(ipcMain, STORE_PATH, CONFIG_PATH)
|
||||||
|
handlePluginUninstall(ipcMain, STORE_PATH, CONFIG_PATH)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -137,6 +137,12 @@ export default {
|
|||||||
plugin.enabled = false
|
plugin.enabled = false
|
||||||
// plugin.reload = true
|
// plugin.reload = true
|
||||||
}
|
}
|
||||||
|
}, {
|
||||||
|
label: '卸载插件',
|
||||||
|
click () {
|
||||||
|
_this.loading = true
|
||||||
|
_this.uninstallPlugin(plugin.name)
|
||||||
|
}
|
||||||
}]
|
}]
|
||||||
for (let i in plugin.config) {
|
for (let i in plugin.config) {
|
||||||
if (plugin.config[i].config.length > 0) {
|
if (plugin.config[i].config.length > 0) {
|
||||||
@@ -161,6 +167,9 @@ export default {
|
|||||||
installPlugin (val) {
|
installPlugin (val) {
|
||||||
this.$electron.ipcRenderer.send('installPlugin', val)
|
this.$electron.ipcRenderer.send('installPlugin', val)
|
||||||
},
|
},
|
||||||
|
uninstallPlugin (val) {
|
||||||
|
this.$electron.ipcRenderer.send('uninstallPlugin', val)
|
||||||
|
},
|
||||||
reloadApp () {
|
reloadApp () {
|
||||||
this.$electron.remote.app.relaunch()
|
this.$electron.remote.app.relaunch()
|
||||||
this.$electron.remote.app.exit(0)
|
this.$electron.remote.app.exit(0)
|
||||||
@@ -215,6 +224,7 @@ export default {
|
|||||||
config: {},
|
config: {},
|
||||||
homepage: item.package.links ? item.package.links.homepage : '',
|
homepage: item.package.links ? item.package.links.homepage : '',
|
||||||
hasInstall: this.pluginNameList.some(plugin => plugin === item.package.name),
|
hasInstall: this.pluginNameList.some(plugin => plugin === item.package.name),
|
||||||
|
installing: false,
|
||||||
reload: false
|
reload: false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user