Added: plugin config save

This commit is contained in:
Molunerfinn 2018-09-20 14:49:20 +08:00
parent 51281f345b
commit 4a420dd5c5
4 changed files with 57 additions and 26 deletions

View File

@ -23,9 +23,9 @@ const getConfig = (name, type, ctx) => {
export default (app, ipcMain) => {
const STORE_PATH = app.getPath('userData')
const CONFIG_PATH = path.join(STORE_PATH, '/data.json')
const picgo = new PicGo(CONFIG_PATH)
ipcMain.on('getPluginList', event => {
const picgo = new PicGo(CONFIG_PATH)
const pluginList = picgo.pluginLoader.getList()
const list = []
for (let i in pluginList) {

View File

@ -10,7 +10,8 @@ import fecha from 'fecha'
// eslint-disable-next-line
const requireFunc = typeof __webpack_require__ === 'function' ? __non_webpack_require__ : require
const PicGo = requireFunc('picgo')
const STORE_PATH = app.getPath('userData')
const CONFIG_PATH = path.join(STORE_PATH, '/data.json')
const renameURL = process.env.NODE_ENV === 'development' ? `http://localhost:9080/#rename-page` : `file://${__dirname}/index.html#rename-page`
const createRenameWindow = () => {
@ -38,9 +39,6 @@ const createRenameWindow = () => {
return window
}
const STORE_PATH = app.getPath('userData')
const CONFIG_PATH = path.join(STORE_PATH, '/data.json')
const waitForShow = (webcontent) => {
return new Promise((resolve, reject) => {
webcontent.on('dom-ready', () => {

View File

@ -9,10 +9,10 @@
>
<el-form-item
v-for="(item, index) in configList"
:key="index"
:label="item.name"
:required="item.required"
:prop="item.name"
:key="item.name + index"
>
<el-input
v-if="item.type === 'input' || item.type === 'password'"
@ -44,6 +44,7 @@
</div>
</template>
<script>
import { cloneDeep } from 'lodash'
export default {
name: 'config-form',
props: {
@ -58,23 +59,36 @@ export default {
}
},
created () {
this.configList = JSON.parse(JSON.stringify(this.config)).map(item => {
this.configList = cloneDeep(this.config).map(item => {
const defaultValue = item.default !== undefined ? item.default : null
this.$set(this.ruleForm, item.name, defaultValue)
return item
})
},
mounted () {
console.log(this.$refs.form)
watch: {
config: {
deep: true,
handler (val) {
this.ruleForm = Object.assign({}, {})
this.configList = cloneDeep(val).map(item => {
const defaultValue = item.default !== undefined ? item.default : null
this.$set(this.ruleForm, item.name, defaultValue)
return item
})
}
}
},
methods: {
validate () {
this.$refs.form.validate(valid => {
if (valid) {
console.log(this.ruleForm)
} else {
return false
}
async validate () {
return new Promise((resolve, reject) => {
this.$refs.form.validate(valid => {
if (valid) {
resolve(this.ruleForm)
} else {
resolve(false)
return false
}
})
})
}
}

View File

@ -26,9 +26,9 @@
{{ item.author }}
</span>
<span class="plugin-item__config" >
<span class="reload-button" v-if="item.reload" @click="reloadApp">
<!-- <span class="reload-button" v-if="item.reload" @click="reloadApp">
重启
</span>
</span> -->
<i
class="el-icon-setting"
@click="buildContextMenu(item)"
@ -80,7 +80,7 @@ export default {
created () {
this.$electron.ipcRenderer.on('pluginList', (evt, list) => {
this.pluginList = list.map(item => {
item.reload = false
// item.reload = false
return item
})
})
@ -100,7 +100,7 @@ export default {
click () {
_this.$db.read().set(`plugins.picgo-plugin-${plugin.name}`, true).write()
plugin.enabled = true
plugin.reload = true
// plugin.reload = true
}
}, {
label: '禁用插件',
@ -108,7 +108,7 @@ export default {
click () {
_this.$db.read().set(`plugins.picgo-plugin-${plugin.name}`, false).write()
plugin.enabled = false
plugin.reload = true
// plugin.reload = true
}
}]
for (let i in plugin.config) {
@ -116,11 +116,10 @@ export default {
const obj = {
label: `配置${i} - ${plugin.config[i].name}`,
click () {
_this.configType = i
_this.currentType = i
_this.configName = plugin.config[i].name
_this.dialogVisible = true
_this.config = plugin.config[i].config
console.log(plugin.config[i].config)
}
}
menu.push(obj)
@ -136,9 +135,29 @@ export default {
this.$electron.remote.app.relaunch()
this.$electron.remote.app.exit(0)
},
handleConfirmConfig () {
console.log(this.$refs.configForm)
this.$refs.configForm.validate()
async handleConfirmConfig () {
const result = await this.$refs.configForm.validate()
if (result !== false) {
switch (this.currentType) {
case 'plugin':
this.$db.read().set(`picgo-plugin-${this.configName}`, result).write()
break
case 'uploader':
this.$db.read().set(`picBed.${this.configName}`, result).write()
break
case 'transformer':
this.$db.read().set(`transformer.${this.configName}`, result).write()
break
}
const successNotification = new window.Notification('设置结果', {
body: '设置成功'
})
successNotification.onclick = () => {
return true
}
this.dialogVisible = false
this.getPluginList()
}
}
}
}