Fixed: bug with function in config

This commit is contained in:
Molunerfinn 2018-09-20 15:14:19 +08:00
parent 4a420dd5c5
commit c3b2d7b941
2 changed files with 16 additions and 7 deletions

View File

@ -20,6 +20,18 @@ const getConfig = (name, type, ctx) => {
}
}
const handleConfigWithFunction = config => {
for (let i in config) {
if (typeof config[i].default === 'function') {
config[i].default = config[i].default()
}
if (typeof config[i].choices === 'function') {
config[i].choices = config[i].choices()
}
}
return config
}
export default (app, ipcMain) => {
const STORE_PATH = app.getPath('userData')
const CONFIG_PATH = path.join(STORE_PATH, '/data.json')
@ -42,15 +54,15 @@ export default (app, ipcMain) => {
config: {
plugin: {
name: pluginList[i].replace(/picgo-plugin-/, ''),
config: plugin.config ? plugin.config(picgo) : []
config: plugin.config ? handleConfigWithFunction(plugin.config(picgo)) : []
},
uploader: {
name: uploaderName,
config: getConfig(uploaderName, 'uploader', picgo)
config: handleConfigWithFunction(getConfig(uploaderName, 'uploader', picgo))
},
transformer: {
name: transformerName,
config: getConfig(uploaderName, 'transformer', picgo)
config: handleConfigWithFunction(getConfig(uploaderName, 'transformer', picgo))
}
},
enabled: picgo.getConfig(`plugins.${pluginList[i]}`)

View File

@ -79,10 +79,7 @@ export default {
},
created () {
this.$electron.ipcRenderer.on('pluginList', (evt, list) => {
this.pluginList = list.map(item => {
// item.reload = false
return item
})
this.pluginList = list.map(item => item)
})
this.getPluginList()
document.addEventListener('keydown', (e) => {