mirror of
https://github.com/pulsar-edit/pulsar.git
synced 2024-11-13 08:44:12 +03:00
Watch the core.disabledPackages config option
This commit is contained in:
parent
e8b50755cb
commit
7b1b73e8eb
@ -367,3 +367,34 @@ describe "the `atom` global", ->
|
||||
activatedPackages = atom.packages.getActivePackages()
|
||||
expect(activatedPackages.length).toBeGreaterThan 0
|
||||
expect(pack.isTheme()).toBeFalsy() for pack in activatedPackages
|
||||
|
||||
describe ".enablePackage()", ->
|
||||
it "enables a disabled package", ->
|
||||
packageName = 'package-with-main'
|
||||
atom.config.pushAtKeyPath('core.disabledPackages', packageName)
|
||||
|
||||
atom.packages.observeDisabledPackages()
|
||||
|
||||
expect(config.get('core.disabledPackages')).toContain packageName
|
||||
|
||||
pack = atom.packages.enablePackage(packageName)
|
||||
|
||||
loadedPackages = atom.packages.getLoadedPackages()
|
||||
activatedPackages = atom.packages.getActivePackages()
|
||||
expect(loadedPackages).toContain(pack)
|
||||
expect(activatedPackages).toContain(pack)
|
||||
expect(config.get('core.disabledPackages')).not.toContain packageName
|
||||
|
||||
it "enables a disabled theme", ->
|
||||
packageName = 'theme-with-package-file'
|
||||
expect(config.get('core.themes')).not.toContain packageName
|
||||
expect(config.get('core.disabledPackages')).not.toContain packageName
|
||||
|
||||
pack = atom.packages.enablePackage(packageName)
|
||||
|
||||
loadedPackages = atom.packages.getLoadedPackages()
|
||||
activatedPackages = atom.packages.getLoadedPackages()
|
||||
expect(loadedPackages).toContain(pack)
|
||||
expect(activatedPackages).toContain(pack)
|
||||
expect(config.get('core.themes')).toContain packageName
|
||||
expect(config.get('core.disabledPackages')).not.toContain packageName
|
||||
|
@ -31,6 +31,7 @@ class PackageManager
|
||||
@loadedPackages = {}
|
||||
@activePackages = {}
|
||||
@packageStates = {}
|
||||
@observingDisabledPackages = false
|
||||
|
||||
getPackageState: (name) ->
|
||||
@packageStates[name]
|
||||
@ -41,15 +42,18 @@ class PackageManager
|
||||
enablePackage: (name) ->
|
||||
pack = @loadPackage(name)
|
||||
pack?.enable()
|
||||
pack
|
||||
|
||||
disablePackage: (name) ->
|
||||
pack = @loadPackage(name)
|
||||
pack?.disable()
|
||||
pack
|
||||
|
||||
activatePackages: ->
|
||||
# ThemeManager handles themes. Only activate non theme packages
|
||||
# This is the only part I dislike
|
||||
@activatePackage(pack.name) for pack in @getLoadedPackages() when not pack.isTheme()
|
||||
@observeDisabledPackages()
|
||||
|
||||
activatePackage: (name, options) ->
|
||||
return pack if pack = @getActivePackage(name)
|
||||
@ -60,6 +64,7 @@ class PackageManager
|
||||
|
||||
deactivatePackages: ->
|
||||
@deactivatePackage(pack.name) for pack in @getActivePackages()
|
||||
@unobserveDisabledPackages()
|
||||
|
||||
deactivatePackage: (name) ->
|
||||
if pack = @getActivePackage(name)
|
||||
@ -78,6 +83,28 @@ class PackageManager
|
||||
isPackageActive: (name) ->
|
||||
@getActivePackage(name)?
|
||||
|
||||
unobserveDisabledPackages: ->
|
||||
return unless @observingDisabledPackages
|
||||
config.unobserve('core.disabledPackages')
|
||||
@observingDisabledPackages = false
|
||||
|
||||
observeDisabledPackages: ->
|
||||
return if @observingDisabledPackages
|
||||
|
||||
config.observe 'core.disabledPackages', callNow: false, (disabledPackages, {previous}) =>
|
||||
packagesToEnable = _.difference(previous, disabledPackages)
|
||||
packagesToDisable = _.difference(disabledPackages, previous)
|
||||
|
||||
console.log previous, disabledPackages
|
||||
console.log packagesToDisable
|
||||
console.log packagesToEnable
|
||||
|
||||
@deactivatePackage(packageName) for packageName in packagesToDisable when @getActivePackage(packageName)
|
||||
@activatePackage(packageName) for packageName in packagesToEnable
|
||||
null
|
||||
|
||||
@observingDisabledPackages = true
|
||||
|
||||
loadPackages: ->
|
||||
# Ensure atom exports is already in the require cache so the load time
|
||||
# of the first package isn't skewed by being the first to require atom
|
||||
@ -87,9 +114,6 @@ class PackageManager
|
||||
@emit 'loaded'
|
||||
|
||||
loadPackage: (name, options) ->
|
||||
if @isPackageDisabled(name)
|
||||
return console.warn("Tried to load disabled package '#{name}'")
|
||||
|
||||
if packagePath = @resolvePackagePath(name)
|
||||
return pack if pack = @getLoadedPackage(name)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user