Added: guiMenu for plugins

This commit is contained in:
PiEgg 2019-01-11 21:13:16 +08:00
parent 927d913f3b
commit a6377696d9
3 changed files with 39 additions and 13 deletions

View File

@ -45,6 +45,10 @@ const handleGetPluginList = (ipcMain, STORE_PATH, CONFIG_PATH) => {
const pluginPKG = requireFunc(path.join(pluginPath, 'package.json'))
const uploaderName = plugin.uploader || ''
const transformerName = plugin.transformer || ''
let menu = []
if (plugin.guiMenu) {
menu = plugin.guiMenu(picgo)
}
const obj = {
name: pluginList[i].replace(/picgo-plugin-/, ''),
author: pluginPKG.author.name || pluginPKG.author,
@ -68,7 +72,7 @@ const handleGetPluginList = (ipcMain, STORE_PATH, CONFIG_PATH) => {
},
enabled: picgo.getConfig(`plugins.${pluginList[i]}`),
homepage: pluginPKG.homepage ? pluginPKG.homepage : '',
guiActions: typeof plugin.guiActions === 'function',
guiMenu: menu,
ing: false
}
list.push(obj)
@ -129,16 +133,28 @@ const handleGetPicBedConfig = (ipcMain, CONFIG_PATH) => {
}
const handlePluginActions = (ipcMain, CONFIG_PATH) => {
ipcMain.on('pluginActions', (event, name) => {
ipcMain.on('pluginActions', (event, name, label) => {
const picgo = new PicGo(CONFIG_PATH)
const plugin = picgo.pluginLoader.getPlugin(`picgo-plugin-${name}`)
const guiApi = new GuiApi(ipcMain, event.sender)
if (plugin.guiActions && typeof plugin.guiActions === 'function') {
plugin.guiActions(picgo, guiApi)
if (plugin.guiMenu && plugin.guiMenu.length > 0) {
const menu = plugin.guiMenu(picgo)
menu.forEach(item => {
if (item.label === label) {
item.handle(picgo, guiApi)
}
})
}
})
}
const handleRemoveFiles = (ipcMain, CONFIG_PATH) => {
ipcMain.on('removeFiles', (event, files) => {
const picgo = new PicGo(CONFIG_PATH)
picgo.emit('remove', files)
})
}
export default (app, ipcMain) => {
const STORE_PATH = app.getPath('userData')
const CONFIG_PATH = path.join(STORE_PATH, '/data.json')
@ -148,4 +164,5 @@ export default (app, ipcMain) => {
handlePluginUpdate(ipcMain, CONFIG_PATH)
handleGetPicBedConfig(ipcMain, CONFIG_PATH)
handlePluginActions(ipcMain, CONFIG_PATH)
handleRemoveFiles(ipcMain, CONFIG_PATH)
}

View File

@ -54,7 +54,7 @@
</div>
</el-col>
<el-col :span="6">
<div class="item-base delete round" :class="{ active: isMultiple(choosedList)}" @click="multiDelete">
<div class="item-base delete round" :class="{ active: isMultiple(choosedList)}" @click="multiRemove">
<i class="el-icon-delete"></i> 批量删除
</div>
</el-col>
@ -229,7 +229,9 @@ export default {
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
const file = this.$db.read().get('uploaded').getById(id).value()
this.$db.read().get('uploaded').removeById(id).write()
this.$electron.ipcRenderer.send('removeFiles', [file])
const obj = {
title: '操作结果',
body: '删除成功'
@ -279,7 +281,7 @@ export default {
isMultiple (obj) {
return Object.values(obj).some(item => item)
},
multiDelete () {
multiRemove () {
// choosedList -> { [id]: true or false }; true means choosed. false means not choosed.
if (Object.values(this.choosedList).some(item => item)) {
this.$confirm('将删除刚才选中的图片,是否继续?', '提示', {
@ -287,8 +289,11 @@ export default {
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
let files = []
Object.keys(this.choosedList).forEach(key => {
if (this.choosedList[key]) {
const file = this.$db.read().get('uploaded').getById(key).value()
files.push(file)
this.$db.read().get('uploaded').removeById(key).write()
}
})
@ -298,6 +303,7 @@ export default {
title: '操作结果',
body: '删除成功'
}
this.$electron.ipcRenderer.send('removeFiles', files)
const myNotification = new window.Notification(obj.title, obj)
myNotification.onclick = () => {
return true

View File

@ -276,13 +276,16 @@ export default {
menu.push(obj)
}
if (plugin.guiActions) {
menu.push({
label: '运行Actions',
click () {
_this.$electron.ipcRenderer.send('pluginActions', plugin.name)
}
})
// plugin custom menus
if (plugin.guiMenu) {
for (let i of plugin.guiMenu) {
menu.push({
label: i.label,
click () {
_this.$electron.ipcRenderer.send('pluginActions', plugin.name, i.label)
}
})
}
}
this.menu = this.$electron.remote.Menu.buildFromTemplate(menu)