feat(plugin): activate & deactivate plugins via a nylas: url

This commit is contained in:
Evan Morikawa 2016-11-05 11:23:14 -07:00
parent dbc81a87a4
commit 9ec3daff0a
2 changed files with 12 additions and 1 deletions

View file

@ -707,6 +707,8 @@ export default class Application extends EventEmitter {
} else if (parts.protocol === 'nylas:') {
if (parts.host === 'calendar') {
this.openCalendarURL(parts.path);
} else if (parts.host === 'plugins') {
main.sendMessage('changePluginStateFromUrl', urlToOpen);
} else {
main.sendMessage('openExternalThread', urlToOpen);
}

View file

@ -1,7 +1,8 @@
path = require 'path'
url = require 'url'
_ = require 'underscore'
{remote} = require 'electron'
{ipcRenderer, remote} = require 'electron'
EmitterMixin = require('emissary').Emitter
{Emitter} = require 'event-kit'
fs = require 'fs-plus'
@ -58,6 +59,8 @@ class PackageManager
@packageActivators = []
@registerPackageActivator(this, ['nylas'])
ipcRenderer.on("changePluginStateFromUrl", @_onChangePluginState)
pluginIdFor: (packageName) =>
env = NylasEnv.config.get("env")
@ -67,6 +70,12 @@ class PackageManager
@cachedPackagePluginIds[cacheKey] = @_resolvePluginIdFor(packageName, env)
return @cachedPackagePluginIds[cacheKey]
_onChangePluginState: (event, urlToOpen = "") =>
{query} = url.parse(urlToOpen, true)
for name, state of query
if state is "off" then @deactivatePackage(name)
else if state is "on" then @activatePackage(name)
_resolvePluginIdFor: (packageName, env) =>
metadata = @loadedPackages[packageName]?.metadata