mirror of
https://github.com/Kuingsmile/PicList.git
synced 2025-01-23 06:38:13 -05:00
Added: guiMenu for plugins
This commit is contained in:
parent
927d913f3b
commit
a6377696d9
@ -45,6 +45,10 @@ const handleGetPluginList = (ipcMain, STORE_PATH, CONFIG_PATH) => {
|
|||||||
const pluginPKG = requireFunc(path.join(pluginPath, 'package.json'))
|
const pluginPKG = requireFunc(path.join(pluginPath, 'package.json'))
|
||||||
const uploaderName = plugin.uploader || ''
|
const uploaderName = plugin.uploader || ''
|
||||||
const transformerName = plugin.transformer || ''
|
const transformerName = plugin.transformer || ''
|
||||||
|
let menu = []
|
||||||
|
if (plugin.guiMenu) {
|
||||||
|
menu = plugin.guiMenu(picgo)
|
||||||
|
}
|
||||||
const obj = {
|
const obj = {
|
||||||
name: pluginList[i].replace(/picgo-plugin-/, ''),
|
name: pluginList[i].replace(/picgo-plugin-/, ''),
|
||||||
author: pluginPKG.author.name || pluginPKG.author,
|
author: pluginPKG.author.name || pluginPKG.author,
|
||||||
@ -68,7 +72,7 @@ const handleGetPluginList = (ipcMain, STORE_PATH, CONFIG_PATH) => {
|
|||||||
},
|
},
|
||||||
enabled: picgo.getConfig(`plugins.${pluginList[i]}`),
|
enabled: picgo.getConfig(`plugins.${pluginList[i]}`),
|
||||||
homepage: pluginPKG.homepage ? pluginPKG.homepage : '',
|
homepage: pluginPKG.homepage ? pluginPKG.homepage : '',
|
||||||
guiActions: typeof plugin.guiActions === 'function',
|
guiMenu: menu,
|
||||||
ing: false
|
ing: false
|
||||||
}
|
}
|
||||||
list.push(obj)
|
list.push(obj)
|
||||||
@ -129,16 +133,28 @@ const handleGetPicBedConfig = (ipcMain, CONFIG_PATH) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const handlePluginActions = (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 picgo = new PicGo(CONFIG_PATH)
|
||||||
const plugin = picgo.pluginLoader.getPlugin(`picgo-plugin-${name}`)
|
const plugin = picgo.pluginLoader.getPlugin(`picgo-plugin-${name}`)
|
||||||
const guiApi = new GuiApi(ipcMain, event.sender)
|
const guiApi = new GuiApi(ipcMain, event.sender)
|
||||||
if (plugin.guiActions && typeof plugin.guiActions === 'function') {
|
if (plugin.guiMenu && plugin.guiMenu.length > 0) {
|
||||||
plugin.guiActions(picgo, guiApi)
|
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) => {
|
export default (app, ipcMain) => {
|
||||||
const STORE_PATH = app.getPath('userData')
|
const STORE_PATH = app.getPath('userData')
|
||||||
const CONFIG_PATH = path.join(STORE_PATH, '/data.json')
|
const CONFIG_PATH = path.join(STORE_PATH, '/data.json')
|
||||||
@ -148,4 +164,5 @@ export default (app, ipcMain) => {
|
|||||||
handlePluginUpdate(ipcMain, CONFIG_PATH)
|
handlePluginUpdate(ipcMain, CONFIG_PATH)
|
||||||
handleGetPicBedConfig(ipcMain, CONFIG_PATH)
|
handleGetPicBedConfig(ipcMain, CONFIG_PATH)
|
||||||
handlePluginActions(ipcMain, CONFIG_PATH)
|
handlePluginActions(ipcMain, CONFIG_PATH)
|
||||||
|
handleRemoveFiles(ipcMain, CONFIG_PATH)
|
||||||
}
|
}
|
||||||
|
@ -54,7 +54,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</el-col>
|
</el-col>
|
||||||
<el-col :span="6">
|
<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> 批量删除
|
<i class="el-icon-delete"></i> 批量删除
|
||||||
</div>
|
</div>
|
||||||
</el-col>
|
</el-col>
|
||||||
@ -229,7 +229,9 @@ export default {
|
|||||||
cancelButtonText: '取消',
|
cancelButtonText: '取消',
|
||||||
type: 'warning'
|
type: 'warning'
|
||||||
}).then(() => {
|
}).then(() => {
|
||||||
|
const file = this.$db.read().get('uploaded').getById(id).value()
|
||||||
this.$db.read().get('uploaded').removeById(id).write()
|
this.$db.read().get('uploaded').removeById(id).write()
|
||||||
|
this.$electron.ipcRenderer.send('removeFiles', [file])
|
||||||
const obj = {
|
const obj = {
|
||||||
title: '操作结果',
|
title: '操作结果',
|
||||||
body: '删除成功'
|
body: '删除成功'
|
||||||
@ -279,7 +281,7 @@ export default {
|
|||||||
isMultiple (obj) {
|
isMultiple (obj) {
|
||||||
return Object.values(obj).some(item => item)
|
return Object.values(obj).some(item => item)
|
||||||
},
|
},
|
||||||
multiDelete () {
|
multiRemove () {
|
||||||
// choosedList -> { [id]: true or false }; true means choosed. false means not choosed.
|
// choosedList -> { [id]: true or false }; true means choosed. false means not choosed.
|
||||||
if (Object.values(this.choosedList).some(item => item)) {
|
if (Object.values(this.choosedList).some(item => item)) {
|
||||||
this.$confirm('将删除刚才选中的图片,是否继续?', '提示', {
|
this.$confirm('将删除刚才选中的图片,是否继续?', '提示', {
|
||||||
@ -287,8 +289,11 @@ export default {
|
|||||||
cancelButtonText: '取消',
|
cancelButtonText: '取消',
|
||||||
type: 'warning'
|
type: 'warning'
|
||||||
}).then(() => {
|
}).then(() => {
|
||||||
|
let files = []
|
||||||
Object.keys(this.choosedList).forEach(key => {
|
Object.keys(this.choosedList).forEach(key => {
|
||||||
if (this.choosedList[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()
|
this.$db.read().get('uploaded').removeById(key).write()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@ -298,6 +303,7 @@ export default {
|
|||||||
title: '操作结果',
|
title: '操作结果',
|
||||||
body: '删除成功'
|
body: '删除成功'
|
||||||
}
|
}
|
||||||
|
this.$electron.ipcRenderer.send('removeFiles', files)
|
||||||
const myNotification = new window.Notification(obj.title, obj)
|
const myNotification = new window.Notification(obj.title, obj)
|
||||||
myNotification.onclick = () => {
|
myNotification.onclick = () => {
|
||||||
return true
|
return true
|
||||||
|
@ -276,13 +276,16 @@ export default {
|
|||||||
menu.push(obj)
|
menu.push(obj)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (plugin.guiActions) {
|
// plugin custom menus
|
||||||
menu.push({
|
if (plugin.guiMenu) {
|
||||||
label: '运行Actions',
|
for (let i of plugin.guiMenu) {
|
||||||
click () {
|
menu.push({
|
||||||
_this.$electron.ipcRenderer.send('pluginActions', plugin.name)
|
label: i.label,
|
||||||
}
|
click () {
|
||||||
})
|
_this.$electron.ipcRenderer.send('pluginActions', plugin.name, i.label)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.menu = this.$electron.remote.Menu.buildFromTemplate(menu)
|
this.menu = this.$electron.remote.Menu.buildFromTemplate(menu)
|
||||||
|
Loading…
Reference in New Issue
Block a user