diff --git a/src/main/utils/picgoCoreIPC.js b/src/main/utils/picgoCoreIPC.js index 43275f6..a47256f 100644 --- a/src/main/utils/picgoCoreIPC.js +++ b/src/main/utils/picgoCoreIPC.js @@ -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) } diff --git a/src/renderer/pages/Gallery.vue b/src/renderer/pages/Gallery.vue index b3dcdda..9732e9f 100644 --- a/src/renderer/pages/Gallery.vue +++ b/src/renderer/pages/Gallery.vue @@ -54,7 +54,7 @@ -
+
批量删除
@@ -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 diff --git a/src/renderer/pages/Plugin.vue b/src/renderer/pages/Plugin.vue index 42c5481..e8d741e 100644 --- a/src/renderer/pages/Plugin.vue +++ b/src/renderer/pages/Plugin.vue @@ -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)