PicList/src/main/utils/getPicBeds.ts

29 lines
934 B
TypeScript
Raw Normal View History

2018-12-23 10:15:00 -05:00
import path from 'path'
2019-12-19 06:17:21 -05:00
import db from '#/datastore'
import { App } from 'electron'
2018-12-23 10:15:00 -05:00
// eslint-disable-next-line
const requireFunc = typeof __webpack_require__ === 'function' ? __non_webpack_require__ : require
2019-12-19 06:17:21 -05:00
const getPicBeds = (app: App) => {
2018-12-23 10:15:00 -05:00
const PicGo = requireFunc('picgo')
const STORE_PATH = app.getPath('userData')
const CONFIG_PATH = path.join(STORE_PATH, '/data.json')
const picgo = new PicGo(CONFIG_PATH)
const picBedTypes = picgo.helper.uploader.getIdList()
2019-09-11 07:30:08 -04:00
const picBedFromDB = db.get('picBed.list') || []
2019-12-19 06:17:21 -05:00
const picBeds = picBedTypes.map((item: string) => {
const visible = picBedFromDB.find((i: IPicBedType) => i.type === item) // object or undefined
2018-12-23 10:15:00 -05:00
return {
type: item,
name: picgo.helper.uploader.get(item).name || item,
visible: visible ? visible.visible : true
}
}) as IPicBedType[]
2018-12-24 03:05:30 -05:00
picgo.cmd.program.removeAllListeners()
2018-12-23 10:15:00 -05:00
return picBeds
}
export {
getPicBeds
}