🐛 Fix: settings bug

ISSUES CLOSED: #710
This commit is contained in:
PiEgg 2021-08-13 00:18:04 +08:00
parent ae692632a5
commit 20d3cf987c
5 changed files with 39 additions and 25 deletions

View File

@ -1,6 +1,6 @@
import PicGoCore from '~/universal/types/picgo' import PicGoCore from '~/universal/types/picgo'
import { dbChecker, dbPathChecker } from 'apis/core/datastore/dbChecker' import { dbChecker, dbPathChecker } from 'apis/core/datastore/dbChecker'
import fs from 'fs-extra' import pkg from 'root/package.json'
// 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') as typeof PicGoCore const PicGo = requireFunc('picgo') as typeof PicGoCore
@ -15,6 +15,7 @@ picgo.saveConfig({
PICGO_ENV: 'GUI' PICGO_ENV: 'GUI'
}) })
global.PICGO_GUI_VERSION = pkg.version
picgo.GUI_VERSION = global.PICGO_GUI_VERSION picgo.GUI_VERSION = global.PICGO_GUI_VERSION
export default picgo! as PicGoCore export default picgo! as PicGoCore

View File

@ -1,19 +1,12 @@
import fs from 'fs-extra' import fs from 'fs-extra'
import path from 'path' import path from 'path'
import os from 'os' import os from 'os'
import pkg from 'root/package.json'
import { dbPathChecker } from 'apis/core/datastore/dbChecker' import { dbPathChecker } from 'apis/core/datastore/dbChecker'
const configPath = dbPathChecker() const configPath = dbPathChecker()
const CONFIG_DIR = path.dirname(configPath) const CONFIG_DIR = path.dirname(configPath)
function injectPicGoVersion () {
global.PICGO_GUI_VERSION = pkg.version
global.PICGO_CORE_VERSION = pkg.dependencies.picgo.replace('^', '')
}
function beforeOpen () { function beforeOpen () {
injectPicGoVersion()
if (process.platform === 'darwin') { if (process.platform === 'darwin') {
resolveMacWorkFlow() resolveMacWorkFlow()
} }

View File

@ -72,7 +72,7 @@ import { cloneDeep, union } from 'lodash'
}) })
export default class extends Vue { export default class extends Vue {
@Prop() private config!: any[] @Prop() private config!: any[]
@Prop() readonly type!: string @Prop() readonly type!: 'uploader' | 'transformer' | 'plugin'
@Prop() readonly id!: string @Prop() readonly id!: string
configList = [] configList = []
ruleForm = {} ruleForm = {}
@ -80,9 +80,42 @@ export default class extends Vue {
deep: true, deep: true,
immediate: true immediate: true
}) })
async handleConfigChange (val: any) { handleConfigChange (val: any) {
this.handleConfig(val)
}
async validate () {
return new Promise((resolve, reject) => {
// @ts-ignore
this.$refs.form.validate((valid: boolean) => {
if (valid) {
resolve(this.ruleForm)
} else {
resolve(false)
return false
}
})
})
}
getConfigType () {
switch (this.type) {
case 'plugin': {
return this.id
}
case 'uploader': {
return `picBed.${this.id}`
}
case 'transformer': {
return `transformer.${this.id}`
}
default:
return `unknown`
}
}
async handleConfig (val: any) {
this.ruleForm = Object.assign({}, {}) this.ruleForm = Object.assign({}, {})
const config = await this.getConfig<IPicGoPluginConfig>(`picBed.${this.id}`) const config = await this.getConfig<IPicGoPluginConfig>(this.getConfigType())
if (val.length > 0 && config) { if (val.length > 0 && config) {
this.configList = cloneDeep(val).map((item: any) => { this.configList = cloneDeep(val).map((item: any) => {
let defaultValue = item.default !== undefined let defaultValue = item.default !== undefined
@ -102,19 +135,6 @@ export default class extends Vue {
}) })
} }
} }
async validate () {
return new Promise((resolve, reject) => {
// @ts-ignore
this.$refs.form.validate((valid: boolean) => {
if (valid) {
resolve(this.ruleForm)
} else {
resolve(false)
return false
}
})
})
}
} }
</script> </script>
<style lang='stylus'> <style lang='stylus'>

View File

@ -422,6 +422,7 @@ export default class extends Vue {
this.os = process.platform this.os = process.platform
ipcRenderer.send('getPicBeds') ipcRenderer.send('getPicBeds')
ipcRenderer.on('getPicBeds', this.getPicBeds) ipcRenderer.on('getPicBeds', this.getPicBeds)
this.initData()
} }
async initData () { async initData () {
const config = (await this.getConfig<IConfig>())! const config = (await this.getConfig<IConfig>())!

View File

@ -11,7 +11,6 @@ export default class extends Vue {
[config]: value [config]: value
} }
} }
console.log(PICGO_SAVE_CONFIG, config, value)
ipcRenderer.send(PICGO_SAVE_CONFIG, config) ipcRenderer.send(PICGO_SAVE_CONFIG, config)
} }
getConfig<T> (key?: string): Promise<T | undefined> { getConfig<T> (key?: string): Promise<T | undefined> {