Added: ctx for guiApi

This commit is contained in:
PiEgg 2019-01-12 13:47:44 +08:00
parent 86265ee5c5
commit 960e01f17f
4 changed files with 11 additions and 5 deletions

View File

@ -9,11 +9,13 @@ import Uploader from './uploader'
import pasteTemplate from './pasteTemplate' import pasteTemplate from './pasteTemplate'
const WEBCONTENTS = Symbol('WEBCONTENTS') const WEBCONTENTS = Symbol('WEBCONTENTS')
const IPCMAIN = Symbol('IPCMAIN') const IPCMAIN = Symbol('IPCMAIN')
const PICGO = Symbol('PICGO')
class GuiApi { class GuiApi {
constructor (ipcMain, webcontents) { constructor (ipcMain, webcontents, picgo) {
this[WEBCONTENTS] = webcontents this[WEBCONTENTS] = webcontents
this[IPCMAIN] = ipcMain this[IPCMAIN] = ipcMain
this[PICGO] = picgo
} }
/** /**
@ -56,7 +58,7 @@ class GuiApi {
* @param {array} input * @param {array} input
*/ */
async upload (input) { async upload (input) {
const imgs = await new Uploader(input, this[WEBCONTENTS]).upload() const imgs = await new Uploader(input, this[WEBCONTENTS], this[PICGO]).upload()
if (imgs !== false) { if (imgs !== false) {
const pasteStyle = db.read().get('settings.pasteStyle').value() || 'markdown' const pasteStyle = db.read().get('settings.pasteStyle').value() || 'markdown'
let pasteText = '' let pasteText = ''

View File

@ -136,7 +136,7 @@ const handlePluginActions = (ipcMain, CONFIG_PATH) => {
ipcMain.on('pluginActions', (event, name, label) => { 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, picgo)
if (plugin.guiMenu && plugin.guiMenu.length > 0) { if (plugin.guiMenu && plugin.guiMenu.length > 0) {
const menu = plugin.guiMenu(picgo) const menu = plugin.guiMenu(picgo)
menu.forEach(item => { menu.forEach(item => {

View File

@ -75,14 +75,15 @@ const waitForRename = (window, id) => {
} }
class Uploader { class Uploader {
constructor (img, webContents) { constructor (img, webContents, picgo = undefined) {
this.img = img this.img = img
this.webContents = webContents this.webContents = webContents
this.picgo = picgo
} }
upload () { upload () {
const win = BrowserWindow.fromWebContents(this.webContents) const win = BrowserWindow.fromWebContents(this.webContents)
const picgo = new PicGo(CONFIG_PATH) const picgo = this.picgo || new PicGo(CONFIG_PATH)
picgo.config.debug = true picgo.config.debug = true
// for picgo-core // for picgo-core
picgo.config.PICGO_ENV = 'GUI' picgo.config.PICGO_ENV = 'GUI'

View File

@ -278,6 +278,9 @@ export default {
// plugin custom menus // plugin custom menus
if (plugin.guiMenu) { if (plugin.guiMenu) {
menu.push({
type: 'separator'
})
for (let i of plugin.guiMenu) { for (let i of plugin.guiMenu) {
menu.push({ menu.push({
label: i.label, label: i.label,