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