Skip to content

Commit

Permalink
🐛 Fix: settings bug
Browse files Browse the repository at this point in the history
ISSUES CLOSED: #710
  • Loading branch information
Molunerfinn committed Aug 12, 2021
1 parent ae69263 commit 20d3cf9
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 25 deletions.
3 changes: 2 additions & 1 deletion src/main/apis/core/picgo/index.ts
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
7 changes: 0 additions & 7 deletions src/main/utils/beforeOpen.ts
Original file line number Diff line number Diff line change
@@ -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()
}
Expand Down
52 changes: 36 additions & 16 deletions src/renderer/components/ConfigForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -72,17 +72,50 @@ 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 = {}
@Watch('config', {
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<IPicGoPluginConfig>(`picBed.${this.id}`)
const config = await this.getConfig<IPicGoPluginConfig>(this.getConfigType())
if (val.length > 0 && config) {
this.configList = cloneDeep(val).map((item: any) => {
let defaultValue = item.default !== undefined
Expand All @@ -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>
<style lang='stylus'>
Expand Down
1 change: 1 addition & 0 deletions src/renderer/pages/PicGoSetting.vue
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,7 @@ export default class extends Vue {
this.os = process.platform
ipcRenderer.send('getPicBeds')
ipcRenderer.on('getPicBeds', this.getPicBeds)
this.initData()
}
async initData () {
const config = (await this.getConfig<IConfig>())!
Expand Down
1 change: 0 additions & 1 deletion src/renderer/utils/mainMixin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ export default class extends Vue {
[config]: value
}
}
console.log(PICGO_SAVE_CONFIG, config, value)
ipcRenderer.send(PICGO_SAVE_CONFIG, config)
}
getConfig<T> (key?: string): Promise<T | undefined> {
Expand Down

0 comments on commit 20d3cf9

Please sign in to comment.