From e6deb83440e77484fe0c27f6b2ee69f17ca1d02a Mon Sep 17 00:00:00 2001 From: Evan Morikawa Date: Thu, 18 Aug 2016 11:42:28 -0700 Subject: [PATCH] feat(plugins): plugins now properly report which are active on change --- build/tasks/set-version-task.coffee | 3 +++ src/flux/actions.coffee | 2 ++ src/package-manager.coffee | 38 +++++++++++++++++++++++++++++ src/pro | 2 +- 4 files changed, 44 insertions(+), 1 deletion(-) diff --git a/build/tasks/set-version-task.coffee b/build/tasks/set-version-task.coffee index 9af1da363..709010003 100644 --- a/build/tasks/set-version-task.coffee +++ b/build/tasks/set-version-task.coffee @@ -12,6 +12,9 @@ module.exports = (grunt) -> if onBuildMachine or onWindows or not inRepository callback(null, version) else + # NOTE: We need to attach the commit hash to the version so it will match + # properly with the S3 bucket we're supposed to download new releases + # from. cmd = 'git' args = ['rev-parse', '--short', 'HEAD'] spawn {cmd, args}, (error, {stdout}={}, code) -> diff --git a/src/flux/actions.coffee b/src/flux/actions.coffee index 4e3afc4b6..6f0395159 100644 --- a/src/flux/actions.coffee +++ b/src/flux/actions.coffee @@ -554,6 +554,8 @@ class Actions @selectSignature: ActionScopeWindow @toggleAccount: ActionScopeWindow + @notifyPluginsChanged: ActionScopeGlobal + # Read the actions we declared on the dummy Actions object above # and translate them into Reflux Actions diff --git a/src/package-manager.coffee b/src/package-manager.coffee index c8af90af5..52f56d36e 100644 --- a/src/package-manager.coffee +++ b/src/package-manager.coffee @@ -7,6 +7,7 @@ EmitterMixin = require('emissary').Emitter fs = require 'fs-plus' Q = require 'q' +Actions = require './flux/actions' Package = require './package' ThemePackage = require './theme-package' DatabaseStore = require './flux/stores/database-store' @@ -37,6 +38,7 @@ class PackageManager constructor: ({configDirPath, @devMode, safeMode, @resourcePath, @specMode}) -> @emitter = new Emitter + @onPluginsChanged = _.debounce(@_onPluginsChanged, 200) @packageDirPaths = [] if @specMode @packageDirPaths.push(path.join(@resourcePath, "spec", "fixtures", "packages")) @@ -422,6 +424,38 @@ class PackageManager null + # This lets us report the active plugins in the main window (since plugins + # are window-specific). Useful for letting the worker window know what + # plugins are installed in the main window. + _onPluginsChanged: => + return unless NylasEnv.isMainWindow() + # All active plugins, core optional, core required, and 3rd party + activePluginNames = @getActivePackages().map((p) -> p.name) + + # Only active 3rd party plugins + activeThirdPartyPluginNames = @getActivePackages().filter((p) -> + (p.path?.indexOf('internal_packages') is -1 and + p.path?.indexOf('nylas-private') is -1) + ).map((p) -> p.name) + + # Only active core optional, and core required plugins + activeCorePluginNames = _.difference(activePluginNames, activeThirdPartyPluginNames) + + # All plugins (3rd party and core optional) that have the {optional: true} + # flag. If it's an internal_packages core package, it'll show up in + # preferences. + optionalPluginNames = @getAvailablePackageMetadata() + .filter(({isOptional}) -> isOptional) + .map((p) -> p.name) + + activeCoreOptionalPluginNames = _.intersection(activeCorePluginNames, optionalPluginNames) + + Actions.notifyPluginsChanged({ + allActivePluginNames: activePluginNames + coreActivePluginNames: activeCoreOptionalPluginNames + thirdPartyActivePluginNames: activeThirdPartyPluginNames + }) + # If a windowType is passed, we'll only load packages who declare that # windowType as `true` in their package.json file. loadPackages: (windowType) -> @@ -451,6 +485,7 @@ class PackageManager @packagesWithDatabaseObjects.push pack @loadedPackages[pack.name] = pack @emitter.emit 'did-load-package', pack + @onPluginsChanged() return pack catch error console.warn "Failed to load package.json '#{path.basename(packagePath)}'" @@ -470,6 +505,7 @@ class PackageManager if pack = @getLoadedPackage(name) delete @loadedPackages[pack.name] @emitter.emit 'did-unload-package', pack + @onPluginsChanged() else throw new Error("No loaded package for name '#{name}'") @@ -522,6 +558,7 @@ class PackageManager pack.activate().then => @activePackages[pack.name] = pack @emitter.emit 'did-activate-package', pack + @onPluginsChanged() pack else Q.reject(new Error("Failed to load package '#{name}'")) @@ -540,3 +577,4 @@ class PackageManager pack.deactivate() delete @activePackages[pack.name] @emitter.emit 'did-deactivate-package', pack + @onPluginsChanged() diff --git a/src/pro b/src/pro index acb4d558b..1975def19 160000 --- a/src/pro +++ b/src/pro @@ -1 +1 @@ -Subproject commit acb4d558b58b2e1ba0348ac351ff23bb41dffc4b +Subproject commit 1975def1985c26eee6a9df27e1558a4d03d796ba