🔨 Refactor: most config handle by picgo-core

for config syncing with picgo-core && picgo-plugins
This commit is contained in:
Molunerfinn 2019-12-26 20:15:41 +08:00
parent fec4360043
commit 3418560c63
30 changed files with 294 additions and 232 deletions

View File

@ -42,7 +42,7 @@
"keycode": "^2.2.0",
"lodash-id": "^0.14.0",
"lowdb": "^1.0.0",
"picgo": "^1.3.7",
"picgo": "^1.4.2",
"vue": "^2.6.10",
"vue-gallery": "^2.0.1",
"vue-lazyload": "^1.2.6",

View File

@ -1,6 +1,5 @@
'use strict'
import Uploader from '~/main/utils/uploader'
import {
app,
BrowserWindow,
@ -21,6 +20,8 @@ import {
installVueDevtools
} from 'vue-cli-plugin-electron-builder/lib'
import db from '#/datastore'
import picgo from '~/main/utils/picgo'
import uploader from '~/main/utils/uploader'
import beforeOpen from '~/main/utils/beforeOpen'
import pasteTemplate from '#/utils/pasteTemplate'
import updateChecker from '~/main/utils/updateChecker'
@ -63,14 +64,16 @@ const miniWinURL = isDevelopment
fixPath()
function createContextMenu () {
const picBeds = getPicBeds(app)
const picBeds = getPicBeds()
const submenu = picBeds.map(item => {
return {
label: item.name,
type: 'radio',
checked: db.get('picBed.current') === item.type,
click () {
db.set('picBed.current', item.type)
picgo.saveConfig({
'picBed.current': item.type
})
if (settingWindow) {
settingWindow.webContents.send('syncPicBed')
}
@ -193,7 +196,7 @@ function createTray () {
tray.on('drop-files', async (event: Event, files: string[]) => {
const pasteStyle = db.get('settings.pasteStyle') || 'markdown'
const imgs = await new Uploader(files, window!.webContents).upload()
const imgs = await uploader.setWebContents(window!.webContents).upload(files)
if (imgs !== false) {
for (let i = 0; i < imgs.length; i++) {
clipboard.writeText(pasteTemplate(pasteStyle, imgs[i]))
@ -374,7 +377,7 @@ const uploadClipboardFiles = async () => {
} else {
win = settingWindow || window || createSettingWindow()
}
let img = await new Uploader(undefined, win!.webContents).upload()
let img = await uploader.setWebContents(win!.webContents).upload()
if (img !== false) {
if (img.length > 0) {
const pasteStyle = db.get('settings.pasteStyle') || 'markdown'
@ -403,7 +406,7 @@ const uploadClipboardFiles = async () => {
const uploadChoosedFiles = async (webContents: WebContents, files: IFileWithPath[]) => {
const input = files.map(item => item.path)
const imgs = await new Uploader(input, webContents).upload()
const imgs = await uploader.setWebContents(webContents).upload(input)
if (imgs !== false) {
const pasteStyle = db.get('settings.pasteStyle') || 'markdown'
let pasteText = ''
@ -427,11 +430,11 @@ const uploadChoosedFiles = async (webContents: WebContents, files: IFileWithPath
}
}
picgoCoreIPC(app, ipcMain)
picgoCoreIPC()
// from macOS tray
ipcMain.on('uploadClipboardFiles', async () => {
const img = await new Uploader(undefined, window!.webContents).upload()
const img = await uploader.setWebContents(window!.webContents).upload()
if (img !== false) {
const pasteStyle = db.get('settings.pasteStyle') || 'markdown'
clipboard.writeText(pasteTemplate(pasteStyle, img[0]))
@ -536,7 +539,7 @@ ipcMain.on('syncPicBed', () => {
})
ipcMain.on('getPicBeds', (evt: IpcMainEvent) => {
const picBeds = getPicBeds(app)
const picBeds = getPicBeds()
evt.sender.send('getPicBeds', picBeds)
evt.returnValue = picBeds
})

View File

@ -6,6 +6,8 @@ import ElementUI from 'element-ui'
import { webFrame } from 'electron'
import 'element-ui/lib/theme-chalk/index.css'
import VueLazyLoad from 'vue-lazyload'
import axios from 'axios'
import mainMixin from './renderer/utils/mainMixin'
webFrame.setVisualZoomLevelLimits(1, 1)
webFrame.setLayoutZoomLevelLimits(0, 0)
@ -22,9 +24,11 @@ Vue.prototype.$builtInPicBed = [
'github'
]
Vue.prototype.$db = db
Vue.prototype.$http = axios
Vue.use(ElementUI)
Vue.use(VueLazyLoad)
Vue.mixin(mainMixin)
new Vue({
router,

View File

@ -1,14 +1,7 @@
import path from 'path'
import db from '#/datastore'
import { App } from 'electron'
// eslint-disable-next-line
const requireFunc = typeof __webpack_require__ === 'function' ? __non_webpack_require__ : require
import picgo from './picgo'
const getPicBeds = (app: App) => {
const PicGo = requireFunc('picgo')
const STORE_PATH = app.getPath('userData')
const CONFIG_PATH = path.join(STORE_PATH, '/data.json')
const picgo = new PicGo(CONFIG_PATH)
const getPicBeds = () => {
const picBedTypes = picgo.helper.uploader.getIdList()
const picBedFromDB = db.get('picBed.list') || []
const picBeds = picBedTypes.map((item: string) => {

View File

@ -7,7 +7,7 @@ import {
ipcMain
} from 'electron'
import db from '#/datastore'
import Uploader from './uploader'
import uploader from './uploader'
import pasteTemplate from '#/utils/pasteTemplate'
const WEBCONTENTS = Symbol('WEBCONTENTS')
@ -52,7 +52,7 @@ class GuiApi implements IGuiApi {
}
async upload (input: IUploadOption) {
const imgs = await new Uploader(input, this[WEBCONTENTS]).upload()
const imgs = await uploader.setWebContents(this[WEBCONTENTS]).upload(input)
if (imgs !== false) {
const pasteStyle = db.get('settings.pasteStyle') || 'markdown'
let pasteText = ''

19
src/main/utils/picgo.ts Normal file
View File

@ -0,0 +1,19 @@
import PicGoCore from '~/universal/types/picgo'
import {
app
} from 'electron'
import path from 'path'
// eslint-disable-next-line
const requireFunc = typeof __webpack_require__ === 'function' ? __non_webpack_require__ : require
const PicGo = requireFunc('picgo') as typeof PicGoCore
const STORE_PATH = app.getPath('userData')
const CONFIG_PATH = path.join(STORE_PATH, '/data.json')
const picgo = new PicGo(CONFIG_PATH)
picgo.setConfig({
debug: true,
PICGO_ENV: 'GUI'
})
export default picgo as PicGoCore

View File

@ -1,14 +1,24 @@
import path from 'path'
import GuiApi from './guiApi'
import { dialog, shell, IpcMain, IpcMainEvent, App } from 'electron'
import db from '#/datastore'
import {
dialog,
shell,
IpcMain,
IpcMainEvent,
App,
ipcMain,
app
} from 'electron'
import PicGoCore from '~/universal/types/picgo'
import { IPicGoHelperType } from '#/types/enum'
import shortKeyHandler from './shortKeyHandler'
import picgo from '~/main/utils/picgo'
// eslint-disable-next-line
const requireFunc = typeof __webpack_require__ === 'function' ? __non_webpack_require__ : require
const PicGo = requireFunc('picgo') as typeof PicGoCore
const PluginHandler = requireFunc('picgo/dist/lib/PluginHandler').default
// const PluginHandler = requireFunc('picgo/dist/lib/PluginHandler').default
const STORE_PATH = app.getPath('userData')
// const CONFIG_PATH = path.join(STORE_PATH, '/data.json')
type PicGoNotice = {
title: string,
@ -48,9 +58,8 @@ const handleConfigWithFunction = (config: any[]) => {
return config
}
const handleGetPluginList = (ipcMain: IpcMain, STORE_PATH: string, CONFIG_PATH: string) => {
const handleGetPluginList = () => {
ipcMain.on('getPluginList', (event: IpcMainEvent) => {
const picgo = new PicGo(CONFIG_PATH)
const pluginList = picgo.pluginLoader.getList()
const list = []
for (let i in pluginList) {
@ -102,48 +111,49 @@ const handleGetPluginList = (ipcMain: IpcMain, STORE_PATH: string, CONFIG_PATH:
})
}
const handlePluginInstall = (ipcMain: IpcMain, CONFIG_PATH: string) => {
const handlePluginInstall = () => {
ipcMain.on('installPlugin', async (event: IpcMainEvent, msg: string) => {
const picgo = new PicGo(CONFIG_PATH)
const pluginHandler = new PluginHandler(picgo)
picgo.on('installSuccess', (notice: PicGoNotice) => {
picgo.once('installSuccess', (notice: PicGoNotice) => {
event.sender.send('installSuccess', notice.body[0].replace(/picgo-plugin-/, ''))
shortKeyHandler.registerPluginShortKey(notice.body[0])
picgo.removeAllListeners('installFailed')
})
picgo.on('failed', () => {
picgo.once('installFailed', () => {
handleNPMError()
picgo.removeAllListeners('installSuccess')
})
await pluginHandler.uninstall([msg])
pluginHandler.install([msg])
await picgo.pluginHandler.install([msg])
picgo.cmd.program.removeAllListeners()
})
}
const handlePluginUninstall = (ipcMain: IpcMain, CONFIG_PATH: string) => {
const handlePluginUninstall = () => {
ipcMain.on('uninstallPlugin', async (event: IpcMainEvent, msg: string) => {
const picgo = new PicGo(CONFIG_PATH)
const pluginHandler = new PluginHandler(picgo)
picgo.on('uninstallSuccess', (notice: PicGoNotice) => {
picgo.once('uninstallSuccess', (notice: PicGoNotice) => {
event.sender.send('uninstallSuccess', notice.body[0].replace(/picgo-plugin-/, ''))
shortKeyHandler.unregisterPluginShortKey(notice.body[0])
picgo.removeAllListeners('uninstallFailed')
})
picgo.on('failed', () => {
picgo.once('uninstallFailed', () => {
handleNPMError()
picgo.removeAllListeners('uninstallSuccess')
})
await pluginHandler.uninstall([msg])
await picgo.pluginHandler.uninstall([msg])
picgo.cmd.program.removeAllListeners()
})
}
const handlePluginUpdate = (ipcMain: IpcMain, CONFIG_PATH: string) => {
const handlePluginUpdate = () => {
ipcMain.on('updatePlugin', async (event: IpcMainEvent, msg: string) => {
const picgo = new PicGo(CONFIG_PATH)
const pluginHandler = new PluginHandler(picgo)
picgo.on('updateSuccess', notice => {
picgo.once('updateSuccess', (notice: { body: string[], title: string }) => {
event.sender.send('updateSuccess', notice.body[0].replace(/picgo-plugin-/, ''))
picgo.removeAllListeners('updateFailed')
})
picgo.on('failed', () => {
picgo.once('updateFailed', () => {
handleNPMError()
picgo.removeAllListeners('updateSuccess')
})
await pluginHandler.update([msg])
await picgo.pluginHandler.update([msg])
picgo.cmd.program.removeAllListeners()
})
}
@ -160,9 +170,8 @@ const handleNPMError = () => {
})
}
const handleGetPicBedConfig = (ipcMain: IpcMain, CONFIG_PATH: string) => {
const handleGetPicBedConfig = () => {
ipcMain.on('getPicBedConfig', (event: IpcMainEvent, type: string) => {
const picgo = new PicGo(CONFIG_PATH)
const name = picgo.helper.uploader.get(type).name || type
if (picgo.helper.uploader.get(type).config) {
const config = handleConfigWithFunction(picgo.helper.uploader.get(type).config(picgo))
@ -174,9 +183,8 @@ const handleGetPicBedConfig = (ipcMain: IpcMain, CONFIG_PATH: string) => {
})
}
const handlePluginActions = (ipcMain: IpcMain, CONFIG_PATH: string) => {
const handlePluginActions = () => {
ipcMain.on('pluginActions', (event: IpcMainEvent, name: string, label: string) => {
const picgo = new PicGo(CONFIG_PATH)
const plugin = picgo.pluginLoader.getPlugin(`picgo-plugin-${name}`)
const guiApi = new GuiApi(event.sender)
if (plugin.guiMenu && plugin.guiMenu(picgo).length > 0) {
@ -190,9 +198,8 @@ const handlePluginActions = (ipcMain: IpcMain, CONFIG_PATH: string) => {
})
}
const handleRemoveFiles = (ipcMain: IpcMain, CONFIG_PATH: string) => {
const handleRemoveFiles = () => {
ipcMain.on('removeFiles', (event: IpcMainEvent, files: ImgInfo[]) => {
const picgo = new PicGo(CONFIG_PATH)
const guiApi = new GuiApi(event.sender)
setTimeout(() => {
picgo.emit('remove', files, guiApi)
@ -200,26 +207,19 @@ const handleRemoveFiles = (ipcMain: IpcMain, CONFIG_PATH: string) => {
})
}
// 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: App, ipcMain: IpcMain) => {
const STORE_PATH = app.getPath('userData')
const CONFIG_PATH = path.join(STORE_PATH, '/data.json')
handleGetPluginList(ipcMain, STORE_PATH, CONFIG_PATH)
handlePluginInstall(ipcMain, CONFIG_PATH)
handlePluginUninstall(ipcMain, CONFIG_PATH)
handlePluginUpdate(ipcMain, CONFIG_PATH)
handleGetPicBedConfig(ipcMain, CONFIG_PATH)
handlePluginActions(ipcMain, CONFIG_PATH)
handleRemoveFiles(ipcMain, CONFIG_PATH)
// handlePluginShortKeyRegister({})
const handlePicGoSaveData = () => {
ipcMain.on('picgoSaveData', (event: IpcMainEvent, data: IObj) => {
picgo.saveConfig(data)
})
}
export default () => {
handleGetPluginList()
handlePluginInstall()
handlePluginUninstall()
handlePluginUpdate()
handleGetPicBedConfig()
handlePluginActions()
handleRemoveFiles()
handlePicGoSaveData()
}

View File

@ -10,12 +10,7 @@ import logger from './logger'
import GuiApi from './guiApi'
import db from '#/datastore'
import shortKeyService from './shortKeyService'
// eslint-disable-next-line
const requireFunc = typeof __webpack_require__ === 'function' ? __non_webpack_require__ : require
const PicGo = requireFunc('picgo') as typeof PicGoCore
const STORE_PATH = app.getPath('userData')
const CONFIG_PATH = path.join(STORE_PATH, '/data.json')
import picgo from './picgo'
class ShortKeyHandler {
private isInModifiedMode: boolean = false
@ -40,7 +35,6 @@ class ShortKeyHandler {
})
}
private initPluginsShortKey () {
const picgo = new PicGo(CONFIG_PATH)
const pluginList = picgo.pluginLoader.getList()
for (let item of pluginList) {
const plugin = picgo.pluginLoader.getPlugin(item)
@ -75,12 +69,14 @@ class ShortKeyHandler {
logger.warn(`${command} do not provide a key to bind`)
}
if (writeFlag) {
db.set(`settings.shortKey.${command}`, {
enable: true,
name: config.name,
label: config.label,
key: config.key
} as IShortKeyConfig)
picgo.saveConfig({
[`settings.shortKey.${command}`]: {
enable: true,
name: config.name,
label: config.label,
key: config.key
}
})
}
}
// enable or disable shortKey
@ -88,13 +84,17 @@ class ShortKeyHandler {
const command = `${from}:${item.name}`
if (item.enable === false) {
globalShortcut.unregister(item.key)
db.set(`settings.shortKey.${command}.enable`, false)
picgo.saveConfig({
[`settings.shortKey.${command}.enable`]: false
})
return true
} else {
if (globalShortcut.isRegistered(item.key)) {
return false
} else {
db.set(`settings.shortKey.${command}.enable`, true)
picgo.saveConfig({
[`settings.shortKey.${command}.enable`]: true
})
globalShortcut.register(item.key, () => {
this.handler(command)
})
@ -107,7 +107,9 @@ class ShortKeyHandler {
const command = `${from}:${item.name}`
if (globalShortcut.isRegistered(item.key)) return false
globalShortcut.unregister(oldKey)
db.set(`settings.shortKey.${command}.key`, item.key)
picgo.saveConfig({
[`settings.shortKey.${command}.key`]: item.key
})
globalShortcut.register(item.key, () => {
this.handler(`${from}:${item.name}`)
})
@ -122,7 +124,6 @@ class ShortKeyHandler {
} else if (command.includes('picgo-plugin-')) {
const handler = shortKeyService.getShortKeyHandler(command)
if (handler) {
const picgo = new PicGo(CONFIG_PATH)
// make sure settingWindow is created
bus.once('createSettingWindowDone', (cmd: string, settingWindowId: number) => {
if (cmd === command) {
@ -138,7 +139,6 @@ class ShortKeyHandler {
}
}
registerPluginShortKey (pluginName: string) {
const picgo = new PicGo(CONFIG_PATH)
const plugin = picgo.pluginLoader.getPlugin(pluginName)
if (plugin && plugin.commands) {
if (typeof plugin.commands !== 'function') {
@ -170,7 +170,7 @@ class ShortKeyHandler {
keyList.forEach(item => {
globalShortcut.unregister(item.key)
shortKeyService.unregisterCommand(item.command)
db.unset('settings.shortKey', item.command)
picgo.unsetConfig('settings.shortKey', item.command)
})
}
}

View File

@ -3,13 +3,8 @@ import db from '#/datastore'
import axios from 'axios'
import pkg from 'root/package.json'
const version = pkg.version
let release = 'https://api.github.com/repos/Molunerfinn/PicGo/releases/latest'
let release = 'https://cdn.jsdelivr.net/gh/Molunerfinn/PicGo/package.json'
const downloadUrl = 'https://github.com/Molunerfinn/PicGo/releases/latest'
const isDevelopment = process.env.NODE_ENV !== 'production'
if (isDevelopment) {
release = `${release}?access_token=${process.env.GITHUB_TOKEN}`
}
const checkVersion = async () => {
let showTip = db.get('settings.showUpdateTip')
@ -25,7 +20,7 @@ const checkVersion = async () => {
console.log(err)
}
if (res.status === 200) {
const latest = res.data.name
const latest = res.data.version
const result = compareVersion2Update(version, latest)
if (result) {
dialog.showMessageBox({

View File

@ -5,37 +5,15 @@ import {
ipcMain,
WebContents
} from 'electron'
import path from 'path'
import dayjs from 'dayjs'
import PicGoCore from '~/universal/types/picgo'
import picgo from '~/main/utils/picgo'
import db from '#/datastore'
// eslint-disable-next-line
const requireFunc = typeof __webpack_require__ === 'function' ? __non_webpack_require__ : require
const PicGo = requireFunc('picgo') as typeof PicGoCore
const STORE_PATH = app.getPath('userData')
const CONFIG_PATH = path.join(STORE_PATH, '/data.json')
const renameURL = process.env.NODE_ENV === 'development'
? `${(process.env.WEBPACK_DEV_SERVER_URL as string)}#rename-page`
: `picgo://./index.html#rename-page`
// type BrowserWindowOptions = {
// height: number,
// width: number,
// show: boolean,
// fullscreenable: boolean,
// resizable: boolean,
// vibrancy: string | any,
// webPreferences: {
// nodeIntegration: boolean,
// nodeIntegrationInWorker: boolean,
// backgroundThrottling: boolean
// },
// backgroundColor?: string
// autoHideMenuBar?: boolean
// transparent?: boolean
// }
const createRenameWindow = (win: BrowserWindow) => {
const createRenameWindow = (currentWindow: BrowserWindow) => {
let options: IBrowserWindowOptions = {
height: 175,
width: 300,
@ -60,9 +38,9 @@ const createRenameWindow = (win: BrowserWindow) => {
const window = new BrowserWindow(options)
window.loadURL(renameURL)
// check if this window is visible
if (win.isVisible()) {
if (currentWindow && currentWindow.isVisible()) {
// bounds: { x: 821, y: 75, width: 800, height: 450 }
const bounds = win.getBounds()
const bounds = currentWindow.getBounds()
const positionX = bounds.x + bounds.width / 2 - 150
let positionY
// if is the settingWindow
@ -98,27 +76,34 @@ const waitForRename = (window: BrowserWindow, id: number): Promise<string|null>
}
class Uploader {
private picgo: PicGoCore
private webContents: WebContents
private img: undefined | string[]
constructor (img: IUploadOption, webContents: WebContents, picgo: PicGoCore | undefined = undefined) {
this.img = img
this.webContents = webContents
this.picgo = picgo || new PicGo(CONFIG_PATH)
private webContents: WebContents | null = null
private currentWindow: BrowserWindow | null = null
constructor () {
this.init()
}
upload (): Promise<ImgInfo[]|false> {
const win = BrowserWindow.fromWebContents(this.webContents)
const picgo = this.picgo
picgo.config.debug = true
// for picgo-core
picgo.config.PICGO_ENV = 'GUI'
let input = this.img
init () {
picgo.on('notification', message => {
const notification = new Notification(message)
notification.show()
})
picgo.on('uploadProgress', progress => {
this.webContents!.send('uploadProgress', progress)
})
picgo.on('beforeTransform', ctx => {
if (db.get('settings.uploadNotification')) {
const notification = new Notification({
title: '上传进度',
body: '正在上传'
})
notification.show()
}
})
picgo.helper.beforeUploadPlugins.register('renameFn', {
handle: async ctx => {
const rename = picgo.getConfig('settings.rename')
const autoRename = picgo.getConfig('settings.autoRename')
const rename = db.get('settings.rename')
const autoRename = db.get('settings.autoRename')
await Promise.all(ctx.output.map(async (item, index) => {
let name: undefined | string | null
let fileName: string | undefined
@ -128,7 +113,7 @@ class Uploader {
fileName = item.fileName
}
if (rename) {
const window = createRenameWindow(win)
const window = createRenameWindow(this.currentWindow!)
await waitForShow(window.webContents)
window.webContents.send('rename', fileName, window.webContents.id)
name = await waitForRename(window, window.webContents.id)
@ -137,46 +122,40 @@ class Uploader {
}))
}
})
}
picgo.on('beforeTransform', ctx => {
if (ctx.getConfig('settings.uploadNotification')) {
const notification = new Notification({
title: '上传进度',
body: '正在上传'
})
notification.show()
}
})
setWebContents (webContents: WebContents) {
this.webContents = webContents
return this
}
picgo.upload(input)
upload (img?: IUploadOption): Promise<ImgInfo[]|false> {
this.currentWindow = BrowserWindow.fromWebContents(this.webContents!)
picgo.on('notification', message => {
const notification = new Notification(message)
notification.show()
})
picgo.on('uploadProgress', progress => {
this.webContents.send('uploadProgress', progress)
})
picgo.upload(img)
return new Promise((resolve) => {
picgo.on('finished', ctx => {
picgo.once('finished', ctx => {
if (ctx.output.every((item: ImgInfo) => item.imgUrl)) {
resolve(ctx.output)
} else {
resolve(false)
}
picgo.removeAllListeners('failed')
})
picgo.on('failed', ctx => {
const notification = new Notification({
title: '上传失败',
body: '请检查配置和上传的文件是否符合要求'
})
notification.show()
picgo.once('failed', ctx => {
setTimeout(() => {
const notification = new Notification({
title: '上传失败',
body: '请检查配置和上传的文件是否符合要求'
})
notification.show()
}, 500)
picgo.removeAllListeners('finished')
resolve(false)
})
})
}
}
export default Uploader
export default new Uploader()

View File

@ -27,7 +27,9 @@ export default {
},
methods: {
choosePicBed (val) {
this.$db.set('picBed.current', this.type)
this.letPicGoSaveData({
'picBed.current': this.type
})
this.$emit('update:choosed', this.type)
}
}

View File

@ -143,7 +143,9 @@ export default class extends Vue {
type: 'radio',
checked: this.$db.get('picBed.current') === item.type,
click () {
_this.$db.set('picBed.current', item.type)
_this.letPicGoSaveData({
'picBed.current': item.type
})
ipcRenderer.send('syncPicBed')
}
}

View File

@ -371,7 +371,9 @@ export default class extends Vue {
}
confirmProxy () {
this.proxyVisible = false
db.set('picBed.proxy', this.proxy)
this.letPicGoSaveData({
'picBed.proxy': this.proxy
})
const successNotification = new Notification('设置代理', {
body: '设置成功'
})
@ -391,7 +393,9 @@ export default class extends Vue {
}
return item
})
db.set('picBed.list', list)
this.letPicGoSaveData({
'picBed.list': list
})
ipcRenderer.send('getPicBeds')
}
handleAutoStartChange (val: boolean) {
@ -399,10 +403,14 @@ export default class extends Vue {
ipcRenderer.send('autoStart', val)
}
handleRename (val: boolean) {
db.set('settings.rename', val)
this.letPicGoSaveData({
'settings.rename': val
})
}
handleAutoRename (val: boolean) {
db.set('settings.autoRename', val)
this.letPicGoSaveData({
'settings.autoRename': val
})
}
compareVersion2Update (current: string, latest: string) {
const currentVersion = current.split('.').map(item => parseInt(item))
@ -447,7 +455,9 @@ export default class extends Vue {
if (this.form.logLevel.length === 0) {
return this.$message.error('请选择日志记录等级')
}
db.set('settings.logLevel', this.form.logLevel)
this.letPicGoSaveData({
'settings.logLevel': this.form.logLevel
})
const successNotification = new Notification('设置日志', {
body: '设置成功'
})

View File

@ -199,7 +199,9 @@ export default class extends Vue {
label: '启用插件',
enabled: !plugin.enabled,
click () {
_this.$db.set(`picgoPlugins.picgo-plugin-${plugin.name}`, true)
_this.letPicGoSaveData({
[`picgoPlugins.picgo-plugin-${plugin.name}`]: true
})
plugin.enabled = true
_this.getPicBeds()
}
@ -207,7 +209,9 @@ export default class extends Vue {
label: '禁用插件',
enabled: plugin.enabled,
click () {
_this.$db.set(`picgoPlugins.picgo-plugin-${plugin.name}`, false)
_this.letPicGoSaveData({
[`picgoPlugins.picgo-plugin-${plugin.name}`]: false
})
plugin.enabled = false
_this.getPicBeds()
if (plugin.config.transformer.name) {
@ -334,9 +338,13 @@ export default class extends Vue {
toggleTransformer (transformer: string) {
let currentTransformer = this.$db.get('picBed.transformer') || 'path'
if (currentTransformer === transformer) {
this.$db.set('picBed.transformer', 'path')
this.letPicGoSaveData({
'picBed.transformer': 'path'
})
} else {
this.$db.set('picBed.transformer', transformer)
this.letPicGoSaveData({
'picBed.transformer': transformer
})
}
}
async handleConfirmConfig () {
@ -345,13 +353,19 @@ export default class extends Vue {
if (result !== false) {
switch (this.currentType) {
case 'plugin':
this.$db.set(`picgo-plugin-${this.configName}`, result)
this.letPicGoSaveData({
[`picgo-plugin-${this.configName}`]: result
})
break
case 'uploader':
this.$db.set(`picBed.${this.configName}`, result)
this.letPicGoSaveData({
[`picBed.${this.configName}`]: result
})
break
case 'transformer':
this.$db.set(`transformer.${this.configName}`, result)
this.letPicGoSaveData({
[`transformer.${this.configName}`]: result
})
break
}
const successNotification = new Notification('设置结果', {
@ -368,9 +382,13 @@ export default class extends Vue {
// this.$http.get(`https://api.npms.io/v2/search?q=${val}`)
this.$http.get(`https://registry.npmjs.com/-/v1/search?text=${val}`)
.then((res: INPMSearchResult) => {
this.pluginList = res.data.objects.map((item: INPMSearchResultObject) => {
return this.handleSearchResult(item)
})
this.pluginList = res.data.objects
.filter((item:INPMSearchResultObject) => {
return item.package.name.includes('picgo-plugin-')
})
.map((item: INPMSearchResultObject) => {
return this.handleSearchResult(item)
})
this.loading = false
})
.catch(err => {
@ -404,13 +422,17 @@ export default class extends Vue {
if (item === 'uploader') {
const current = this.$db.get('picBed.current')
if (current === name) {
this.$db.set('picBed.current', 'smms')
this.letPicGoSaveData({
'picBed.current': 'smms'
})
}
}
if (item === 'transformer') {
const current = this.$db.get('picBed.transformer')
if (current === name) {
this.$db.set('picBed.transformer', 'path')
this.letPicGoSaveData({
'picBed.transformer': 'path'
})
}
}
}
@ -422,6 +444,9 @@ export default class extends Vue {
goAwesomeList () {
remote.shell.openExternal('https://github.com/PicGo/Awesome-PicGo')
}
letPicGoSaveData (data: IObj) {
ipcRenderer.send('picgoSaveData', data)
}
beforeDestroy () {
ipcRenderer.removeAllListeners('pluginList')
ipcRenderer.removeAllListeners('installSuccess')

View File

@ -166,7 +166,9 @@ export default class extends Vue {
type: 'radio',
checked: this.$db.get('picBed.current') === item.type,
click () {
_this.$db.set('picBed.current', item.type)
_this.letPicGoSaveData({
'picBed.current': item.type
})
ipcRenderer.send('syncPicBed')
}
}

View File

@ -90,7 +90,9 @@ export default class extends Vue {
// @ts-ignore
this.$refs.aliyun.validate((valid) => {
if (valid) {
this.$db.set('picBed.aliyun', this.form)
this.letPicGoSaveData({
'picBed.aliyun': this.form
})
const successNotification = new window.Notification('设置结果', {
body: '设置成功'
})

View File

@ -81,7 +81,9 @@ export default class extends Vue {
// @ts-ignore
this.$refs.github.validate((valid) => {
if (valid) {
this.$db.set('picBed.github', this.form)
this.letPicGoSaveData({
'picBed.github': this.form
})
const successNotification = new Notification('设置结果', {
body: '设置成功'
})

View File

@ -58,7 +58,9 @@ export default class extends Vue {
// @ts-ignore
this.$refs.imgur.validate((valid) => {
if (valid) {
this.$db.set('picBed.imgur', this.form)
this.letPicGoSaveData({
'picBed.imgur': this.form
})
const successNotification = new Notification('设置结果', {
body: '设置成功'
})

View File

@ -56,7 +56,9 @@ export default class extends Vue {
// @ts-ignore
const result = await this.$refs.configForm.validate()
if (result !== false) {
this.$db.set(`picBed.${this.type}`, result)
this.letPicGoSaveData({
[`picBed.${this.type}`]: result
})
const successNotification = new Notification('设置结果', {
body: '设置成功'
})
@ -66,7 +68,9 @@ export default class extends Vue {
}
}
setDefaultPicBed (type: string) {
this.$db.set('picBed.current', type)
this.letPicGoSaveData({
'picBed.current': type
})
// @ts-ignore mixin
this.defaultPicBed = type
const successNotification = new Notification('设置默认图床', {

View File

@ -98,7 +98,9 @@ export default class extends Vue {
// @ts-ignore
this.$refs.qiniu.validate((valid) => {
if (valid) {
this.$db.set('picBed.qiniu', this.form)
this.letPicGoSaveData({
'picBed.qiniu': this.form
})
const successNotification = new Notification('设置结果', {
body: '设置成功'
})

View File

@ -24,7 +24,9 @@ import mixin from '@/utils/ConfirmButtonMixin'
})
export default class extends Vue {
confirm () {
this.$db.set('picBed.smms', true)
this.letPicGoSaveData({
'picBed.smms': true
})
// @ts-ignore mixin
this.setDefaultPicBed('smms')
const successNotification = new window.Notification('设置结果', {

View File

@ -114,7 +114,9 @@ export default class extends Vue {
// @ts-ignore
this.$refs.tcyun.validate((valid) => {
if (valid) {
this.$db.set('picBed.tcyun', this.form)
this.letPicGoSaveData({
'picBed.tcyun': this.form
})
const successNotification = new window.Notification('设置结果', {
body: '设置成功'
})

View File

@ -89,7 +89,9 @@ export default class extends Vue {
// @ts-ignore
this.$refs.tcyun.validate((valid) => {
if (valid) {
this.$db.set('picBed.upyun', this.form)
this.letPicGoSaveData({
'picBed.upyun': this.form
})
const successNotification = new Notification('设置结果', {
body: '设置成功'
})

View File

@ -91,12 +91,14 @@ export default {
confirm (formName) {
this.$refs[formName].validate((valid) => {
if (valid) {
this.$db.set('picBed.weibo', {
username: this.form.username,
password: this.form.password,
quality: this.quality,
cookie: this.form.cookie,
chooseCookie: this.chooseCookie
this.letPicGoSaveData({
'picBed.weibo': {
username: this.form.username,
password: this.form.password,
quality: this.quality,
cookie: this.form.cookie,
chooseCookie: this.chooseCookie
}
})
const successNotification = new window.Notification('设置结果', {
body: '设置成功'

View File

@ -1,9 +1,12 @@
import { Component, Vue } from 'vue-property-decorator'
import { ipcRenderer } from 'electron'
@Component
export default class extends Vue {
defaultPicBed = this.$db.get('picBed.current')
setDefaultPicBed (type: string) {
this.$db.set('picBed.current', type)
this.letPicGoSaveData({
'picBed.current': type
})
this.defaultPicBed = type
const successNotification = new Notification('设置默认图床', {
body: '设置成功'

View File

@ -0,0 +1,8 @@
import { Component, Vue } from 'vue-property-decorator'
import { ipcRenderer } from 'electron'
@Component
export default class extends Vue {
letPicGoSaveData (data: IObj) {
ipcRenderer.send('picgoSaveData', data)
}
}

View File

@ -59,7 +59,7 @@ class DB {
return this.read().get(key).insert(value).write()
}
unset (key: string, value: any): boolean {
return this.read().get(key).unset(value).write()
return this.read().get(key).unset(value).value()
}
}

View File

@ -8,5 +8,6 @@ declare module 'vue/types/vue' {
$db: typeof db
$http: typeof axios
$builtInPicBed: string[]
letPicGoSaveData(data: IObj): void
}
}

View File

@ -162,7 +162,7 @@ interface IShowInputBoxOption {
type IShowFileExplorerOption = IObj
type IUploadOption = undefined | string[]
type IUploadOption = string[]
interface IShowNotificationOption {
title: string

View File

@ -2870,12 +2870,15 @@ commander@~2.8.1:
dependencies:
graceful-readlink ">= 1.0.0"
comment-json@^1.1.3:
version "1.1.3"
resolved "https://registry.yarnpkg.com/comment-json/-/comment-json-1.1.3.tgz#6986c3330fee0c4c9e00c2398cd61afa5d8f239e"
integrity sha1-aYbDMw/uDEyeAMI5jNYa+l2PI54=
comment-json@^2.3.1:
version "2.3.1"
resolved "https://registry.npm.taobao.org/comment-json/download/comment-json-2.3.1.tgz#40f24f573ffece9b9a87806244c330d614a32604"
integrity sha1-QPJPVz/+zpuah4BiRMMw1hSjJgQ=
dependencies:
json-parser "^1.0.0"
core-util-is "^1.0.2"
esprima "^4.0.1"
has-own-prop "^2.0.0"
repeat-string "^1.6.1"
commitizen@^4.0.3:
version "4.0.3"
@ -3262,7 +3265,7 @@ core-js@^3.3.2, core-js@^3.4.3:
resolved "https://registry.yarnpkg.com/core-js/-/core-js-3.6.0.tgz#2b854e451de1967d1e29896025cdc13a2518d9ea"
integrity sha512-AHPTNKzyB+YwgDWoSOCaid9PUSEF6781vsfiK8qUz62zRR448/XgK2NtCbpiUGizbep8Lrpt0Du19PpGGZvw3Q==
core-util-is@1.0.2, core-util-is@~1.0.0:
core-util-is@1.0.2, core-util-is@^1.0.2, core-util-is@~1.0.0:
version "1.0.2"
resolved "https://registry.yarnpkg.com/core-util-is/-/core-util-is-1.0.2.tgz#b5fd54220aa2bc5ab57aab7140c940754503c1a7"
integrity sha1-tf1UIgqivFq1eqtxQMlAdUUDwac=
@ -4534,12 +4537,7 @@ espree@^5.0.1:
acorn-jsx "^5.0.0"
eslint-visitor-keys "^1.0.0"
esprima@^2.7.0:
version "2.7.3"
resolved "https://registry.yarnpkg.com/esprima/-/esprima-2.7.3.tgz#96e3b70d5779f6ad49cd032673d1c312767ba581"
integrity sha1-luO3DVd59q1JzQMmc9HDEnZ7pYE=
esprima@^4.0.0:
esprima@^4.0.0, esprima@^4.0.1:
version "4.0.1"
resolved "https://registry.yarnpkg.com/esprima/-/esprima-4.0.1.tgz#13b04cdb3e6c5d19df91ab6987a8695619b0aa71"
integrity sha512-eGuFFw7Upda+g4p+QHvnW0RyTX/SVeJBDM/gCtMARO0cLuT2HcEKnTPvhjV6aGeqrCB/sbNop0Kszm0jsaWU4A==
@ -5628,6 +5626,11 @@ has-flag@^4.0.0:
resolved "https://registry.yarnpkg.com/has-flag/-/has-flag-4.0.0.tgz#944771fd9c81c81265c4d6941860da06bb59479b"
integrity sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==
has-own-prop@^2.0.0:
version "2.0.0"
resolved "https://registry.npm.taobao.org/has-own-prop/download/has-own-prop-2.0.0.tgz#f0f95d58f65804f5d218db32563bb85b8e0417af"
integrity sha1-8PldWPZYBPXSGNsyVju4W44EF68=
has-symbol-support-x@^1.4.1:
version "1.4.2"
resolved "https://registry.yarnpkg.com/has-symbol-support-x/-/has-symbol-support-x-1.4.2.tgz#1409f98bc00247da45da67cee0a36f282ff26455"
@ -6661,13 +6664,6 @@ json-parse-better-errors@^1.0.1, json-parse-better-errors@^1.0.2:
resolved "https://registry.yarnpkg.com/json-parse-better-errors/-/json-parse-better-errors-1.0.2.tgz#bb867cfb3450e69107c131d1c514bab3dc8bcaa9"
integrity sha512-mrqyZKfX5EhL7hvqcV6WG1yYjnjeuYDzDhhcAAUrq8Po85NBQBJP+ZDUT75qZQ98IkUoBqdkExkukOU7Ts2wrw==
json-parser@^1.0.0:
version "1.1.5"
resolved "https://registry.yarnpkg.com/json-parser/-/json-parser-1.1.5.tgz#e62ec5261d1a6a5fc20e812a320740c6d9005677"
integrity sha1-5i7FJh0aal/CDoEqMgdAxtkAVnc=
dependencies:
esprima "^2.7.0"
json-schema-traverse@^0.4.1:
version "0.4.1"
resolved "https://registry.yarnpkg.com/json-schema-traverse/-/json-schema-traverse-0.4.1.tgz#69f6a87d9513ab8bb8fe63bdb0979c448e684660"
@ -8280,14 +8276,14 @@ performance-now@^2.1.0:
resolved "https://registry.yarnpkg.com/performance-now/-/performance-now-2.1.0.tgz#6309f4e0e5fa913ec1c69307ae364b4b377c9e7b"
integrity sha1-Ywn04OX6kT7BxpMHrjZLSzd8nns=
picgo@^1.3.7:
version "1.3.7"
resolved "https://registry.yarnpkg.com/picgo/-/picgo-1.3.7.tgz#b152ec8235062a5638243c20afbafe87bf295c47"
integrity sha512-iJamLDhBy+Io/ePS6G+WT7ncXdmATrDFRFP4RvypqkuIdvPBULhukWyIEbB5hiXaQbYNBK6xx2trxp86YuvyeQ==
picgo@^1.4.2:
version "1.4.2"
resolved "https://registry.npm.taobao.org/picgo/download/picgo-1.4.2.tgz#3a9ca1fb3c7c51c0b94036eac95a842bb022a5dc"
integrity sha1-Opyh+zx8UcC5QDbqyVqEK7Aipdw=
dependencies:
chalk "^2.4.1"
commander "^2.17.0"
comment-json "^1.1.3"
comment-json "^2.3.1"
cross-spawn "^6.0.5"
dayjs "^1.7.4"
download-git-repo "^1.1.0"