mirror of
https://github.com/Kuingsmile/PicList.git
synced 2026-06-03 14:50:57 +08:00
Finished: other picbed page
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
26
src/main/utils/getPicBeds.js
Normal file
26
src/main/utils/getPicBeds.js
Normal file
@@ -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
|
||||
}
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user