Skip to content

Plugin Development

Zack Young edited this page Oct 26, 2016 · 3 revisions

plugin

Plugin for ELaunch is a simple npm package, but exports an object with specific methods below

This is useful is you need to watch something like clipboard. Parameters see init below.

init() [optional]

init(pluginConfig, globalConfig, context)

This method would be called this first time you triggered this plugin by command, or on ELaunch start if the plugin config has initOnStart field set true.

  • pluginConfig is the config merged command config and plugin config in config file
  • globalConfig is the config file plus some useful tool:
globalConfig = {
  dataPath: '~/.ELaunch',
  userConfigFile: '~/.ELaunch/config.js',
  merge(obj1,obj2,obj3...){
    //(func) deeply merge properties in objects, notice it won't merge array
  },
  debug:, //(bool) whether it's running in debug mode
  context: { //(object)
    mainWindow: mainWindow, //the BrowserWindow contains the input box, this could be used to inject js/css to mainWindow, please be careful!!
    notifier: {//notifier is a wrapper for notification runs in both main process and renderer process, it has only one method is `notify(title, options)`, please see [html5 notification](http://devdocs.io/dom/notification)
      notify(title, opts){

      }
    }
  }
}
context = globalConfig.context

exec()

exec(args, event, cmdInfo)

  • args(array): the command args array that not including command key
  • event: event.sender.send() , please see electron docs
  • cmdInfo(object): raw object of command
cmdInfo = {
  key: key,
  script: path.resolve(config.dataPath, plugin.script),
  args: args,
  config: plugin.config || {}
}

return

let items = [{
  name: 'HAHA',
  icon: `${__dirname}/assets/shell.png`,
  value: args.join(' '),// for item.value in execItem, mostly is `args.join(' ')`
  detail: '',
  opts: [{name: 'exec',label: 'Exec'}],//option buttons for item.opt , the first is default
  custom_view: ''// custom html to show in the item list
}]
event.sender.send('exec-reply', items)

execItem()

execItem(item, event)

  • item(object):
item = {
    value: '',//the value of item
    opt: ''//the name of option in item, this could be undefined if no opts in reply of exec method
}
  • event: like event in exec

return

event.sender.send('exec-item-reply')//this would cause the mainWindow to hide

Demos

You can see more demos in built-in plugins

Clone this wiki locally