mirror of
https://github.com/Kuingsmile/PicList.git
synced 2026-05-26 02:30:18 +08:00
@@ -2,6 +2,7 @@ import fs from 'fs-extra'
|
||||
import path from 'path'
|
||||
import { remote, app } from 'electron'
|
||||
import dayjs from 'dayjs'
|
||||
import { getLogger } from '@core/utils/localLogger'
|
||||
const APP = process.type === 'renderer' ? remote.app : app
|
||||
const STORE_PATH = APP.getPath('userData')
|
||||
const configFilePath = path.join(STORE_PATH, 'data.json')
|
||||
@@ -15,9 +16,11 @@ const errorMsg = {
|
||||
brokenButBackup: 'PicGo 配置文件损坏,已经恢复为备份配置'
|
||||
}
|
||||
|
||||
/** ensure notification list */
|
||||
if (!global.notificationList) global.notificationList = []
|
||||
|
||||
function dbChecker () {
|
||||
if (process.type !== 'renderer') {
|
||||
if (!global.notificationList) global.notificationList = []
|
||||
// db save bak
|
||||
try {
|
||||
const { dbPath, dbBackupPath } = getGalleryDBPath()
|
||||
@@ -50,16 +53,16 @@ function dbChecker () {
|
||||
fs.writeFileSync(configFilePath, configFile, { encoding: 'utf-8' })
|
||||
const stats = fs.statSync(configFileBackupPath)
|
||||
optionsTpl.body = `${errorMsg.brokenButBackup}\n备份文件版本:${dayjs(stats.mtime).format('YYYY-MM-DD HH:mm:ss')}`
|
||||
global.notificationList.push(optionsTpl)
|
||||
global.notificationList?.push(optionsTpl)
|
||||
return
|
||||
} catch (e) {
|
||||
optionsTpl.body = errorMsg.broken
|
||||
global.notificationList.push(optionsTpl)
|
||||
global.notificationList?.push(optionsTpl)
|
||||
return
|
||||
}
|
||||
}
|
||||
optionsTpl.body = errorMsg.broken
|
||||
global.notificationList.push(optionsTpl)
|
||||
global.notificationList?.push(optionsTpl)
|
||||
return
|
||||
}
|
||||
fs.writeFileSync(configFileBackupPath, configFile, { encoding: 'utf-8' })
|
||||
@@ -92,15 +95,17 @@ function dbPathChecker (): string {
|
||||
}
|
||||
return _configFilePath
|
||||
} catch (e) {
|
||||
// TODO: local logger is needed
|
||||
const picgoLogPath = path.join(defaultConfigPath, 'picgo.log')
|
||||
const logger = getLogger(picgoLogPath)
|
||||
if (!hasCheckPath) {
|
||||
let optionsTpl = {
|
||||
title: '注意',
|
||||
body: '自定义文件解析出错,请检查路径内容是否正确'
|
||||
}
|
||||
global.notificationList.push(optionsTpl)
|
||||
global.notificationList?.push(optionsTpl)
|
||||
hasCheckPath = true
|
||||
}
|
||||
logger('error', e)
|
||||
console.error(e)
|
||||
_configFilePath = defaultConfigPath
|
||||
return _configFilePath
|
||||
|
||||
32
src/main/apis/core/utils/localLogger.ts
Normal file
32
src/main/apis/core/utils/localLogger.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
import fs from 'fs-extra'
|
||||
import dayjs from 'dayjs'
|
||||
import util from 'util'
|
||||
|
||||
/**
|
||||
* for local log before picgo inited
|
||||
*/
|
||||
const getLogger = (logPath: string) => {
|
||||
if (!fs.existsSync(logPath)) {
|
||||
fs.ensureFileSync(logPath)
|
||||
}
|
||||
return (type: string, ...msg: any[]) => {
|
||||
let log = `${dayjs().format('YYYY-MM-DD HH:mm:ss')} [PicGo ${type.toUpperCase()}] `
|
||||
msg.forEach((item: ILogArgvTypeWithError) => {
|
||||
if (typeof item === 'object' && type === 'error') {
|
||||
log += `\n------Error Stack Begin------\n${util.format(item.stack)}\n-------Error Stack End------- `
|
||||
} else {
|
||||
if (typeof item === 'object') {
|
||||
item = JSON.stringify(item)
|
||||
}
|
||||
log += `${item} `
|
||||
}
|
||||
})
|
||||
log += '\n'
|
||||
// A synchronized approach to avoid log msg sequence errors
|
||||
fs.appendFileSync(logPath, log)
|
||||
}
|
||||
}
|
||||
|
||||
export {
|
||||
getLogger
|
||||
}
|
||||
@@ -96,8 +96,8 @@ class LifeCycle {
|
||||
handleStartUpFiles(process.argv, process.cwd())
|
||||
}
|
||||
|
||||
if (global.notificationList?.length > 0) {
|
||||
while (global.notificationList.length) {
|
||||
if (global.notificationList && global.notificationList?.length > 0) {
|
||||
while (global.notificationList?.length) {
|
||||
const option = global.notificationList.pop()
|
||||
const notice = new Notification(option!)
|
||||
notice.show()
|
||||
|
||||
@@ -37,7 +37,7 @@ const migrateGalleryFromVersion230 = async (configDB: typeof ConfigStore, galler
|
||||
const configPath = configDB.getConfigPath()
|
||||
const configBakPath = path.join(path.dirname(configPath), 'config.bak.json')
|
||||
// migrate gallery from config to gallery db
|
||||
if (originGallery && originGallery?.length > 0) {
|
||||
if (originGallery && Array.isArray(originGallery) && originGallery?.length > 0) {
|
||||
if (fse.existsSync(configBakPath)) {
|
||||
fse.copyFileSync(configPath, configBakPath)
|
||||
}
|
||||
|
||||
@@ -116,7 +116,7 @@ export default class extends Vue {
|
||||
async handleConfig (val: any) {
|
||||
this.ruleForm = Object.assign({}, {})
|
||||
const config = await this.getConfig<IPicGoPluginConfig>(this.getConfigType())
|
||||
if (val.length > 0 && config) {
|
||||
if (val.length > 0) {
|
||||
this.configList = cloneDeep(val).map((item: any) => {
|
||||
let defaultValue = item.default !== undefined
|
||||
? item.default : item.type === 'checkbox'
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
:default-active="defaultActive"
|
||||
@select="handleSelect"
|
||||
:unique-opened="true"
|
||||
@open="handleGetPicPeds"
|
||||
>
|
||||
<el-menu-item index="upload">
|
||||
<i class="el-icon-upload"></i>
|
||||
@@ -192,8 +193,8 @@ export default class extends Vue {
|
||||
created () {
|
||||
this.os = process.platform
|
||||
this.buildMenu()
|
||||
ipcRenderer.send('getPicBeds')
|
||||
ipcRenderer.on('getPicBeds', this.getPicBeds)
|
||||
this.handleGetPicPeds()
|
||||
}
|
||||
|
||||
@Watch('choosedPicBedForQRCode')
|
||||
@@ -207,6 +208,10 @@ export default class extends Vue {
|
||||
}
|
||||
}
|
||||
|
||||
handleGetPicPeds = () => {
|
||||
ipcRenderer.send('getPicBeds')
|
||||
}
|
||||
|
||||
handleSelect (index: string) {
|
||||
const type = index.match(/picbeds-/)
|
||||
if (type === null) {
|
||||
|
||||
2
src/universal/types/electron.d.ts
vendored
2
src/universal/types/electron.d.ts
vendored
@@ -27,7 +27,7 @@ declare global {
|
||||
interface Global {
|
||||
PICGO_GUI_VERSION: string
|
||||
PICGO_CORE_VERSION: string
|
||||
notificationList: IAppNotification[]
|
||||
notificationList?: IAppNotification[]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
4
src/universal/types/types.d.ts
vendored
4
src/universal/types/types.d.ts
vendored
@@ -321,3 +321,7 @@ interface IAnalyticsData {
|
||||
interface IStringKeyMap {
|
||||
[propName: string]: any
|
||||
}
|
||||
|
||||
type ILogArgvType = string | number
|
||||
|
||||
type ILogArgvTypeWithError = ILogArgvType | Error
|
||||
|
||||
Reference in New Issue
Block a user