From 9c1ca86cb06531f01ca626bba784af7ddb23e8e6 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Fri, 31 Oct 2014 10:35:15 -0700 Subject: [PATCH 1/5] Load atom://assets/ urls from ~/.atom/assets --- src/browser/atom-protocol-handler.coffee | 27 ++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/src/browser/atom-protocol-handler.coffee b/src/browser/atom-protocol-handler.coffee index 6777a21ee..50d5298b7 100644 --- a/src/browser/atom-protocol-handler.coffee +++ b/src/browser/atom-protocol-handler.coffee @@ -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) From afdb96e1b190521fb6d292ea71ab7f054222c5b2 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Fri, 31 Oct 2014 10:42:27 -0700 Subject: [PATCH 2/5] Don't load from ~/.atom/dev when in safe mode --- src/browser/atom-application.coffee | 2 +- src/browser/atom-protocol-handler.coffee | 16 +++++++++------- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/browser/atom-application.coffee b/src/browser/atom-application.coffee index 8e1f66ec0..402a3f3ed 100644 --- a/src/browser/atom-application.coffee +++ b/src/browser/atom-application.coffee @@ -70,7 +70,7 @@ class AtomApplication @autoUpdateManager = new AutoUpdateManager(@version) @applicationMenu = new ApplicationMenu(@version) - @atomProtocolHandler = new AtomProtocolHandler(@resourcePath) + @atomProtocolHandler = new AtomProtocolHandler(@resourcePath, @safeMode) @listenForArgumentsFromNewProcess() @setupJavaScriptArguments() diff --git a/src/browser/atom-protocol-handler.coffee b/src/browser/atom-protocol-handler.coffee index 50d5298b7..c1acedda5 100644 --- a/src/browser/atom-protocol-handler.coffee +++ b/src/browser/atom-protocol-handler.coffee @@ -10,18 +10,20 @@ protocol = require 'protocol' # # The following directories are searched in order: # * ~/.atom/assets -# * ~/.atom/dev/packages +# * ~/.atom/dev/packages (unless in safe mode) # * ~/.atom/packages # * RESOURCE_PATH/node_modules # 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') - ] + constructor: (@resourcePath, safeMode) -> + @loadPaths = [] + + unless safeMode + @loadPaths.push(path.join(app.getHomeDir(), '.atom', 'dev', 'packages')) + + @loadPaths.push(path.join(app.getHomeDir(), '.atom', 'packages')) + @loadPaths.push(path.join(@resourcePath, 'node_modules')) @registerAtomProtocol() From 6d8b891b652fc1acac5e0137633daceffa992557 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Fri, 31 Oct 2014 10:43:07 -0700 Subject: [PATCH 3/5] :lipstick: --- src/browser/atom-protocol-handler.coffee | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/browser/atom-protocol-handler.coffee b/src/browser/atom-protocol-handler.coffee index c1acedda5..faa051b36 100644 --- a/src/browser/atom-protocol-handler.coffee +++ b/src/browser/atom-protocol-handler.coffee @@ -34,8 +34,7 @@ class AtomProtocolHandler if relativePath.indexOf('assets/') is 0 assetsPath = path.join(app.getHomeDir(), '.atom', relativePath) - if fs.statSyncNoException(assetsPath).isFile?() - filePath = assetsPath + filePath = assetsPath if fs.statSyncNoException(assetsPath).isFile?() unless filePath for loadPath in @loadPaths From ab0f9e88a776f0a5daa334b2f6e802865ac9598d Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Fri, 31 Oct 2014 10:56:03 -0700 Subject: [PATCH 4/5] Add dot atom directory ivar --- src/browser/atom-protocol-handler.coffee | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/browser/atom-protocol-handler.coffee b/src/browser/atom-protocol-handler.coffee index faa051b36..2d494f85e 100644 --- a/src/browser/atom-protocol-handler.coffee +++ b/src/browser/atom-protocol-handler.coffee @@ -18,11 +18,12 @@ module.exports = class AtomProtocolHandler constructor: (@resourcePath, safeMode) -> @loadPaths = [] + @dotAtomDirectory = path.join(app.getHomeDir(), '.atom') unless safeMode - @loadPaths.push(path.join(app.getHomeDir(), '.atom', 'dev', 'packages')) + @loadPaths.push(path.join(@dotAtomDirectory, 'dev', 'packages')) - @loadPaths.push(path.join(app.getHomeDir(), '.atom', 'packages')) + @loadPaths.push(path.join(@dotAtomDirectory, 'packages')) @loadPaths.push(path.join(@resourcePath, 'node_modules')) @registerAtomProtocol() @@ -33,7 +34,7 @@ class AtomProtocolHandler relativePath = path.normalize(request.url.substr(7)) if relativePath.indexOf('assets/') is 0 - assetsPath = path.join(app.getHomeDir(), '.atom', relativePath) + assetsPath = path.join(@dotAtomDirectory, relativePath) filePath = assetsPath if fs.statSyncNoException(assetsPath).isFile?() unless filePath From 26f21abcf3ca15eb91b00820a3220c79381b2382 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Fri, 31 Oct 2014 11:24:26 -0700 Subject: [PATCH 5/5] Remove ivar only used in constructor --- src/browser/atom-protocol-handler.coffee | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/browser/atom-protocol-handler.coffee b/src/browser/atom-protocol-handler.coffee index 2d494f85e..d6c1f567b 100644 --- a/src/browser/atom-protocol-handler.coffee +++ b/src/browser/atom-protocol-handler.coffee @@ -16,7 +16,7 @@ protocol = require 'protocol' # module.exports = class AtomProtocolHandler - constructor: (@resourcePath, safeMode) -> + constructor: (resourcePath, safeMode) -> @loadPaths = [] @dotAtomDirectory = path.join(app.getHomeDir(), '.atom') @@ -24,7 +24,7 @@ class AtomProtocolHandler @loadPaths.push(path.join(@dotAtomDirectory, 'dev', 'packages')) @loadPaths.push(path.join(@dotAtomDirectory, 'packages')) - @loadPaths.push(path.join(@resourcePath, 'node_modules')) + @loadPaths.push(path.join(resourcePath, 'node_modules')) @registerAtomProtocol()