From a3559d1289d5b76e9f8266bf7bb6fe255ae4a81c Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Mon, 7 Oct 2013 14:36:19 -0700 Subject: [PATCH 01/15] Call methods through this instead of atom global --- src/package-manager.coffee | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/package-manager.coffee b/src/package-manager.coffee index cc08c6f56..70eaec4aa 100644 --- a/src/package-manager.coffee +++ b/src/package-manager.coffee @@ -122,8 +122,8 @@ class PackageManager getAvailablePackageMetadata: -> packages = [] - for packagePath in atom.getAvailablePackagePaths() + for packagePath in @getAvailablePackagePaths() name = path.basename(packagePath) - metadata = atom.getLoadedPackage(name)?.metadata ? Package.loadMetadata(packagePath, true) + metadata = @getLoadedPackage(name)?.metadata ? Package.loadMetadata(packagePath, true) packages.push(metadata) packages From 722be2267d8e5b8284162f4250bdf44d3929b1c8 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Mon, 7 Oct 2013 14:36:58 -0700 Subject: [PATCH 02/15] Add getter for config directory path --- src/config.coffee | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/config.coffee b/src/config.coffee index 1b2466381..05bdc19a4 100644 --- a/src/config.coffee +++ b/src/config.coffee @@ -117,6 +117,9 @@ class Config _.extend hash, defaults @update() + # Public: Get the path to this config's directory. + getDirectoryPath: -> @configDirPath + # Public: Returns a new {Object} containing all of settings and defaults. getSettings: -> _.deepExtend(@settings, @defaultSettings) From 87bfcf56837486f25a1641bc0f8aa5ede9c8bbe1 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Mon, 7 Oct 2013 14:38:19 -0700 Subject: [PATCH 03/15] :syringe: dependencies into AtomPackage Removes use of resourcePath and config globals --- src/atom.coffee | 18 ++++++++++-------- src/package-manager.coffee | 14 +++++++++----- 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/src/atom.coffee b/src/atom.coffee index 07569171e..7a2982101 100644 --- a/src/atom.coffee +++ b/src/atom.coffee @@ -27,6 +27,8 @@ class Atom initialize: -> @unsubscribe() + {devMode, resourcePath} = atom.getLoadSettings() + Config = require './config' Keymap = require './keymap' PackageManager = require './package-manager' @@ -35,20 +37,20 @@ class Atom ThemeManager = require './theme-manager' ContextMenuManager = require './context-menu-manager' - @packages = new PackageManager() - - #TODO Remove once packages have been updated to not touch atom.packageStates directly - @__defineGetter__ 'packageStates', => @packages.packageStates - @__defineSetter__ 'packageStates', (packageStates) => @packages.packageStates = packageStates - - @subscribe @packages, 'loaded', => @watchThemes() @themes = new ThemeManager() - @contextMenu = new ContextMenuManager(@getLoadSettings().devMode) + @contextMenu = new ContextMenuManager(devMode) @config = new Config() @pasteboard = new Pasteboard() @keymap = new Keymap() @syntax = deserialize(@getWindowState('syntax')) ? new Syntax() + @packages = new PackageManager({devMode, resourcePath, configDirPath: @config.getDirectoryPath()}) + @subscribe @packages, 'loaded', => @watchThemes() + + #TODO Remove once packages have been updated to not touch atom.packageStates directly + @__defineGetter__ 'packageStates', => @packages.packageStates + @__defineSetter__ 'packageStates', (packageStates) => @packages.packageStates = packageStates + getCurrentWindow: -> remote.getCurrentWindow() diff --git a/src/package-manager.coffee b/src/package-manager.coffee index 70eaec4aa..a2f026b2d 100644 --- a/src/package-manager.coffee +++ b/src/package-manager.coffee @@ -8,7 +8,11 @@ module.exports = class PackageManager _.extend @prototype, EventEmitter - constructor: -> + constructor: ({configDirPath, devMode, @resourcePath}) -> + @packageDirPaths = [path.join(configDirPath, "packages")] + if devMode + @packageDirPaths.unshift(path.join(configDirPath, "dev", "packages")) + @loadedPackages = {} @activePackages = {} @packageStates = {} @@ -83,10 +87,10 @@ class PackageManager resolvePackagePath: (name) -> return name if fsUtils.isDirectorySync(name) - packagePath = fsUtils.resolve(config.packageDirPaths..., name) + packagePath = fsUtils.resolve(@packageDirPaths..., name) return packagePath if fsUtils.isDirectorySync(packagePath) - packagePath = path.join(window.resourcePath, 'node_modules', name) + packagePath = path.join(@resourcePath, 'node_modules', name) return packagePath if @isInternalPackage(packagePath) isInternalPackage: (packagePath) -> @@ -108,11 +112,11 @@ class PackageManager getAvailablePackagePaths: -> packagePaths = [] - for packageDirPath in config.packageDirPaths + for packageDirPath in @packageDirPaths for packagePath in fsUtils.listSync(packageDirPath) packagePaths.push(packagePath) if fsUtils.isDirectorySync(packagePath) - for packagePath in fsUtils.listSync(path.join(window.resourcePath, 'node_modules')) + for packagePath in fsUtils.listSync(path.join(@resourcePath, 'node_modules')) packagePaths.push(packagePath) if @isInternalPackage(packagePath) _.uniq(packagePaths) From 19a8626c212a14f211c0e9860dfd4dd58aecf2cc Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Mon, 7 Oct 2013 14:40:05 -0700 Subject: [PATCH 04/15] Add extension point for opening urls If packages specify a urlMain in their package.json then that file will be used as the bootstrap script new windows when a URL is opened to that package. --- src/atom-application.coffee | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/src/atom-application.coffee b/src/atom-application.coffee index b54b99bfa..25c7c2b1e 100644 --- a/src/atom-application.coffee +++ b/src/atom-application.coffee @@ -51,7 +51,7 @@ class AtomApplication version: null constructor: (options) -> - {@resourcePath, @version} = options + {@resourcePath, @version, @devMode} = options global.atomApplication = this @pidsToOpenWindows = {} @@ -147,7 +147,7 @@ class AtomApplication app.on 'open-url', (event, urlToOpen) => event.preventDefault() - @openUrl(urlToOpen) + @openUrl({urlToOpen, @devMode}) autoUpdater.on 'ready-for-update-on-quit', (event, version, quitAndUpdateCallback) => event.preventDefault() @@ -253,8 +253,6 @@ class AtomApplication # Private: Handles an atom:// url. # - # Currently only supports atom://session/ urls. - # # * options # + urlToOpen: # The atom:// url to open. @@ -262,14 +260,27 @@ class AtomApplication # Boolean to control the opened window's dev mode. openUrl: ({urlToOpen, devMode}) -> parsedUrl = url.parse(urlToOpen) - if parsedUrl.host is 'session' - sessionId = parsedUrl.path.split('/')[1] - console.log "Joining session #{sessionId}" - if sessionId - bootstrapScript = 'collaboration/lib/bootstrap' - new AtomWindow({bootstrapScript, @resourcePath, sessionId, devMode}) + packageName = parsedUrl.host + unless @packages? + PackageManager = require './package-manager' + fsUtils = require './fs-utils' + @packages = new PackageManager({ + devMode: devMode + configDirPath: fsUtils.absolute('~/.atom') + resourcePath: @resourcePath + }) + + pack = _.find @packages.getAvailablePackageMetadata(), ({name}) -> name is packageName + if pack? + console.log(pack) + if pack.urlMain + packagePath = @packages.resolvePackagePath(packageName) + bootstrapScript = path.resolve(packagePath, pack.urlMain) + new AtomWindow({bootstrapScript, @resourcePath, devMode}) + else + console.log "Package '#{pack.name}' does not have a url main: #{urlToOpen}" else - console.log "Opening unknown url #{urlToOpen}" + console.log "Opening unknown url: #{urlToOpen}" # Private: Opens up a new {AtomWindow} to run specs within. # From ad577d6315ba6bd1f12ab068c529247c7cb4407d Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Mon, 7 Oct 2013 14:41:13 -0700 Subject: [PATCH 05/15] Add url to open to load settings --- src/atom-application.coffee | 1 + 1 file changed, 1 insertion(+) diff --git a/src/atom-application.coffee b/src/atom-application.coffee index 25c7c2b1e..0807209b3 100644 --- a/src/atom-application.coffee +++ b/src/atom-application.coffee @@ -268,6 +268,7 @@ class AtomApplication devMode: devMode configDirPath: fsUtils.absolute('~/.atom') resourcePath: @resourcePath + urlToOpen: urlToOpen }) pack = _.find @packages.getAvailablePackageMetadata(), ({name}) -> name is packageName From db47d02c3c59e5d79d9033278544f65850bea487 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Mon, 7 Oct 2013 14:52:30 -0700 Subject: [PATCH 06/15] Add fixture packages to atom.packages.packageDirPaths --- spec/spec-helper.coffee | 1 + 1 file changed, 1 insertion(+) diff --git a/spec/spec-helper.coffee b/spec/spec-helper.coffee index a902fc2b4..5fb160e87 100644 --- a/spec/spec-helper.coffee +++ b/spec/spec-helper.coffee @@ -18,6 +18,7 @@ atom.themes.loadBaseStylesheets() atom.themes.requireStylesheet '../static/jasmine' fixturePackagesPath = path.resolve(__dirname, './fixtures/packages') +atom.packages.packageDirPaths.unshift(fixturePackagesPath) atom.keymap.loadBundledKeymaps() [bindingSetsToRestore, bindingSetsByFirstKeystrokeToRestore] = [] From 55b71405c9bac21133f79a5953330fc505c1c04d Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Mon, 7 Oct 2013 14:56:19 -0700 Subject: [PATCH 07/15] Remove uneeded curlies and parens --- src/atom-application.coffee | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/atom-application.coffee b/src/atom-application.coffee index 0807209b3..d95a27a4e 100644 --- a/src/atom-application.coffee +++ b/src/atom-application.coffee @@ -264,12 +264,11 @@ class AtomApplication unless @packages? PackageManager = require './package-manager' fsUtils = require './fs-utils' - @packages = new PackageManager({ + @packages = new PackageManager devMode: devMode configDirPath: fsUtils.absolute('~/.atom') resourcePath: @resourcePath urlToOpen: urlToOpen - }) pack = _.find @packages.getAvailablePackageMetadata(), ({name}) -> name is packageName if pack? From 9db3f9b5d9d4d8c9553217d9ffb1de4d4a4d46b4 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Mon, 7 Oct 2013 15:06:59 -0700 Subject: [PATCH 08/15] Remove logging of found package --- src/atom-application.coffee | 1 - 1 file changed, 1 deletion(-) diff --git a/src/atom-application.coffee b/src/atom-application.coffee index d95a27a4e..491b9650e 100644 --- a/src/atom-application.coffee +++ b/src/atom-application.coffee @@ -272,7 +272,6 @@ class AtomApplication pack = _.find @packages.getAvailablePackageMetadata(), ({name}) -> name is packageName if pack? - console.log(pack) if pack.urlMain packagePath = @packages.resolvePackagePath(packageName) bootstrapScript = path.resolve(packagePath, pack.urlMain) From 0033c9659f36f38db7179959e810cfac39434e83 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Mon, 7 Oct 2013 15:28:00 -0700 Subject: [PATCH 09/15] :syringe: directory dependencies into Config --- spec/spec-helper.coffee | 4 +++- src/atom.coffee | 24 +++++++++++++++--------- src/config.coffee | 18 ++++++------------ 3 files changed, 24 insertions(+), 22 deletions(-) diff --git a/spec/spec-helper.coffee b/spec/spec-helper.coffee index 5fb160e87..db907b685 100644 --- a/spec/spec-helper.coffee +++ b/spec/spec-helper.coffee @@ -51,7 +51,9 @@ beforeEach -> bindingSetsByFirstKeystrokeToRestore = _.clone(keymap.bindingSetsByFirstKeystroke) # reset config before each spec; don't load or save from/to `config.json` - config = new Config() + config = new Config + resourcePath: window.resourcePath + configDirPath: atom.getConfigDirPath() config.packageDirPaths.unshift(fixturePackagesPath) spyOn(config, 'load') spyOn(config, 'save') diff --git a/src/atom.coffee b/src/atom.coffee index 7a2982101..96501496b 100644 --- a/src/atom.coffee +++ b/src/atom.coffee @@ -28,6 +28,7 @@ class Atom @unsubscribe() {devMode, resourcePath} = atom.getLoadSettings() + configDirPath = @getConfigDirPath() Config = require './config' Keymap = require './keymap' @@ -37,20 +38,21 @@ class Atom ThemeManager = require './theme-manager' ContextMenuManager = require './context-menu-manager' - @themes = new ThemeManager() - @contextMenu = new ContextMenuManager(devMode) - @config = new Config() - @pasteboard = new Pasteboard() - @keymap = new Keymap() - @syntax = deserialize(@getWindowState('syntax')) ? new Syntax() - - @packages = new PackageManager({devMode, resourcePath, configDirPath: @config.getDirectoryPath()}) - @subscribe @packages, 'loaded', => @watchThemes() + @packages = new PackageManager({devMode, configDirPath, resourcePath}) #TODO Remove once packages have been updated to not touch atom.packageStates directly @__defineGetter__ 'packageStates', => @packages.packageStates @__defineSetter__ 'packageStates', (packageStates) => @packages.packageStates = packageStates + @subscribe @packages, 'loaded', => @watchThemes() + @themes = new ThemeManager() + @contextMenu = new ContextMenuManager(devMode) + @config = new Config({configDirPath, resourcePath}) + @pasteboard = new Pasteboard() + @keymap = new Keymap() + @syntax = deserialize(@getWindowState('syntax')) ? new Syntax() + + getCurrentWindow: -> remote.getCurrentWindow() @@ -215,6 +217,10 @@ class Atom getHomeDirPath: -> app.getHomeDir() + # Public: Get the directory path to Atom's configuration area. + getConfigDirPath: -> + @configDirPath ?= fsUtils.absolute('~/.atom') + getWindowStatePath: -> switch @windowMode when 'spec' diff --git a/src/config.coffee b/src/config.coffee index 05bdc19a4..c50384e18 100644 --- a/src/config.coffee +++ b/src/config.coffee @@ -7,8 +7,6 @@ path = require 'path' async = require 'async' pathWatcher = require 'pathwatcher' -configDirPath = fsUtils.absolute("~/.atom") - # Public: Used to access all of Atom's configuration details. # # A global instance of this class is available to all plugins which can be @@ -35,14 +33,13 @@ class Config configFileHasErrors: null # Private: Created during initialization, available as `global.config` - constructor: -> - @configDirPath = configDirPath - @bundledKeymapsDirPath = path.join(resourcePath, "keymaps") - @nodeModulesDirPath = path.join(resourcePath, "node_modules") + constructor: ({@configDirPath, @resourcePath}={}) -> + @bundledKeymapsDirPath = path.join(@resourcePath, "keymaps") + @nodeModulesDirPath = path.join(@resourcePath, "node_modules") @bundledPackageDirPaths = [@nodeModulesDirPath] @lessSearchPaths = [ - path.join(resourcePath, 'static', 'variables') - path.join(resourcePath, 'static') + path.join(@resourcePath, 'static', 'variables') + path.join(@resourcePath, 'static') ] @packageDirPaths = [path.join(configDirPath, "packages")] if atom.getLoadSettings().devMode @@ -67,7 +64,7 @@ class Config fsUtils.copy(sourcePath, destinationPath, callback) queue.drain = done - templateConfigDirPath = fsUtils.resolve(window.resourcePath, 'dot-atom') + templateConfigDirPath = fsUtils.resolve(@resourcePath, 'dot-atom') onConfigDirFile = (sourcePath) => relativePath = sourcePath.substring(templateConfigDirPath.length + 1) destinationPath = path.join(@configDirPath, relativePath) @@ -117,9 +114,6 @@ class Config _.extend hash, defaults @update() - # Public: Get the path to this config's directory. - getDirectoryPath: -> @configDirPath - # Public: Returns a new {Object} containing all of settings and defaults. getSettings: -> _.deepExtend(@settings, @defaultSettings) From e95e8a22c3f755a31771c57449560e6bcdd662e4 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Mon, 7 Oct 2013 15:29:44 -0700 Subject: [PATCH 10/15] :lipstick: Remove extra newline --- src/atom.coffee | 1 - 1 file changed, 1 deletion(-) diff --git a/src/atom.coffee b/src/atom.coffee index 96501496b..f4ce8e441 100644 --- a/src/atom.coffee +++ b/src/atom.coffee @@ -52,7 +52,6 @@ class Atom @keymap = new Keymap() @syntax = deserialize(@getWindowState('syntax')) ? new Syntax() - getCurrentWindow: -> remote.getCurrentWindow() From f8e61f5c4861b07f9ac24eda76ac0fab080f8a9f Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Mon, 7 Oct 2013 15:31:08 -0700 Subject: [PATCH 11/15] Add missing @ before configDirPath --- src/config.coffee | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/config.coffee b/src/config.coffee index c50384e18..f6104747f 100644 --- a/src/config.coffee +++ b/src/config.coffee @@ -41,18 +41,18 @@ class Config path.join(@resourcePath, 'static', 'variables') path.join(@resourcePath, 'static') ] - @packageDirPaths = [path.join(configDirPath, "packages")] + @packageDirPaths = [path.join(@configDirPath, "packages")] if atom.getLoadSettings().devMode - @packageDirPaths.unshift(path.join(configDirPath, "dev", "packages")) + @packageDirPaths.unshift(path.join(@configDirPath, "dev", "packages")) @userPackageDirPaths = _.clone(@packageDirPaths) - @userStoragePath = path.join(configDirPath, "storage") + @userStoragePath = path.join(@configDirPath, "storage") @defaultSettings = core: _.clone(require('./root-view').configDefaults) editor: _.clone(require('./editor').configDefaults) @settings = {} - @configFilePath = fsUtils.resolve(configDirPath, 'config', ['json', 'cson']) - @configFilePath ?= path.join(configDirPath, 'config.cson') + @configFilePath = fsUtils.resolve(@configDirPath, 'config', ['json', 'cson']) + @configFilePath ?= path.join(@configDirPath, 'config.cson') # Private: initializeConfigDirectory: (done) -> From d3e2d9b5f9fe874649fc46faf5ecca8d210cff3d Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Mon, 7 Oct 2013 15:42:23 -0700 Subject: [PATCH 12/15] :memo: Update AtomApplication.openUrl() comment --- src/atom-application.coffee | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/atom-application.coffee b/src/atom-application.coffee index 491b9650e..354e3d202 100644 --- a/src/atom-application.coffee +++ b/src/atom-application.coffee @@ -251,7 +251,11 @@ class AtomApplication console.log("Killing process #{pid} failed: #{error.code}") delete @pidsToOpenWindows[pid] - # Private: Handles an atom:// url. + # Private: Open an atom:// url. + # + # The host of the URL being opened is assumed to be the package name + # responsible for opening the URL. A new window will be created with + # that package's `urlMain` as the bootstrap script. # # * options # + urlToOpen: From 124b1ebd3398306bd714021d465442a78dd17318 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Mon, 7 Oct 2013 15:42:42 -0700 Subject: [PATCH 13/15] :lipstick: Reorganize option param --- src/atom-application.coffee | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/atom-application.coffee b/src/atom-application.coffee index 354e3d202..f6b95e06c 100644 --- a/src/atom-application.coffee +++ b/src/atom-application.coffee @@ -269,8 +269,8 @@ class AtomApplication PackageManager = require './package-manager' fsUtils = require './fs-utils' @packages = new PackageManager - devMode: devMode configDirPath: fsUtils.absolute('~/.atom') + devMode: devMode resourcePath: @resourcePath urlToOpen: urlToOpen From 7f0150c6b880d66c7bd6ebc91f858425b9ca85ba Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Mon, 7 Oct 2013 15:43:31 -0700 Subject: [PATCH 14/15] :lipstick: Inline parsed url --- src/atom-application.coffee | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/atom-application.coffee b/src/atom-application.coffee index f6b95e06c..7d86e68bf 100644 --- a/src/atom-application.coffee +++ b/src/atom-application.coffee @@ -263,8 +263,6 @@ class AtomApplication # + devMode: # Boolean to control the opened window's dev mode. openUrl: ({urlToOpen, devMode}) -> - parsedUrl = url.parse(urlToOpen) - packageName = parsedUrl.host unless @packages? PackageManager = require './package-manager' fsUtils = require './fs-utils' @@ -274,6 +272,7 @@ class AtomApplication resourcePath: @resourcePath urlToOpen: urlToOpen + packageName = url.parse(urlToOpen).host pack = _.find @packages.getAvailablePackageMetadata(), ({name}) -> name is packageName if pack? if pack.urlMain From 2029895f0bf6a0e948892a25476620c6865a28d4 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Mon, 7 Oct 2013 16:01:32 -0700 Subject: [PATCH 15/15] Pass urlToOpen to AtomWindow constructor --- src/atom-application.coffee | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/atom-application.coffee b/src/atom-application.coffee index 7d86e68bf..2d3bb244f 100644 --- a/src/atom-application.coffee +++ b/src/atom-application.coffee @@ -270,7 +270,6 @@ class AtomApplication configDirPath: fsUtils.absolute('~/.atom') devMode: devMode resourcePath: @resourcePath - urlToOpen: urlToOpen packageName = url.parse(urlToOpen).host pack = _.find @packages.getAvailablePackageMetadata(), ({name}) -> name is packageName @@ -278,7 +277,7 @@ class AtomApplication if pack.urlMain packagePath = @packages.resolvePackagePath(packageName) bootstrapScript = path.resolve(packagePath, pack.urlMain) - new AtomWindow({bootstrapScript, @resourcePath, devMode}) + new AtomWindow({bootstrapScript, @resourcePath, devMode, urlToOpen}) else console.log "Package '#{pack.name}' does not have a url main: #{urlToOpen}" else