diff --git a/src/atom-application.coffee b/src/atom-application.coffee index 54f2fa92b..507baccfc 100644 --- a/src/atom-application.coffee +++ b/src/atom-application.coffee @@ -1,5 +1,6 @@ AtomWindow = require 'atom-window' ApplicationMenu = require 'application-menu' +AtomProtocolHandler = require 'atom-protocol-handler' BrowserWindow = require 'browser-window' Menu = require 'menu' autoUpdater = require 'auto-updater' @@ -45,6 +46,7 @@ class AtomApplication windows: null applicationMenu: null + atomProtocolHandler: null resourcePath: null version: null @@ -56,6 +58,7 @@ class AtomApplication @windows = [] @applicationMenu = new ApplicationMenu(@version, devMode) + @atomProtocolHandler = new AtomProtocolHandler(@resourcePath) @listenForArgumentsFromNewProcess() @setupJavaScriptArguments() diff --git a/src/atom-protocol-handler.coffee b/src/atom-protocol-handler.coffee new file mode 100644 index 000000000..e8fde85f1 --- /dev/null +++ b/src/atom-protocol-handler.coffee @@ -0,0 +1,18 @@ +path = require 'path' +protocol = require 'protocol' + +# Private: Handles requests with 'atom' protocol. +# +# It's created by {AtomApplication} upon instantiation, and is used to create a +# custom resource loader by adding the 'atom' custom protocol. +module.exports = +class AtomProtocolHandler + constructor: (@resourcePath) -> + @registerAtomProtocol() + + # Private: Creates the 'atom' custom protocol handler. + registerAtomProtocol: -> + protocol.registerProtocol 'atom', (request) => + relativePath = path.normalize(request.url.substr(7)) + filePath = path.join(@resourcePath, 'node_modules', relativePath) + return new protocol.RequestFileJob(filePath)