Create task shell that bootstraps worker

This commit is contained in:
Kevin Sawicki
2013-01-24 11:58:40 -08:00
parent 9ab730b3d0
commit 2393bd0e9e
4 changed files with 48 additions and 45 deletions

View File

@@ -1,43 +1,23 @@
eval("window = {};")
eval("console = {};")
console.warn = ->
self.postMessage
type: 'warn'
details: arguments
console.log = ->
self.postMessage
type: 'warn'
details: arguments
eval("attachEvent = function(){};")
module.exports =
loadTextmateSnippets: ({path}) ->
fs = require 'fs'
snippetsDirPath = fs.join(path, 'Snippets')
snippets = fs.list(snippetsDirPath).map (snippetPath) ->
fs.readPlist(snippetPath)
self.postMessage
type: 'loadSnippets'
snippets: snippets
self.addEventListener 'message', (event) ->
switch event.data.type
when 'start'
window.resourcePath = event.data.resourcePath
importScripts(event.data.requirePath)
self.postMessage(type:'started')
else
self[event.data.type](event.data)
self.loadTextmateSnippets = ({path}) ->
fs = require 'fs'
snippetsDirPath = fs.join(path, 'Snippets')
snippets = fs.list(snippetsDirPath).map (snippetPath) ->
fs.readPlist(snippetPath)
self.postMessage
type: 'loadSnippets'
snippets: snippets
self.loadAtomSnippets = ({path}) ->
fs = require 'fs'
snippetsDirPath = fs.join(path, 'snippets')
snippets = []
for snippetsPath in fs.list(snippetsDirPath)
continue if fs.base(snippetsPath).indexOf('.') is 0
try
snippets.push(fs.readObject(snippetsPath))
catch e
console.warn "Error reading snippets file '#{snippetsPath}'"
self.postMessage
type: 'loadSnippets'
snippets: snippets
loadAtomSnippets: ({path}) ->
fs = require 'fs'
snippetsDirPath = fs.join(path, 'snippets')
snippets = []
for snippetsPath in fs.list(snippetsDirPath)
continue if fs.base(snippetsPath).indexOf('.') is 0
try
snippets.push(fs.readObject(snippetsPath))
catch e
console.warn "Error reading snippets file '#{snippetsPath}'"
self.postMessage
type: 'loadSnippets'
snippets: snippets

View File

@@ -0,0 +1,21 @@
eval("window = {};")
eval("attachEvent = function(){};")
eval("console = {};")
console.warn = ->
self.postMessage
type: 'warn'
details: arguments
console.log = ->
self.postMessage
type: 'warn'
details: arguments
self.addEventListener 'message', (event) ->
switch event.data.type
when 'start'
window.resourcePath = event.data.resourcePath
importScripts(event.data.requirePath)
self.task = require(event.data.taskPath)
self.postMessage(type:'started')
else
self.task[event.data.type](event.data)

View File

@@ -1,13 +1,12 @@
module.exports =
class Task
constructor: (path) ->
@path = require.getPath(path)
constructor: (@path) ->
onProgress: (event) ->
start: ->
worker = new Worker(@path)
worker = new Worker(require.getPath('task-shell'))
worker.onmessage = (event) =>
switch event.data.type
when 'warn'
@@ -24,3 +23,4 @@ class Task
type: 'start'
resourcePath: window.resourcePath
requirePath: require.getPath('require')
taskPath: @path

View File

@@ -1,7 +1,9 @@
# Like sands through the hourglass, so are the days of our lives.
date = new Date().getTime()
require 'atom'
require 'window'
pathToOpen = atom.getWindowState('pathToOpen') ? window.location.params.pathToOpen
window.attachRootView(pathToOpen)
atom.show()
console.log "Load time: #{new Date().getTime() - date}"