🔨 Refactor: use picgo-core's picbed list without using builtin picbed list

This commit is contained in:
PiEgg
2022-08-21 10:54:30 +08:00
parent 428ffc7ef1
commit d50ad3a592
28 changed files with 127 additions and 1097 deletions
+6 -3
View File
@@ -37,9 +37,12 @@ class ConfigStore {
this.read()
}
read (flush = false) {
// if flush -> true, read origin file again
this.db.read(flush)
flush () {
this.db = new JSONStore(CONFIG_PATH)
}
read () {
this.db.read()
return this.db
}
+8 -3
View File
@@ -2,6 +2,7 @@ import { dbChecker, dbPathChecker } from 'apis/core/datastore/dbChecker'
import pkg from 'root/package.json'
import { PicGo } from 'picgo'
import db from 'apis/core/datastore'
import debounce from 'lodash/debounce'
const CONFIG_PATH = dbPathChecker()
@@ -18,12 +19,16 @@ picgo.GUI_VERSION = global.PICGO_GUI_VERSION
const originPicGoSaveConfig = picgo.saveConfig.bind(picgo)
function flushDB () {
db.flush()
}
const debounced = debounce(flushDB, 1000)
picgo.saveConfig = (config: IStringKeyMap) => {
originPicGoSaveConfig(config)
// flush electron's db
setTimeout(() => {
db.read(true)
}, 0)
debounced()
}
export default picgo
+4 -3
View File
@@ -27,7 +27,8 @@ import {
OPEN_URL,
RELOAD_APP,
SHOW_PLUGIN_PAGE_MENU,
SET_MINI_WINDOW_POS
SET_MINI_WINDOW_POS,
GET_PICBEDS
} from '#/events/constants'
import {
uploadClipboardFiles,
@@ -151,9 +152,9 @@ export default {
}
})
ipcMain.on('getPicBeds', (evt: IpcMainEvent) => {
ipcMain.on(GET_PICBEDS, (evt: IpcMainEvent) => {
const picBeds = getPicBeds()
evt.sender.send('getPicBeds', picBeds)
evt.sender.send(GET_PICBEDS, picBeds)
evt.returnValue = picBeds
})
+1
View File
@@ -383,6 +383,7 @@ const handleI18n = () => {
ipcMain.on(SET_CURRENT_LANGUAGE, (event: IpcMainEvent, language: string) => {
i18nManager.setCurrentLanguage(language)
const { lang, locales } = i18nManager.getCurrentLocales()
picgo.i18n.setLanguage(lang)
if (process.platform === 'darwin') {
const trayWindow = windowManager.get(IWindowList.TRAY_WINDOW)
trayWindow?.webContents.send(SET_CURRENT_LANGUAGE, lang, locales)
+2 -7
View File
@@ -2,6 +2,7 @@ import yaml from 'js-yaml'
import { ObjectAdapter, I18n } from '@picgo/i18n'
import path from 'path'
import fs from 'fs-extra'
import { builtinI18nList } from '#/i18n'
class I18nManager {
private i18n: I18n | null = null
@@ -10,13 +11,7 @@ class I18nManager {
private localesMap: Map<string, ILocales> = new Map()
private currentLanguage: string = 'zh-CN'
readonly defaultLanguage: string = 'zh-CN'
private i18nFileList: II18nItem[] = [{
label: '简体中文',
value: 'zh-CN'
}, {
label: 'English',
value: 'en'
}]
private i18nFileList: II18nItem[] = builtinI18nList
setOutterI18nFolder (folder: string) {
this.outterI18nFolder = folder
+9 -11
View File
@@ -93,18 +93,16 @@ function resolveOtherI18nFiles () {
withFileTypes: true
})
i18nFiles.forEach(item => {
if (item.isFile()) {
if (item.name.endsWith('.yml')) {
const i18nFilePath = path.join(i18nFolder, item.name)
const i18nFile = fs.readFileSync(i18nFilePath, 'utf8')
try {
const i18nFileObj = yaml.load(i18nFile) as unknown as ILocales
if (i18nFileObj?.LANG_DISPLAY_LABEL) {
i18nManager.addI18nFile(item.name.replace('.yml', ''), i18nFileObj.LANG_DISPLAY_LABEL)
}
} catch (e) {
console.error(e)
if (item.isFile() && item.name?.endsWith('.yml')) {
const i18nFilePath = path.join(i18nFolder, item.name)
const i18nFile = fs.readFileSync(i18nFilePath, 'utf8')
try {
const i18nFileObj = yaml.load(i18nFile) as unknown as ILocales
if (i18nFileObj?.LANG_DISPLAY_LABEL) {
i18nManager.addI18nFile(item.name.replace('.yml', ''), i18nFileObj.LANG_DISPLAY_LABEL)
}
} catch (e) {
console.error(e)
}
}
})