mirror of
https://github.com/pulsar-edit/pulsar.git
synced 2025-01-01 03:03:09 +03:00
Correctly set NODE_PATH before opening window.
This commit is contained in:
parent
3b87c5d84b
commit
bb114932ea
@ -3,33 +3,77 @@ delegate = require 'atom_delegate'
|
||||
path = require 'path'
|
||||
Window = require 'window'
|
||||
|
||||
resourcePath = path.dirname(__dirname)
|
||||
|
||||
# All opened windows.
|
||||
windows = []
|
||||
|
||||
# Quit when all windows are closed.
|
||||
app.on 'window-all-closed', ->
|
||||
app.quit()
|
||||
|
||||
openWindowWithParams = (pairs) ->
|
||||
win = new Window width: 800, height: 600, show: false, title: 'Atom'
|
||||
class AtomWindow
|
||||
@windows = []
|
||||
|
||||
windows.push win
|
||||
win.on 'destroyed', ->
|
||||
windows.splice windows.indexOf(win), 1
|
||||
constructor: (options) ->
|
||||
{@bootstrapScript, @isDev, @isSpec, @exitWhenDone} = options
|
||||
|
||||
url = "file://#{resourcePath}/static/index.html"
|
||||
separator = '?'
|
||||
for pair in pairs
|
||||
url += "#{separator}#{pair.name}=#{pair.param}"
|
||||
separator = '&' if separator is '?'
|
||||
if @isDev
|
||||
# TODO: read resource-path command parameter
|
||||
else
|
||||
@resourcePath = path.dirname(__dirname)
|
||||
|
||||
win.loadUrl url
|
||||
win.show()
|
||||
@window = @open()
|
||||
|
||||
open: ->
|
||||
params = [
|
||||
{name: 'bootstrapScript', param: @bootstrapScript},
|
||||
{name: 'resourcePath', param: @resourcePath},
|
||||
]
|
||||
params.push {name: 'devMode', param: 1} if @isDev
|
||||
params.push {name: 'exitWhenDone', param: 1} if @exitWhenDone
|
||||
|
||||
@setNodePaths()
|
||||
@openWithParams(params)
|
||||
|
||||
setNodePaths: (isSpec) ->
|
||||
resourcePaths = [
|
||||
'src/stdlib',
|
||||
'src/app',
|
||||
'src/packages',
|
||||
'src',
|
||||
'vendor',
|
||||
'static',
|
||||
'node_modules',
|
||||
]
|
||||
|
||||
if @isSpec
|
||||
resourcePaths = ['benchmark', 'spec'].contat resourcePaths
|
||||
resourcePaths.push 'spec/fixtures/packages'
|
||||
|
||||
homeDir = process.env[if process.platform is 'win32' then 'USERPROFILE' else 'HOME']
|
||||
resourcePaths.push path.join(homeDir, '.atom', 'packages')
|
||||
|
||||
resourcePaths = resourcePaths.map (relativeOrAbsolutePath) =>
|
||||
path.resolve @resourcePath, relativeOrAbsolutePath
|
||||
|
||||
process.env['NODE_PATH'] = resourcePaths.join path.delimiter
|
||||
|
||||
openWithParams: (pairs) ->
|
||||
win = new Window width: 800, height: 600, show: false, title: 'Atom'
|
||||
|
||||
AtomWindow.windows.push win
|
||||
win.on 'destroyed', =>
|
||||
AtomWindow.windows.splice AtomWindow.windows.indexOf(win), 1
|
||||
|
||||
url = "file://#{@resourcePath}/static/index.html"
|
||||
separator = '?'
|
||||
for pair in pairs
|
||||
url += "#{separator}#{pair.name}=#{pair.param}"
|
||||
separator = '&' if separator is '?'
|
||||
|
||||
console.log url
|
||||
win.loadUrl url
|
||||
win.show()
|
||||
|
||||
delegate.browserMainParts.preMainMessageLoopRun = ->
|
||||
openWindowWithParams [
|
||||
{name: 'bootstrapScript', param: 'window-bootstrap'},
|
||||
{name: 'resourcePath', param: resourcePath},
|
||||
]
|
||||
new AtomWindow
|
||||
bootstrapScript: 'window-bootstrap',
|
||||
isDev: false,
|
||||
isSpec: false,
|
||||
exitWhenDone: false
|
||||
|
@ -21,7 +21,8 @@
|
||||
if (bootstrapScript) require(bootstrapScript);
|
||||
}
|
||||
catch (error) {
|
||||
if (atom && atom.showDevTools) { atom.showDevTools(); }
|
||||
var currentWindow = require('remote').getCurrentWindow();
|
||||
currentWindow.openDevTools();
|
||||
console.error(error.stack || error);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user