diff --git a/src/main/index.js b/src/main/index.js index 93ffab3..836ea32 100644 --- a/src/main/index.js +++ b/src/main/index.js @@ -5,8 +5,8 @@ import { app, BrowserWindow, Tray, Menu, Notification, clipboard, ipcMain, globa import db from '../datastore' import pasteTemplate from './utils/pasteTemplate' import updateChecker from './utils/updateChecker' +import { getPicBeds } from './utils/getPicBeds' import pkg from '../../package.json' -import picBed from '../datastore/pic-bed' import picgoCoreIPC from './utils/picgoCoreIPC' /** * Set `__static` path to static files in production @@ -38,7 +38,8 @@ const miniWinURL = process.env.NODE_ENV === 'development' function createTray () { const menubarPic = process.platform === 'darwin' ? `${__static}/menubar.png` : `${__static}/menubar-nodarwin.png` tray = new Tray(menubarPic) - const submenu = picBed.map(item => { + const picBeds = getPicBeds(app) + const submenu = picBeds.map(item => { return { label: item.name, type: 'radio', @@ -354,7 +355,8 @@ const uploadClipboardFiles = async () => { const updateDefaultPicBed = () => { if (process.platform === 'darwin' || process.platform === 'win32') { - const types = picBed.map(item => item.type) + const picBeds = getPicBeds(app) + const types = picBeds.map(item => item.type) let submenuItem = contextMenu.items[2].submenu.items submenuItem.forEach((item, index) => { const result = db.read().get('picBed.current').value() === types[index] @@ -484,6 +486,11 @@ ipcMain.on('syncPicBed', (evt) => { updateDefaultPicBed() }) +ipcMain.on('getPicBeds', (evt) => { + const picBeds = getPicBeds(app) + evt.sender.send('getPicBeds', picBeds) +}) + const shortKeyHash = { upload: uploadClipboardFiles } diff --git a/src/main/utils/getPicBeds.js b/src/main/utils/getPicBeds.js new file mode 100644 index 0000000..2bd3fc1 --- /dev/null +++ b/src/main/utils/getPicBeds.js @@ -0,0 +1,26 @@ +import path from 'path' +import db from '../../datastore' +// eslint-disable-next-line +const requireFunc = typeof __webpack_require__ === 'function' ? __non_webpack_require__ : require + +const getPicBeds = (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 picBedTypes = picgo.helper.uploader.getIdList() + const picBedFromDB = db.read().get('picBed.list').value() || [] + const picBeds = picBedTypes.map(item => { + const visible = picBedFromDB.find(i => i.type === item) // object or undefined + return { + type: item, + name: picgo.helper.uploader.get(item).name || item, + visible: visible ? visible.visible : true + } + }) + return picBeds +} + +export { + getPicBeds +} diff --git a/src/main/utils/picgoCoreIPC.js b/src/main/utils/picgoCoreIPC.js index 841a3bb..eec99dd 100644 --- a/src/main/utils/picgoCoreIPC.js +++ b/src/main/utils/picgoCoreIPC.js @@ -75,7 +75,7 @@ const handleGetPluginList = (ipcMain, STORE_PATH, CONFIG_PATH) => { }) } -const handlePluginInstall = (ipcMain, STORE_PATH, CONFIG_PATH) => { +const handlePluginInstall = (ipcMain, CONFIG_PATH) => { ipcMain.on('installPlugin', (event, msg) => { const picgo = new PicGo(CONFIG_PATH) const pluginHandler = new PluginHandler(picgo) @@ -87,7 +87,7 @@ const handlePluginInstall = (ipcMain, STORE_PATH, CONFIG_PATH) => { }) } -const handlePluginUninstall = (ipcMain, STORE_PATH, CONFIG_PATH) => { +const handlePluginUninstall = (ipcMain, CONFIG_PATH) => { ipcMain.on('uninstallPlugin', (event, msg) => { const picgo = new PicGo(CONFIG_PATH) const pluginHandler = new PluginHandler(picgo) @@ -99,7 +99,7 @@ const handlePluginUninstall = (ipcMain, STORE_PATH, CONFIG_PATH) => { }) } -const handlePluginUpdate = (ipcMain, STORE_PATH, CONFIG_PATH) => { +const handlePluginUpdate = (ipcMain, CONFIG_PATH) => { ipcMain.on('updatePlugin', (event, msg) => { const picgo = new PicGo(CONFIG_PATH) const pluginHandler = new PluginHandler(picgo) @@ -111,11 +111,21 @@ const handlePluginUpdate = (ipcMain, STORE_PATH, CONFIG_PATH) => { }) } +const handleGetPicBedConfig = (ipcMain, CONFIG_PATH) => { + ipcMain.on('getPicBedConfig', (event, type) => { + const picgo = new PicGo(CONFIG_PATH) + const config = handleConfigWithFunction(picgo.helper.uploader.get(type).config(picgo)) + const name = picgo.helper.uploader.get(type).name || type + event.sender.send('getPicBedConfig', config, name) + }) +} + export default (app, ipcMain) => { const STORE_PATH = app.getPath('userData') const CONFIG_PATH = path.join(STORE_PATH, '/data.json') handleGetPluginList(ipcMain, STORE_PATH, CONFIG_PATH) - handlePluginInstall(ipcMain, STORE_PATH, CONFIG_PATH) - handlePluginUninstall(ipcMain, STORE_PATH, CONFIG_PATH) - handlePluginUpdate(ipcMain, STORE_PATH, CONFIG_PATH) + handlePluginInstall(ipcMain, CONFIG_PATH) + handlePluginUninstall(ipcMain, CONFIG_PATH) + handlePluginUpdate(ipcMain, CONFIG_PATH) + handleGetPicBedConfig(ipcMain, CONFIG_PATH) } diff --git a/src/renderer/components/ConfigForm.vue b/src/renderer/components/ConfigForm.vue index bfd9afc..6373bb3 100644 --- a/src/renderer/components/ConfigForm.vue +++ b/src/renderer/components/ConfigForm.vue @@ -27,8 +27,22 @@ > + + + @@ -40,17 +54,21 @@ > + diff --git a/src/renderer/main.js b/src/renderer/main.js index fc96128..9ebbe6f 100644 --- a/src/renderer/main.js +++ b/src/renderer/main.js @@ -8,7 +8,6 @@ import store from './store' import db from '../datastore/index' import { webFrame } from 'electron' import './assets/fonts/iconfont.css' -import picBed from '../datastore/pic-bed' import VueLazyLoad from 'vue-lazyload' Vue.use(ElementUI) @@ -20,7 +19,16 @@ webFrame.setLayoutZoomLevelLimits(0, 0) if (!process.env.IS_WEB) Vue.use(require('vue-electron')) Vue.http = Vue.prototype.$http = axios Vue.prototype.$db = db -Vue.prototype.$picBed = picBed +Vue.prototype.$builtInPicBed = [ + 'smms', + 'weibo', + 'imgur', + 'qiniu', + 'tcyun', + 'upyun', + 'aliyun', + 'github' +] Vue.config.productionTip = false /* eslint-disable no-new */ diff --git a/src/renderer/pages/Gallery.vue b/src/renderer/pages/Gallery.vue index d2b7b33..2c42e79 100644 --- a/src/renderer/pages/Gallery.vue +++ b/src/renderer/pages/Gallery.vue @@ -16,7 +16,7 @@ style="width: 100%" placeholder="请选择显示的图床"> @@ -135,7 +135,8 @@ export default { URL: 'URL', UBB: 'UBB', Custom: 'Custom' - } + }, + picBed: [] } }, created () { @@ -145,7 +146,11 @@ export default { this.filterList = this.getGallery() }) }) + this.$electron.ipcRenderer.on('getPicBeds', (event, picBeds) => { + this.picBed = picBeds + }) this.getPasteStyle() + this.getPicBeds() }, computed: { filterList: { @@ -158,6 +163,9 @@ export default { } }, methods: { + getPicBeds () { + this.$electron.ipcRenderer.send('getPicBeds') + }, getGallery () { if (this.choosedPicBed.length > 0) { let arr = [] @@ -335,6 +343,7 @@ export default { }, beforeDestroy () { this.$electron.ipcRenderer.removeAllListeners('updateGallery') + this.$electron.ipcRenderer.removeAllListeners('getPicBeds') } } diff --git a/src/renderer/pages/MiniPage.vue b/src/renderer/pages/MiniPage.vue index 0503288..c23d7a3 100644 --- a/src/renderer/pages/MiniPage.vue +++ b/src/renderer/pages/MiniPage.vue @@ -17,7 +17,6 @@ diff --git a/src/renderer/pages/Upload.vue b/src/renderer/pages/Upload.vue index b0e08c9..a445549 100644 --- a/src/renderer/pages/Upload.vue +++ b/src/renderer/pages/Upload.vue @@ -3,7 +3,7 @@
- 图片上传 - {{ picBed }} + 图片上传 - {{ picBedName }}
{ this.getDefaultPicBed() }) + this.getPicBeds() + this.$electron.ipcRenderer.on('getPicBeds', (event, picBeds) => { + this.picBed = picBeds + this.getDefaultPicBed() + }) }, watch: { progress (val) { @@ -100,6 +106,7 @@ export default { beforeDestroy () { this.$electron.ipcRenderer.removeAllListeners('uploadProgress') this.$electron.ipcRenderer.removeAllListeners('syncPicBed') + this.$electron.ipcRenderer.removeAllListeners('getPicBeds') }, methods: { onDrop (e) { @@ -136,11 +143,14 @@ export default { }, getDefaultPicBed () { const current = this.$db.read().get('picBed.current').value() - this.$picBed.forEach(item => { + this.picBed.forEach(item => { if (item.type === current) { - this.picBed = item.name + this.picBedName = item.name } }) + }, + getPicBeds () { + this.$electron.ipcRenderer.send('getPicBeds') } } } diff --git a/src/renderer/pages/picbeds/Others.vue b/src/renderer/pages/picbeds/Others.vue index e0d976e..32f4872 100644 --- a/src/renderer/pages/picbeds/Others.vue +++ b/src/renderer/pages/picbeds/Others.vue @@ -3,55 +3,98 @@
- Imgur图床设置 + {{ picBedName }}设置
- - - - - - - + - 确定 + 确定 设为默认图床 - + +
\ No newline at end of file diff --git a/src/renderer/utils/ConfirmButtonMixin.js b/src/renderer/utils/ConfirmButtonMixin.js index 43713c6..81940dd 100644 --- a/src/renderer/utils/ConfirmButtonMixin.js +++ b/src/renderer/utils/ConfirmButtonMixin.js @@ -1,14 +1,13 @@ -import db from '~/datastore' export default { name: '', data () { return { - defaultPicBed: db.read().get('picBed.current').value() + defaultPicBed: this.$db.read().get('picBed.current').value() } }, methods: { setDefaultPicBed (type) { - db.read().set('picBed.current', type).write() + this.$db.read().set('picBed.current', type).write() this.defaultPicBed = type this.$electron.ipcRenderer.send('updateDefaultPicBed', type) const successNotification = new window.Notification('设置默认图床', {