mirror of
https://github.com/Kuingsmile/PicList.git
synced 2026-05-12 02:20:46 +08:00
🔨 Refactor: db class
This commit is contained in:
@@ -21,62 +21,47 @@ if (process.type !== 'renderer') {
|
||||
}
|
||||
}
|
||||
|
||||
const adapter = new FileSync(path.join(STORE_PATH, '/data.json'))
|
||||
class DB {
|
||||
constructor () {
|
||||
const adapter = new FileSync(path.join(STORE_PATH, '/data.json'))
|
||||
|
||||
const db = Datastore(adapter)
|
||||
db._.mixin(LodashId)
|
||||
this.db = Datastore(adapter)
|
||||
this.db._.mixin(LodashId)
|
||||
|
||||
if (!db.has('uploaded').value()) {
|
||||
db.set('uploaded', []).write()
|
||||
}
|
||||
if (!this.db.has('uploaded').value()) {
|
||||
this.db.set('uploaded', []).write()
|
||||
}
|
||||
|
||||
if (!db.has('picBed').value()) {
|
||||
db.set('picBed', {
|
||||
current: 'weibo'
|
||||
}).write()
|
||||
}
|
||||
if (!this.db.has('picBed').value()) {
|
||||
this.db.set('picBed', {
|
||||
current: 'weibo'
|
||||
}).write()
|
||||
}
|
||||
|
||||
if (!db.has('settings.shortKey').value()) {
|
||||
db.set('settings.shortKey', {
|
||||
upload: 'CommandOrControl+Shift+P'
|
||||
}).write()
|
||||
}
|
||||
|
||||
// init generate clipboard image files
|
||||
let clipboardFiles = getClipboardFiles()
|
||||
if (!fs.pathExistsSync(path.join(STORE_PATH, 'windows10.ps1'))) {
|
||||
clipboardFiles.forEach(item => {
|
||||
fs.copyFileSync(item.origin, item.dest)
|
||||
})
|
||||
} else {
|
||||
clipboardFiles.forEach(item => {
|
||||
diffFilesAndUpdate(item.origin, item.dest)
|
||||
})
|
||||
}
|
||||
|
||||
function diffFilesAndUpdate (filePath1, filePath2) {
|
||||
let file1 = fs.readFileSync(filePath1)
|
||||
let file2 = fs.readFileSync(filePath2)
|
||||
|
||||
if (!file1.equals(file2)) {
|
||||
fs.copyFileSync(filePath1, filePath2)
|
||||
if (!this.db.has('settings.shortKey').value()) {
|
||||
this.db.set('settings.shortKey[picgo:upload]', {
|
||||
enable: true,
|
||||
key: 'CommandOrControl+Shift+P',
|
||||
name: 'picgo:upload',
|
||||
label: '快捷上传'
|
||||
}).write()
|
||||
}
|
||||
}
|
||||
read () {
|
||||
return this.db.read()
|
||||
}
|
||||
get (key = '') {
|
||||
return this.read().get(key).value()
|
||||
}
|
||||
set (key, value) {
|
||||
return this.read().set(key, value).write()
|
||||
}
|
||||
has (key) {
|
||||
return this.read().has(key).value()
|
||||
}
|
||||
insert (key, value) {
|
||||
return this.read().get(key).insert(value).write()
|
||||
}
|
||||
}
|
||||
|
||||
function getClipboardFiles () {
|
||||
let files = [
|
||||
'/linux.sh',
|
||||
'/mac.applescript',
|
||||
'/windows.ps1',
|
||||
'/windows10.ps1'
|
||||
]
|
||||
|
||||
return files.map(item => {
|
||||
return {
|
||||
origin: path.join(__static, item),
|
||||
dest: path.join(STORE_PATH, item)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
export default db
|
||||
export default new DB()
|
||||
|
||||
@@ -43,7 +43,7 @@ let picBed = [
|
||||
}
|
||||
]
|
||||
|
||||
let picBedFromDB = db.read().get('picBed.list').value() || []
|
||||
let picBedFromDB = db.get('picBed.list') || []
|
||||
let oldLength = picBedFromDB.length
|
||||
let newLength = picBed.length
|
||||
|
||||
|
||||
@@ -69,9 +69,9 @@ function createContextMenu () {
|
||||
return {
|
||||
label: item.name,
|
||||
type: 'radio',
|
||||
checked: db.read().get('picBed.current').value() === item.type,
|
||||
checked: db.get('picBed.current') === item.type,
|
||||
click () {
|
||||
db.read().set('picBed.current', item.type).write()
|
||||
db.set('picBed.current', item.type)
|
||||
if (settingWindow) {
|
||||
settingWindow.webContents.send('syncPicBed')
|
||||
}
|
||||
@@ -112,10 +112,10 @@ function createContextMenu () {
|
||||
{
|
||||
label: '打开更新助手',
|
||||
type: 'checkbox',
|
||||
checked: db.get('settings.showUpdateTip').value(),
|
||||
checked: db.get('settings.showUpdateTip'),
|
||||
click () {
|
||||
const value = db.read().get('settings.showUpdateTip').value()
|
||||
db.read().set('settings.showUpdateTip', !value).write()
|
||||
const value = db.get('settings.showUpdateTip')
|
||||
db.set('settings.showUpdateTip', !value)
|
||||
}
|
||||
},
|
||||
{
|
||||
@@ -189,7 +189,7 @@ function createTray () {
|
||||
})
|
||||
|
||||
tray.on('drop-files', async (event, files) => {
|
||||
const pasteStyle = db.read().get('settings.pasteStyle').value() || 'markdown'
|
||||
const pasteStyle = db.get('settings.pasteStyle') || 'markdown'
|
||||
const imgs = await new Uploader(files, window.webContents).upload()
|
||||
if (imgs !== false) {
|
||||
for (let i in imgs) {
|
||||
@@ -202,7 +202,7 @@ function createTray () {
|
||||
setTimeout(() => {
|
||||
notification.show()
|
||||
}, i * 100)
|
||||
db.read().get('uploaded').insert(imgs[i]).write()
|
||||
db.insert('uploaded', imgs[i])
|
||||
}
|
||||
window.webContents.send('dragFiles', imgs)
|
||||
}
|
||||
@@ -263,7 +263,7 @@ const createMiniWidow = () => {
|
||||
}
|
||||
}
|
||||
|
||||
if (db.read().get('settings.miniWindowOntop').value()) {
|
||||
if (db.get('settings.miniWindowOntop')) {
|
||||
obj.alwaysOnTop = true
|
||||
}
|
||||
|
||||
@@ -370,7 +370,7 @@ const uploadClipboardFiles = async () => {
|
||||
let img = await new Uploader(undefined, win.webContents).upload()
|
||||
if (img !== false) {
|
||||
if (img.length > 0) {
|
||||
const pasteStyle = db.read().get('settings.pasteStyle').value() || 'markdown'
|
||||
const pasteStyle = db.get('settings.pasteStyle') || 'markdown'
|
||||
clipboard.writeText(pasteTemplate(pasteStyle, img[0]))
|
||||
const notification = new Notification({
|
||||
title: '上传成功',
|
||||
@@ -378,7 +378,7 @@ const uploadClipboardFiles = async () => {
|
||||
icon: img[0].imgUrl
|
||||
})
|
||||
notification.show()
|
||||
db.read().get('uploaded').insert(img[0]).write()
|
||||
db.insert('uploaded', img[0])
|
||||
window.webContents.send('clipboardFiles', [])
|
||||
window.webContents.send('uploadFiles', img)
|
||||
if (settingWindow) {
|
||||
@@ -398,7 +398,7 @@ const uploadChoosedFiles = async (webContents, files) => {
|
||||
const input = files.map(item => item.path)
|
||||
const imgs = await new Uploader(input, webContents).upload()
|
||||
if (imgs !== false) {
|
||||
const pasteStyle = db.read().get('settings.pasteStyle').value() || 'markdown'
|
||||
const pasteStyle = db.get('settings.pasteStyle') || 'markdown'
|
||||
let pasteText = ''
|
||||
for (let i in imgs) {
|
||||
pasteText += pasteTemplate(pasteStyle, imgs[i]) + '\r\n'
|
||||
@@ -410,7 +410,7 @@ const uploadChoosedFiles = async (webContents, files) => {
|
||||
setTimeout(() => {
|
||||
notification.show()
|
||||
}, i * 100)
|
||||
db.read().get('uploaded').insert(imgs[i]).write()
|
||||
db.insert('uploaded', imgs[i])
|
||||
}
|
||||
clipboard.writeText(pasteText)
|
||||
window.webContents.send('uploadFiles', imgs)
|
||||
@@ -426,7 +426,7 @@ picgoCoreIPC(app, ipcMain)
|
||||
ipcMain.on('uploadClipboardFiles', async (evt, file) => {
|
||||
const img = await new Uploader(undefined, window.webContents).upload()
|
||||
if (img !== false) {
|
||||
const pasteStyle = db.read().get('settings.pasteStyle').value() || 'markdown'
|
||||
const pasteStyle = db.get('settings.pasteStyle') || 'markdown'
|
||||
clipboard.writeText(pasteTemplate(pasteStyle, img[0]))
|
||||
const notification = new Notification({
|
||||
title: '上传成功',
|
||||
@@ -435,7 +435,7 @@ ipcMain.on('uploadClipboardFiles', async (evt, file) => {
|
||||
icon: img[0].imgUrl
|
||||
})
|
||||
notification.show()
|
||||
db.read().get('uploaded').insert(img[0]).write()
|
||||
db.insert('uploaded', img[0])
|
||||
window.webContents.send('clipboardFiles', [])
|
||||
if (settingWindow) {
|
||||
settingWindow.webContents.send('updateGallery')
|
||||
@@ -558,13 +558,13 @@ app.on('ready', () => {
|
||||
if (process.platform === 'darwin' || process.platform === 'win32') {
|
||||
createTray()
|
||||
}
|
||||
db.read().set('needReload', false).write()
|
||||
db.set('needReload', false)
|
||||
updateChecker()
|
||||
initEventCenter()
|
||||
// 不需要阻塞
|
||||
process.nextTick(() => {
|
||||
updateShortKeyFromVersion212(db, db.read().get('settings.shortKey').value())
|
||||
initShortKeyRegister(globalShortcut, db.read().get('settings.shortKey').value())
|
||||
updateShortKeyFromVersion212(db, db.get('settings.shortKey'))
|
||||
initShortKeyRegister(globalShortcut, db.get('settings.shortKey'))
|
||||
})
|
||||
|
||||
if (process.env.NODE_ENV !== 'development') {
|
||||
@@ -606,7 +606,7 @@ app.on('will-quit', () => {
|
||||
})
|
||||
|
||||
app.setLoginItemSettings({
|
||||
openAtLogin: db.read().get('settings.autoStart').value() || false
|
||||
openAtLogin: db.get('settings.autoStart') || false
|
||||
})
|
||||
|
||||
function initEventCenter () {
|
||||
|
||||
@@ -12,7 +12,7 @@ const updateShortKeyFromVersion212 = (db, shortKeyConfig) => {
|
||||
delete shortKeyConfig.upload
|
||||
}
|
||||
if (needUpgrade) {
|
||||
db.read().set('settings.shortKey', shortKeyConfig).write()
|
||||
db.set('settings.shortKey', shortKeyConfig)
|
||||
return shortKeyConfig
|
||||
} else {
|
||||
return false
|
||||
|
||||
@@ -1,13 +1,28 @@
|
||||
import fs from 'fs-extra'
|
||||
import path from 'path'
|
||||
import os from 'os'
|
||||
import { remote, app } from 'electron'
|
||||
if (process.env.NODE_ENV !== 'development') {
|
||||
global.__static = path.join(__dirname, '/static').replace(/\\/g, '\\\\')
|
||||
}
|
||||
if (process.env.DEBUG_ENV === 'debug') {
|
||||
global.__static = path.join(__dirname, '../../../static').replace(/\\/g, '\\\\')
|
||||
}
|
||||
|
||||
const APP = process.type === 'renderer' ? remote.app : app
|
||||
const STORE_PATH = APP.getPath('userData')
|
||||
|
||||
function beforeOpen () {
|
||||
if (process.platform === 'darwin') {
|
||||
resolveMacWorkFlow()
|
||||
}
|
||||
resolveClipboardImageGenerator()
|
||||
}
|
||||
|
||||
/**
|
||||
* macOS 右键菜单
|
||||
*/
|
||||
function resolveMacWorkFlow () {
|
||||
const dest = `${os.homedir}/Library/Services/Upload pictures with PicGo.workflow`
|
||||
if (fs.existsSync(dest)) {
|
||||
return true
|
||||
@@ -20,4 +35,45 @@ function beforeOpen () {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化剪贴板生成图片的脚本
|
||||
*/
|
||||
function resolveClipboardImageGenerator () {
|
||||
let clipboardFiles = getClipboardFiles()
|
||||
if (!fs.pathExistsSync(path.join(STORE_PATH, 'windows10.ps1'))) {
|
||||
clipboardFiles.forEach(item => {
|
||||
fs.copyFileSync(item.origin, item.dest)
|
||||
})
|
||||
} else {
|
||||
clipboardFiles.forEach(item => {
|
||||
diffFilesAndUpdate(item.origin, item.dest)
|
||||
})
|
||||
}
|
||||
|
||||
function diffFilesAndUpdate (filePath1, filePath2) {
|
||||
let file1 = fs.readFileSync(filePath1)
|
||||
let file2 = fs.readFileSync(filePath2)
|
||||
|
||||
if (!file1.equals(file2)) {
|
||||
fs.copyFileSync(filePath1, filePath2)
|
||||
}
|
||||
}
|
||||
|
||||
function getClipboardFiles () {
|
||||
let files = [
|
||||
'/linux.sh',
|
||||
'/mac.applescript',
|
||||
'/windows.ps1',
|
||||
'/windows10.ps1'
|
||||
]
|
||||
|
||||
return files.map(item => {
|
||||
return {
|
||||
origin: path.join(__static, item),
|
||||
dest: path.join(STORE_PATH, item)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
export default beforeOpen
|
||||
|
||||
@@ -9,7 +9,7 @@ const getPicBeds = (app) => {
|
||||
const CONFIG_PATH = path.join(STORE_PATH, '/data.json')
|
||||
const picgo = new PicGo(CONFIG_PATH)
|
||||
const picBedTypes = picgo.helper.uploader.getIdList()
|
||||
const picBedFromDB = db.read().get('picBed.list').value() || []
|
||||
const picBedFromDB = db.get('picBed.list') || []
|
||||
const picBeds = picBedTypes.map(item => {
|
||||
const visible = picBedFromDB.find(i => i.type === item) // object or undefined
|
||||
return {
|
||||
|
||||
@@ -60,7 +60,7 @@ class GuiApi {
|
||||
async upload (input) {
|
||||
const imgs = await new Uploader(input, this[WEBCONTENTS], this[PICGO]).upload()
|
||||
if (imgs !== false) {
|
||||
const pasteStyle = db.read().get('settings.pasteStyle').value() || 'markdown'
|
||||
const pasteStyle = db.get('settings.pasteStyle') || 'markdown'
|
||||
let pasteText = ''
|
||||
for (let i in imgs) {
|
||||
pasteText += pasteTemplate(pasteStyle, imgs[i]) + '\r\n'
|
||||
@@ -72,7 +72,7 @@ class GuiApi {
|
||||
setTimeout(() => {
|
||||
notification.show()
|
||||
}, i * 100)
|
||||
db.read().get('uploaded').insert(imgs[i]).write()
|
||||
db.insert('uploaded', imgs[i])
|
||||
}
|
||||
clipboard.writeText(pasteText)
|
||||
this[WEBCONTENTS].send('uploadFiles', imgs)
|
||||
|
||||
@@ -19,7 +19,7 @@ const formatCustomLink = (customLink, item) => {
|
||||
|
||||
export default (style, item) => {
|
||||
let url = item.url || item.imgUrl
|
||||
const customLink = db.read().get('settings.customLink').value() || '$url'
|
||||
const customLink = db.get('settings.customLink') || '$url'
|
||||
const tpl = {
|
||||
'markdown': ``,
|
||||
'HTML': `<img src="${url}"/>`,
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import path from 'path'
|
||||
import GuiApi from './guiApi'
|
||||
import { dialog, shell } from 'electron'
|
||||
import db from '../../datastore'
|
||||
|
||||
// eslint-disable-next-line
|
||||
const requireFunc = typeof __webpack_require__ === 'function' ? __non_webpack_require__ : require
|
||||
@@ -187,6 +188,17 @@ const handleRemoveFiles = (ipcMain, CONFIG_PATH) => {
|
||||
})
|
||||
}
|
||||
|
||||
const handlePluginShortKeyRegister = (plugin) => {
|
||||
if (plugin.shortKeys && plugin.shortKeys.length > 0) {
|
||||
let shortKeyConfig = db.get('settings.shortKey')
|
||||
plugin.shortKeys.forEach(item => {
|
||||
if (!shortKeyConfig[item.name]) {
|
||||
shortKeyConfig[item.name] = item
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
export default (app, ipcMain) => {
|
||||
const STORE_PATH = app.getPath('userData')
|
||||
const CONFIG_PATH = path.join(STORE_PATH, '/data.json')
|
||||
@@ -197,4 +209,5 @@ export default (app, ipcMain) => {
|
||||
handleGetPicBedConfig(ipcMain, CONFIG_PATH)
|
||||
handlePluginActions(ipcMain, CONFIG_PATH)
|
||||
handleRemoveFiles(ipcMain, CONFIG_PATH)
|
||||
handlePluginShortKeyRegister({})
|
||||
}
|
||||
|
||||
@@ -7,9 +7,9 @@ const release = 'https://api.github.com/repos/Molunerfinn/PicGo/releases/latest'
|
||||
const downloadUrl = 'https://github.com/Molunerfinn/PicGo/releases/latest'
|
||||
|
||||
const checkVersion = async () => {
|
||||
let showTip = db.read().get('settings.showUpdateTip').value()
|
||||
let showTip = db.get('settings.showUpdateTip')
|
||||
if (showTip === undefined) {
|
||||
db.read().set('settings.showUpdateTip', true).write()
|
||||
db.set('settings.showUpdateTip', true)
|
||||
showTip = true
|
||||
}
|
||||
if (showTip) {
|
||||
@@ -29,7 +29,7 @@ const checkVersion = async () => {
|
||||
if (res === 0) { // if selected yes
|
||||
shell.openExternal(downloadUrl)
|
||||
}
|
||||
db.read().set('settings.showUpdateTip', !checkboxChecked).write()
|
||||
db.set('settings.showUpdateTip', !checkboxChecked)
|
||||
})
|
||||
}
|
||||
} else {
|
||||
|
||||
@@ -21,7 +21,7 @@ export default {
|
||||
}
|
||||
},
|
||||
created () {
|
||||
if (this.type === this.$db.get('picBed.current').value()) {
|
||||
if (this.type === this.$db.get('picBed.current')) {
|
||||
this.value = true
|
||||
}
|
||||
},
|
||||
|
||||
@@ -83,7 +83,7 @@ export default {
|
||||
deep: true,
|
||||
handler (val) {
|
||||
this.ruleForm = Object.assign({}, {})
|
||||
const config = this.$db.read().get(`picBed.${this.id}`).value()
|
||||
const config = this.$db.get(`picBed.${this.id}`)
|
||||
if (val.length > 0) {
|
||||
this.configList = cloneDeep(val).map(item => {
|
||||
let defaultValue = item.default !== undefined
|
||||
|
||||
@@ -18,7 +18,7 @@ export default {
|
||||
}
|
||||
},
|
||||
created () {
|
||||
this.$db.read().get('settings.shortKey')
|
||||
this.$db.get('settings.shortKey')
|
||||
},
|
||||
data () {
|
||||
return {
|
||||
|
||||
@@ -185,7 +185,7 @@ export default {
|
||||
keyBindingVisible: false,
|
||||
customLinkVisible: false,
|
||||
customLink: {
|
||||
value: db.read().get('customLink').value() || '$url'
|
||||
value: db.get('customLink') || '$url'
|
||||
},
|
||||
rules: {
|
||||
value: [
|
||||
@@ -194,7 +194,7 @@ export default {
|
||||
},
|
||||
os: '',
|
||||
shortKey: {
|
||||
upload: db.read().get('shortKey.upload').value()
|
||||
upload: db.get('shortKey.upload')
|
||||
},
|
||||
picBed: [],
|
||||
// for showInputBox
|
||||
@@ -279,22 +279,22 @@ export default {
|
||||
},
|
||||
cancelKeyBinding () {
|
||||
this.keyBindingVisible = false
|
||||
this.shortKey = db.read().get('shortKey').value()
|
||||
this.shortKey = db.get('shortKey')
|
||||
},
|
||||
confirmKeyBinding () {
|
||||
const oldKey = db.read().get('shortKey').value()
|
||||
db.read().set('shortKey', this.shortKey).write()
|
||||
const oldKey = db.get('shortKey')
|
||||
db.set('shortKey', this.shortKey)
|
||||
this.keyBindingVisible = false
|
||||
this.$electron.ipcRenderer.send('updateShortKey', oldKey)
|
||||
},
|
||||
cancelCustomLink () {
|
||||
this.customLinkVisible = false
|
||||
this.customLink.value = db.read().get('customLink').value() || '$url'
|
||||
this.customLink.value = db.get('customLink') || '$url'
|
||||
},
|
||||
confirmCustomLink () {
|
||||
this.$refs.customLink.validate((valid) => {
|
||||
if (valid) {
|
||||
db.read().set('customLink', this.customLink.value).write()
|
||||
db.set('customLink', this.customLink.value)
|
||||
this.customLinkVisible = false
|
||||
this.$electron.ipcRenderer.send('updateCustomLink')
|
||||
} else {
|
||||
|
||||
@@ -213,7 +213,7 @@ export default {
|
||||
this.changeZIndexForGallery(false)
|
||||
},
|
||||
copy (item) {
|
||||
const style = this.$db.read().get('settings.pasteStyle').value() || 'markdown'
|
||||
const style = this.$db.get('settings.pasteStyle') || 'markdown'
|
||||
const copyLink = pasteStyle(style, item)
|
||||
const obj = {
|
||||
title: '复制链接成功',
|
||||
@@ -232,7 +232,7 @@ export default {
|
||||
cancelButtonText: '取消',
|
||||
type: 'warning'
|
||||
}).then(() => {
|
||||
const file = this.$db.read().get('uploaded').getById(id).value()
|
||||
const file = this.$db.get('uploaded').getById(id)
|
||||
this.$db.read().get('uploaded').removeById(id).write()
|
||||
this.$electron.ipcRenderer.send('removeFiles', [file])
|
||||
const obj = {
|
||||
@@ -319,7 +319,7 @@ export default {
|
||||
multiCopy () {
|
||||
if (Object.values(this.choosedList).some(item => item)) {
|
||||
let copyString = ''
|
||||
const style = this.$db.read().get('settings.pasteStyle').value() || 'markdown'
|
||||
const style = this.$db.get('settings.pasteStyle') || 'markdown'
|
||||
// choosedList -> { [id]: true or false }; true means choosed. false means not choosed.
|
||||
Object.keys(this.choosedList).forEach(key => {
|
||||
if (this.choosedList[key]) {
|
||||
@@ -343,11 +343,10 @@ export default {
|
||||
this.handleBarActive = !this.handleBarActive
|
||||
},
|
||||
getPasteStyle () {
|
||||
this.pasteStyle = this.$db.read().get('settings.pasteStyle').value() || 'markdown'
|
||||
this.pasteStyle = this.$db.get('settings.pasteStyle') || 'markdown'
|
||||
},
|
||||
handlePasteStyleChange (val) {
|
||||
this.$db.read().set('settings.pasteStyle', val)
|
||||
.write()
|
||||
this.$db.set('settings.pasteStyle', val)
|
||||
this.pasteStyle = val
|
||||
}
|
||||
},
|
||||
|
||||
@@ -136,9 +136,9 @@ export default {
|
||||
return {
|
||||
label: item.name,
|
||||
type: 'radio',
|
||||
checked: this.$db.read().get('picBed.current').value() === item.type,
|
||||
checked: this.$db.get('picBed.current') === item.type,
|
||||
click () {
|
||||
_this.$db.read().set('picBed.current', item.type).write()
|
||||
_this.$db.set('picBed.current', item.type)
|
||||
_this.$electron.ipcRenderer.send('syncPicBed')
|
||||
}
|
||||
}
|
||||
|
||||
@@ -290,7 +290,7 @@ export default {
|
||||
return callback()
|
||||
}
|
||||
}
|
||||
let logLevel = this.$db.read().get('settings.logLevel').value()
|
||||
let logLevel = this.$db.get('settings.logLevel')
|
||||
if (!Array.isArray(logLevel)) {
|
||||
if (logLevel && logLevel.length > 0) {
|
||||
logLevel = [logLevel]
|
||||
@@ -300,13 +300,13 @@ export default {
|
||||
}
|
||||
return {
|
||||
form: {
|
||||
updateHelper: this.$db.read().get('settings.showUpdateTip').value(),
|
||||
updateHelper: this.$db.get('settings.showUpdateTip'),
|
||||
showPicBedList: [],
|
||||
autoStart: this.$db.read().get('settings.autoStart').value() || false,
|
||||
rename: this.$db.read().get('settings.rename').value() || false,
|
||||
autoRename: this.$db.read().get('settings.autoRename').value() || false,
|
||||
uploadNotification: this.$db.read().get('settings.uploadNotification').value() || false,
|
||||
miniWindowOntop: this.$db.read().get('settings.miniWindowOntop').value() || false,
|
||||
autoStart: this.$db.get('settings.autoStart') || false,
|
||||
rename: this.$db.get('settings.rename') || false,
|
||||
autoRename: this.$db.get('settings.autoRename') || false,
|
||||
uploadNotification: this.$db.get('settings.uploadNotification') || false,
|
||||
miniWindowOntop: this.$db.get('settings.miniWindowOntop') || false,
|
||||
logLevel
|
||||
},
|
||||
picBed: [],
|
||||
@@ -316,12 +316,12 @@ export default {
|
||||
checkUpdateVisible: false,
|
||||
proxyVisible: false,
|
||||
customLink: {
|
||||
value: this.$db.read().get('settings.customLink').value() || '$url'
|
||||
value: this.$db.get('settings.customLink') || '$url'
|
||||
},
|
||||
shortKey: {
|
||||
upload: this.$db.read().get('settings.shortKey.upload').value()
|
||||
upload: this.$db.get('settings.shortKey.upload')
|
||||
},
|
||||
proxy: this.$db.read().get('picBed.proxy').value() || undefined,
|
||||
proxy: this.$db.get('picBed.proxy') || undefined,
|
||||
rules: {
|
||||
value: [
|
||||
{ validator: customLinkRule, trigger: 'blur' }
|
||||
@@ -368,22 +368,22 @@ export default {
|
||||
},
|
||||
cancelKeyBinding () {
|
||||
this.keyBindingVisible = false
|
||||
this.shortKey = this.$db.read().get('settings.shortKey').value()
|
||||
this.shortKey = this.$db.get('settings.shortKey')
|
||||
},
|
||||
confirmKeyBinding () {
|
||||
const oldKey = this.$db.read().get('settings.shortKey').value()
|
||||
this.$db.read().set('settings.shortKey', this.shortKey).write()
|
||||
const oldKey = this.$db.get('settings.shortKey')
|
||||
this.$db.set('settings.shortKey', this.shortKey)
|
||||
this.keyBindingVisible = false
|
||||
this.$electron.ipcRenderer.send('updateShortKey', oldKey)
|
||||
},
|
||||
cancelCustomLink () {
|
||||
this.customLinkVisible = false
|
||||
this.customLink.value = this.$db.read().get('settings.customLink').value() || '$url'
|
||||
this.customLink.value = this.$db.get('settings.customLink') || '$url'
|
||||
},
|
||||
confirmCustomLink () {
|
||||
this.$refs.customLink.validate((valid) => {
|
||||
if (valid) {
|
||||
this.$db.read().set('settings.customLink', this.customLink.value).write()
|
||||
this.$db.set('settings.customLink', this.customLink.value)
|
||||
this.customLinkVisible = false
|
||||
this.$electron.ipcRenderer.send('updateCustomLink')
|
||||
} else {
|
||||
@@ -393,11 +393,11 @@ export default {
|
||||
},
|
||||
cancelProxy () {
|
||||
this.proxyVisible = false
|
||||
this.proxy = this.$db.read().get('picBed.proxy').value() || undefined
|
||||
this.proxy = this.$db.get('picBed.proxy') || undefined
|
||||
},
|
||||
confirmProxy () {
|
||||
this.proxyVisible = false
|
||||
this.$db.read().set('picBed.proxy', this.proxy).write()
|
||||
this.$db.set('picBed.proxy', this.proxy)
|
||||
const successNotification = new window.Notification('设置代理', {
|
||||
body: '设置成功'
|
||||
})
|
||||
@@ -406,7 +406,7 @@ export default {
|
||||
}
|
||||
},
|
||||
updateHelperChange (val) {
|
||||
this.$db.read().set('settings.showUpdateTip', val).write()
|
||||
this.$db.set('settings.showUpdateTip', val)
|
||||
},
|
||||
handleShowPicBedListChange (val) {
|
||||
const list = this.picBed.map(item => {
|
||||
@@ -417,18 +417,18 @@ export default {
|
||||
}
|
||||
return item
|
||||
})
|
||||
this.$db.read().set('picBed.list', list).write()
|
||||
this.$db.set('picBed.list', list)
|
||||
this.$electron.ipcRenderer.send('getPicBeds')
|
||||
},
|
||||
handleAutoStartChange (val) {
|
||||
this.$db.read().set('settings.autoStart', val).write()
|
||||
this.$db.set('settings.autoStart', val)
|
||||
this.$electron.ipcRenderer.send('autoStart', val)
|
||||
},
|
||||
handleRename (val) {
|
||||
this.$db.read().set('settings.rename', val).write()
|
||||
this.$db.set('settings.rename', val)
|
||||
},
|
||||
handleAutoRename (val) {
|
||||
this.$db.read().set('settings.autoRename', val).write()
|
||||
this.$db.set('settings.autoRename', val)
|
||||
},
|
||||
compareVersion2Update (current, latest) {
|
||||
const currentVersion = current.split('.').map(item => parseInt(item))
|
||||
@@ -463,17 +463,17 @@ export default {
|
||||
this.checkUpdateVisible = false
|
||||
},
|
||||
handleUploadNotification (val) {
|
||||
this.$db.read().set('settings.uploadNotification', val).write()
|
||||
this.$db.set('settings.uploadNotification', val)
|
||||
},
|
||||
handleMiniWindowOntop (val) {
|
||||
this.$db.read().set('settings.miniWindowOntop', val).write()
|
||||
this.$db.set('settings.miniWindowOntop', val)
|
||||
this.$message('需要重启生效')
|
||||
},
|
||||
confirmLogLevelSetting () {
|
||||
if (this.form.logLevel.length === 0) {
|
||||
return this.$message.error('请选择日志记录等级')
|
||||
}
|
||||
this.$db.read().set('settings.logLevel', this.form.logLevel).write()
|
||||
this.$db.set('settings.logLevel', this.form.logLevel)
|
||||
const successNotification = new window.Notification('设置日志', {
|
||||
body: '设置成功'
|
||||
})
|
||||
@@ -484,7 +484,7 @@ export default {
|
||||
},
|
||||
cancelLogLevelSetting () {
|
||||
this.logFileVisible = false
|
||||
let logLevel = this.$db.read().get('settings.logLevel').value()
|
||||
let logLevel = this.$db.get('settings.logLevel')
|
||||
if (!Array.isArray(logLevel)) {
|
||||
if (logLevel && logLevel.length > 0) {
|
||||
logLevel = [logLevel]
|
||||
|
||||
@@ -183,7 +183,7 @@ export default {
|
||||
})
|
||||
this.getPluginList()
|
||||
this.getSearchResult = debounce(this.getSearchResult, 50)
|
||||
this.needReload = this.$db.read().get('needReload').value()
|
||||
this.needReload = this.$db.get('needReload')
|
||||
},
|
||||
methods: {
|
||||
buildContextMenu (plugin) {
|
||||
@@ -192,7 +192,7 @@ export default {
|
||||
label: '启用插件',
|
||||
enabled: !plugin.enabled,
|
||||
click () {
|
||||
_this.$db.read().set(`picgoPlugins.picgo-plugin-${plugin.name}`, true).write()
|
||||
_this.$db.set(`picgoPlugins.picgo-plugin-${plugin.name}`, true)
|
||||
plugin.enabled = true
|
||||
_this.getPicBeds()
|
||||
}
|
||||
@@ -200,7 +200,7 @@ export default {
|
||||
label: '禁用插件',
|
||||
enabled: plugin.enabled,
|
||||
click () {
|
||||
_this.$db.read().set(`picgoPlugins.picgo-plugin-${plugin.name}`, false).write()
|
||||
_this.$db.set(`picgoPlugins.picgo-plugin-${plugin.name}`, false)
|
||||
plugin.enabled = false
|
||||
_this.getPicBeds()
|
||||
if (plugin.config.transformer.name) {
|
||||
@@ -238,7 +238,7 @@ export default {
|
||||
|
||||
// handle transformer
|
||||
if (plugin.config.transformer.name) {
|
||||
let currentTransformer = this.$db.read().get('picBed.transformer').value() || 'path'
|
||||
let currentTransformer = this.$db.get('picBed.transformer') || 'path'
|
||||
let pluginTransformer = plugin.config.transformer.name
|
||||
const obj = {
|
||||
label: `${currentTransformer === pluginTransformer ? '禁用' : '启用'}transformer - ${plugin.config.transformer.name}`,
|
||||
@@ -311,7 +311,7 @@ export default {
|
||||
this.$electron.remote.app.exit(0)
|
||||
},
|
||||
handleReload () {
|
||||
this.$db.read().set('needReload', true).write()
|
||||
this.$db.set('needReload', true)
|
||||
this.needReload = true
|
||||
const successNotification = new window.Notification('更新成功', {
|
||||
body: '请点击此通知重启应用以生效'
|
||||
@@ -324,11 +324,11 @@ export default {
|
||||
this.searchText = ''
|
||||
},
|
||||
toggleTransformer (transformer) {
|
||||
let currentTransformer = this.$db.read().get('picBed.transformer').value() || 'path'
|
||||
let currentTransformer = this.$db.get('picBed.transformer') || 'path'
|
||||
if (currentTransformer === transformer) {
|
||||
this.$db.read().set('picBed.transformer', 'path').write()
|
||||
this.$db.set('picBed.transformer', 'path')
|
||||
} else {
|
||||
this.$db.read().set('picBed.transformer', transformer).write()
|
||||
this.$db.set('picBed.transformer', transformer)
|
||||
}
|
||||
},
|
||||
async handleConfirmConfig () {
|
||||
@@ -336,13 +336,13 @@ export default {
|
||||
if (result !== false) {
|
||||
switch (this.currentType) {
|
||||
case 'plugin':
|
||||
this.$db.read().set(`picgo-plugin-${this.configName}`, result).write()
|
||||
this.$db.set(`picgo-plugin-${this.configName}`, result)
|
||||
break
|
||||
case 'uploader':
|
||||
this.$db.read().set(`picBed.${this.configName}`, result).write()
|
||||
this.$db.set(`picBed.${this.configName}`, result)
|
||||
break
|
||||
case 'transformer':
|
||||
this.$db.read().set(`transformer.${this.configName}`, result).write()
|
||||
this.$db.set(`transformer.${this.configName}`, result)
|
||||
break
|
||||
}
|
||||
const successNotification = new window.Notification('设置结果', {
|
||||
@@ -393,15 +393,15 @@ export default {
|
||||
// restore Uploader & Transformer
|
||||
handleRestoreState (item, name) {
|
||||
if (item === 'uploader') {
|
||||
const current = this.$db.read().get('picBed.current').value()
|
||||
const current = this.$db.get('picBed.current')
|
||||
if (current === name) {
|
||||
this.$db.read().set('picBed.current', 'smms').write()
|
||||
this.$db.set('picBed.current', 'smms')
|
||||
}
|
||||
}
|
||||
if (item === 'transformer') {
|
||||
const current = this.$db.read().get('picBed.transformer').value()
|
||||
const current = this.$db.get('picBed.transformer')
|
||||
if (current === name) {
|
||||
this.$db.read().set('picBed.transformer', 'path').write()
|
||||
this.$db.set('picBed.transformer', 'path')
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
@@ -71,7 +71,7 @@ export default {
|
||||
}
|
||||
},
|
||||
created () {
|
||||
const shortKeyConfig = this.$db.read().get('settings.shortKey').value()
|
||||
const shortKeyConfig = this.$db.get('settings.shortKey')
|
||||
this.list = Object.keys(shortKeyConfig).map(item => shortKeyConfig[item])
|
||||
},
|
||||
methods: {
|
||||
@@ -82,8 +82,8 @@ export default {
|
||||
toggleEnable (item) {
|
||||
const status = !item.enable
|
||||
item.enable = status
|
||||
this.$db.set(`settings.shortKey.${item.name}.enable`, status).write()
|
||||
this.$electron.ipcRenderer.send('updateShortKeyConfig', item)
|
||||
this.$db.set(`settings.shortKey.${item.name}.enable`, status)
|
||||
this.$electron.ipcRenderer.send('updateShortKey', item)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,7 +53,7 @@
|
||||
this.getData()
|
||||
this.$electron.ipcRenderer.on('dragFiles', (event, files) => {
|
||||
files.forEach(item => {
|
||||
this.$db.read().get('uploaded').insert(item).write()
|
||||
this.$db.insert('uploaded', item)
|
||||
})
|
||||
this.files = this.$db.read().get('uploaded').slice().reverse().slice(0, 5).value()
|
||||
})
|
||||
@@ -83,7 +83,7 @@
|
||||
this.notification.body = item.imgUrl
|
||||
this.notification.icon = item.imgUrl
|
||||
const myNotification = new window.Notification(this.notification.title, this.notification)
|
||||
const pasteStyle = this.$db.read().get('settings.pasteStyle').value() || 'markdown'
|
||||
const pasteStyle = this.$db.get('settings.pasteStyle') || 'markdown'
|
||||
this.$electron.clipboard.writeText(pasteTemplate(pasteStyle, item))
|
||||
myNotification.onclick = () => {
|
||||
return true
|
||||
|
||||
@@ -130,17 +130,16 @@ export default {
|
||||
this.$electron.ipcRenderer.send('uploadChoosedFiles', sendFiles)
|
||||
},
|
||||
getPasteStyle () {
|
||||
this.pasteStyle = this.$db.read().get('settings.pasteStyle').value() || 'markdown'
|
||||
this.pasteStyle = this.$db.get('settings.pasteStyle') || 'markdown'
|
||||
},
|
||||
handlePasteStyleChange (val) {
|
||||
this.$db.read().set('settings.pasteStyle', val)
|
||||
.write()
|
||||
this.$db.set('settings.pasteStyle', val)
|
||||
},
|
||||
uploadClipboardFiles () {
|
||||
this.$electron.ipcRenderer.send('uploadClipboardFilesFromUploadPage')
|
||||
},
|
||||
getDefaultPicBed () {
|
||||
const current = this.$db.read().get('picBed.current').value()
|
||||
const current = this.$db.get('picBed.current')
|
||||
this.picBed.forEach(item => {
|
||||
if (item.type === current) {
|
||||
this.picBedName = item.name
|
||||
@@ -161,9 +160,9 @@ export default {
|
||||
return {
|
||||
label: item.name,
|
||||
type: 'radio',
|
||||
checked: this.$db.read().get('picBed.current').value() === item.type,
|
||||
checked: this.$db.get('picBed.current') === item.type,
|
||||
click () {
|
||||
_this.$db.read().set('picBed.current', item.type).write()
|
||||
_this.$db.set('picBed.current', item.type)
|
||||
_this.$electron.ipcRenderer.send('syncPicBed')
|
||||
}
|
||||
}
|
||||
|
||||
@@ -82,7 +82,7 @@ export default {
|
||||
}
|
||||
},
|
||||
created () {
|
||||
const config = this.$db.get('picBed.aliyun').value()
|
||||
const config = this.$db.get('picBed.aliyun')
|
||||
if (config) {
|
||||
for (let i in config) {
|
||||
this.form[i] = config[i]
|
||||
|
||||
@@ -73,7 +73,7 @@ export default {
|
||||
}
|
||||
},
|
||||
created () {
|
||||
const config = this.$db.get('picBed.github').value()
|
||||
const config = this.$db.get('picBed.github')
|
||||
if (config) {
|
||||
for (let i in config) {
|
||||
this.form[i] = config[i]
|
||||
|
||||
@@ -50,7 +50,7 @@ export default {
|
||||
}
|
||||
},
|
||||
created () {
|
||||
const config = this.$db.get('picBed.imgur').value()
|
||||
const config = this.$db.get('picBed.imgur')
|
||||
if (config) {
|
||||
for (let i in config) {
|
||||
this.form[i] = config[i]
|
||||
|
||||
@@ -52,7 +52,7 @@ export default {
|
||||
async handleConfirm () {
|
||||
const result = await this.$refs.configForm.validate()
|
||||
if (result !== false) {
|
||||
this.$db.read().set(`picBed.${this.type}`, result).write()
|
||||
this.$db.set(`picBed.${this.type}`, result)
|
||||
const successNotification = new window.Notification('设置结果', {
|
||||
body: '设置成功'
|
||||
})
|
||||
@@ -62,7 +62,7 @@ export default {
|
||||
}
|
||||
},
|
||||
setDefaultPicBed (type) {
|
||||
this.$db.read().set('picBed.current', type).write()
|
||||
this.$db.set('picBed.current', type)
|
||||
this.defaultPicBed = type
|
||||
const successNotification = new window.Notification('设置默认图床', {
|
||||
body: '设置成功'
|
||||
|
||||
@@ -90,7 +90,7 @@ export default {
|
||||
}
|
||||
},
|
||||
created () {
|
||||
const config = this.$db.get('picBed.qiniu').value()
|
||||
const config = this.$db.get('picBed.qiniu')
|
||||
if (config) {
|
||||
for (let i in config) {
|
||||
this.form[i] = config[i]
|
||||
|
||||
@@ -105,7 +105,7 @@ export default {
|
||||
}
|
||||
},
|
||||
created () {
|
||||
const config = this.$db.get('picBed.tcyun').value()
|
||||
const config = this.$db.get('picBed.tcyun')
|
||||
if (config) {
|
||||
for (let i in config) {
|
||||
this.form[i] = config[i]
|
||||
|
||||
@@ -81,7 +81,7 @@ export default {
|
||||
}
|
||||
},
|
||||
created () {
|
||||
const config = this.$db.get('picBed.upyun').value()
|
||||
const config = this.$db.get('picBed.upyun')
|
||||
if (config) {
|
||||
for (let i in config) {
|
||||
this.form[i] = config[i]
|
||||
|
||||
@@ -78,7 +78,7 @@ export default {
|
||||
}
|
||||
},
|
||||
created () {
|
||||
const config = this.$db.read().get('picBed.weibo').value()
|
||||
const config = this.$db.get('picBed.weibo')
|
||||
if (config) {
|
||||
this.form.username = config.username
|
||||
this.form.password = config.password
|
||||
@@ -91,13 +91,13 @@ export default {
|
||||
confirm (formName) {
|
||||
this.$refs[formName].validate((valid) => {
|
||||
if (valid) {
|
||||
this.$db.read().set('picBed.weibo', {
|
||||
this.$db.set('picBed.weibo', {
|
||||
username: this.form.username,
|
||||
password: this.form.password,
|
||||
quality: this.quality,
|
||||
cookie: this.form.cookie,
|
||||
chooseCookie: this.chooseCookie
|
||||
}).write()
|
||||
})
|
||||
const successNotification = new window.Notification('设置结果', {
|
||||
body: '设置成功'
|
||||
})
|
||||
|
||||
@@ -2,12 +2,12 @@ export default {
|
||||
name: '',
|
||||
data () {
|
||||
return {
|
||||
defaultPicBed: this.$db.read().get('picBed.current').value()
|
||||
defaultPicBed: this.$db.get('picBed.current')
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
setDefaultPicBed (type) {
|
||||
this.$db.read().set('picBed.current', type).write()
|
||||
this.$db.set('picBed.current', type)
|
||||
this.defaultPicBed = type
|
||||
const successNotification = new window.Notification('设置默认图床', {
|
||||
body: '设置成功'
|
||||
|
||||
Reference in New Issue
Block a user