Skip to content

Commit

Permalink
Added: guiMenu for plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
Molunerfinn committed Jan 11, 2019
1 parent 927d913 commit a637769
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 13 deletions.
25 changes: 21 additions & 4 deletions src/main/utils/picgoCoreIPC.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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)
Expand Down Expand Up @@ -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')
Expand All @@ -148,4 +164,5 @@ export default (app, ipcMain) => {
handlePluginUpdate(ipcMain, CONFIG_PATH)
handleGetPicBedConfig(ipcMain, CONFIG_PATH)
handlePluginActions(ipcMain, CONFIG_PATH)
handleRemoveFiles(ipcMain, CONFIG_PATH)
}
10 changes: 8 additions & 2 deletions src/renderer/pages/Gallery.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -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: '删除成功'
Expand Down Expand Up @@ -279,16 +281,19 @@ 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('将删除刚才选中的图片,是否继续?', '提示', {
confirmButtonText: '确定',
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()
}
})
Expand All @@ -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
Expand Down
17 changes: 10 additions & 7 deletions src/renderer/pages/Plugin.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit a637769

Please sign in to comment.