mirror of
https://github.com/atom/atom.git
synced 2026-01-23 13:58:08 -05:00
Packages may be linked into ~/.atom/packages or ~/.atom/dev/packages so the resource should be loaded from there when available.
29 lines
959 B
CoffeeScript
29 lines
959 B
CoffeeScript
app = require 'app'
|
|
fs = require 'fs-plus'
|
|
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) ->
|
|
@loadPaths = [
|
|
path.join(app.getHomeDir(), '.atom', 'dev', 'packages')
|
|
path.join(app.getHomeDir(), '.atom', 'packages')
|
|
path.join(@resourcePath, 'node_modules')
|
|
]
|
|
|
|
@registerAtomProtocol()
|
|
|
|
# Private: Creates the 'atom' custom protocol handler.
|
|
registerAtomProtocol: ->
|
|
protocol.registerProtocol 'atom', (request) =>
|
|
relativePath = path.normalize(request.url.substr(7))
|
|
for loadPath in @loadPaths
|
|
filePath = path.join(loadPath, relativePath)
|
|
break if fs.isFileSync(filePath)
|
|
return new protocol.RequestFileJob(filePath)
|