Load atom://assets/ urls from ~/.atom/assets

This commit is contained in:
Kevin Sawicki
2014-10-31 10:35:15 -07:00
parent 4e95977fbd
commit 9c1ca86cb0

View File

@@ -5,8 +5,15 @@ protocol = require 'protocol'
# 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.
# It's created by {AtomApplication} upon instantiation and is used to create a
# custom resource loader for 'atom://' URLs.
#
# The following directories are searched in order:
# * ~/.atom/assets
# * ~/.atom/dev/packages
# * ~/.atom/packages
# * RESOURCE_PATH/node_modules
#
module.exports =
class AtomProtocolHandler
constructor: (@resourcePath) ->
@@ -22,7 +29,15 @@ class AtomProtocolHandler
registerAtomProtocol: ->
protocol.registerProtocol 'atom', (request) =>
relativePath = path.normalize(request.url.substr(7))
for loadPath in @loadPaths
filePath = path.join(loadPath, relativePath)
break if fs.statSyncNoException(filePath).isFile?()
return new protocol.RequestFileJob(filePath)
if relativePath.indexOf('assets/') is 0
assetsPath = path.join(app.getHomeDir(), '.atom', relativePath)
if fs.statSyncNoException(assetsPath).isFile?()
filePath = assetsPath
unless filePath
for loadPath in @loadPaths
filePath = path.join(loadPath, relativePath)
break if fs.statSyncNoException(filePath).isFile?()
new protocol.RequestFileJob(filePath)