mirror of
https://github.com/Kuingsmile/PicList.git
synced 2026-09-05 23:47:43 +08:00
🔨 Refactor: use picgo-core's picbed list without using builtin picbed list
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
})
|
||||
|
||||
|
||||
@@ -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,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
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user