From 2393bd0e9e7838ebe0a2bf399aa33f572d5e8944 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Thu, 24 Jan 2013 11:58:40 -0800 Subject: [PATCH] Create task shell that bootstraps worker --- .../snippets/src/snippets-reader.coffee | 64 +++++++------------ src/stdlib/task-shell.coffee | 21 ++++++ src/stdlib/task.coffee | 6 +- src/window-bootstrap.coffee | 2 + 4 files changed, 48 insertions(+), 45 deletions(-) create mode 100644 src/stdlib/task-shell.coffee diff --git a/src/packages/snippets/src/snippets-reader.coffee b/src/packages/snippets/src/snippets-reader.coffee index b5469c0fd..83ee59aa3 100644 --- a/src/packages/snippets/src/snippets-reader.coffee +++ b/src/packages/snippets/src/snippets-reader.coffee @@ -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 diff --git a/src/stdlib/task-shell.coffee b/src/stdlib/task-shell.coffee new file mode 100644 index 000000000..562a2773c --- /dev/null +++ b/src/stdlib/task-shell.coffee @@ -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) diff --git a/src/stdlib/task.coffee b/src/stdlib/task.coffee index 8abea562a..c393fb1b2 100644 --- a/src/stdlib/task.coffee +++ b/src/stdlib/task.coffee @@ -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 diff --git a/src/window-bootstrap.coffee b/src/window-bootstrap.coffee index fa815e832..cca57c7d7 100644 --- a/src/window-bootstrap.coffee +++ b/src/window-bootstrap.coffee @@ -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}"