diff --git a/src/main/apis/core/picgo/index.ts b/src/main/apis/core/picgo/index.ts index 94a6331d..08b68600 100644 --- a/src/main/apis/core/picgo/index.ts +++ b/src/main/apis/core/picgo/index.ts @@ -1,6 +1,6 @@ import PicGoCore from '~/universal/types/picgo' import { dbChecker, dbPathChecker } from 'apis/core/datastore/dbChecker' -import fs from 'fs-extra' +import pkg from 'root/package.json' // eslint-disable-next-line const requireFunc = typeof __webpack_require__ === 'function' ? __non_webpack_require__ : require const PicGo = requireFunc('picgo') as typeof PicGoCore @@ -15,6 +15,7 @@ picgo.saveConfig({ PICGO_ENV: 'GUI' }) +global.PICGO_GUI_VERSION = pkg.version picgo.GUI_VERSION = global.PICGO_GUI_VERSION export default picgo! as PicGoCore diff --git a/src/main/utils/beforeOpen.ts b/src/main/utils/beforeOpen.ts index db84d32e..90da106f 100644 --- a/src/main/utils/beforeOpen.ts +++ b/src/main/utils/beforeOpen.ts @@ -1,19 +1,12 @@ import fs from 'fs-extra' import path from 'path' import os from 'os' -import pkg from 'root/package.json' import { dbPathChecker } from 'apis/core/datastore/dbChecker' const configPath = dbPathChecker() const CONFIG_DIR = path.dirname(configPath) -function injectPicGoVersion () { - global.PICGO_GUI_VERSION = pkg.version - global.PICGO_CORE_VERSION = pkg.dependencies.picgo.replace('^', '') -} - function beforeOpen () { - injectPicGoVersion() if (process.platform === 'darwin') { resolveMacWorkFlow() } diff --git a/src/renderer/components/ConfigForm.vue b/src/renderer/components/ConfigForm.vue index 519833be..17a118f8 100644 --- a/src/renderer/components/ConfigForm.vue +++ b/src/renderer/components/ConfigForm.vue @@ -72,7 +72,7 @@ import { cloneDeep, union } from 'lodash' }) export default class extends Vue { @Prop() private config!: any[] - @Prop() readonly type!: string + @Prop() readonly type!: 'uploader' | 'transformer' | 'plugin' @Prop() readonly id!: string configList = [] ruleForm = {} @@ -80,9 +80,42 @@ export default class extends Vue { deep: 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({}, {}) - const config = await this.getConfig(`picBed.${this.id}`) + const config = await this.getConfig(this.getConfigType()) if (val.length > 0 && config) { this.configList = cloneDeep(val).map((item: any) => { 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 - } - }) - }) - } }