mirror of
https://github.com/pulsar-edit/pulsar.git
synced 2024-11-10 10:17:11 +03:00
Add atom.whenShellEnvironmentLoaded()
This provides a way to be notified when the shell environment has loaded—even if it's already happened.
This commit is contained in:
parent
18ed0f0657
commit
ddd8a8b978
@ -458,6 +458,39 @@ describe "AtomEnvironment", ->
|
||||
atomEnvironment.unloadEditorWindow()
|
||||
atomEnvironment.destroy()
|
||||
|
||||
describe "::whenShellEnvironmentLoaded()", ->
|
||||
[atomEnvironment, envLoaded, spy] = []
|
||||
|
||||
beforeEach ->
|
||||
resolve = null
|
||||
promise = new Promise (r) -> resolve = r
|
||||
envLoaded = ->
|
||||
resolve()
|
||||
waitsForPromise -> promise
|
||||
atomEnvironment = new AtomEnvironment
|
||||
applicationDelegate: atom.applicationDelegate
|
||||
updateProcessEnv: -> promise
|
||||
atomEnvironment.initialize({window, document})
|
||||
spyOn(atomEnvironment.packages, 'getAvailablePackagePaths').andReturn []
|
||||
spyOn(atomEnvironment, 'displayWindow').andReturn Promise.resolve()
|
||||
spy = jasmine.createSpy()
|
||||
atomEnvironment.startEditorWindow()
|
||||
|
||||
afterEach ->
|
||||
atomEnvironment.unloadEditorWindow()
|
||||
atomEnvironment.destroy()
|
||||
|
||||
it "is triggered once the shell environment is loaded", ->
|
||||
atomEnvironment.whenShellEnvironmentLoaded spy
|
||||
envLoaded()
|
||||
runs -> expect(spy).toHaveBeenCalled()
|
||||
|
||||
it "triggers the callback immediately if the shell environment is already loaded", ->
|
||||
envLoaded()
|
||||
runs ->
|
||||
atomEnvironment.whenShellEnvironmentLoaded spy
|
||||
expect(spy).toHaveBeenCalled()
|
||||
|
||||
describe "::openLocations(locations) (called via IPC from browser process)", ->
|
||||
beforeEach ->
|
||||
spyOn(atom.workspace, 'open')
|
||||
|
@ -125,7 +125,7 @@ class AtomEnvironment extends Model
|
||||
|
||||
# Call .loadOrCreate instead
|
||||
constructor: (params={}) ->
|
||||
{@applicationDelegate, @clipboard, @enablePersistence, onlyLoadBaseStyleSheets} = params
|
||||
{@applicationDelegate, @clipboard, @enablePersistence, onlyLoadBaseStyleSheets, @updateProcessEnv} = params
|
||||
|
||||
@nextProxyRequestId = 0
|
||||
@unloaded = false
|
||||
@ -136,6 +136,7 @@ class AtomEnvironment extends Model
|
||||
@deserializeTimings = {}
|
||||
@views = new ViewRegistry(this)
|
||||
@notifications = new NotificationManager
|
||||
@updateProcessEnv ?= updateProcessEnv # For testing
|
||||
|
||||
@stateStore = new StateStore('AtomEnvironments', 1)
|
||||
|
||||
@ -398,6 +399,17 @@ class AtomEnvironment extends Model
|
||||
onDidFailAssertion: (callback) ->
|
||||
@emitter.on 'did-fail-assertion', callback
|
||||
|
||||
# Extended: Invoke the given callback as soon as the shell environment is
|
||||
# loaded (or immediately if it was already loaded).
|
||||
#
|
||||
# * `callback` {Function} to be called whenever there is an unhandled error
|
||||
whenShellEnvironmentLoaded: (callback) ->
|
||||
if @shellEnvironmentLoaded
|
||||
callback()
|
||||
new Disposable()
|
||||
else
|
||||
@emitter.once 'loaded-shell-environment', callback
|
||||
|
||||
###
|
||||
Section: Atom Details
|
||||
###
|
||||
@ -660,8 +672,10 @@ class AtomEnvironment extends Model
|
||||
# Call this method when establishing a real application window.
|
||||
startEditorWindow: ->
|
||||
@unloaded = false
|
||||
updateProcessEnvPromise = updateProcessEnv(@getLoadSettings().env)
|
||||
updateProcessEnvPromise = @updateProcessEnv(@getLoadSettings().env)
|
||||
updateProcessEnvPromise.then =>
|
||||
@shellEnvironmentLoaded = true
|
||||
@emitter.emit('loaded-shell-environment')
|
||||
@packages.triggerActivationHook('core:loaded-shell-environment')
|
||||
|
||||
loadStatePromise = @loadState().then (state) =>
|
||||
|
Loading…
Reference in New Issue
Block a user