diff --git a/package.json b/package.json index 09d76509b..3b4089d07 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "atom", "version": "31.0.0", - "main": "./src/main.js", + "main": "./src/browser/main.js", "repository": { "type": "git", "url": "https://github.com/atom/atom.git" diff --git a/src/application-menu.coffee b/src/browser/application-menu.coffee similarity index 100% rename from src/application-menu.coffee rename to src/browser/application-menu.coffee diff --git a/src/atom-application.coffee b/src/browser/atom-application.coffee similarity index 96% rename from src/atom-application.coffee rename to src/browser/atom-application.coffee index b3fc70596..aad19da63 100644 --- a/src/atom-application.coffee +++ b/src/browser/atom-application.coffee @@ -1,6 +1,6 @@ -AtomWindow = require 'atom-window' -ApplicationMenu = require 'application-menu' -AtomProtocolHandler = require 'atom-protocol-handler' +AtomWindow = require './atom-window' +ApplicationMenu = require './application-menu' +AtomProtocolHandler = require './atom-protocol-handler' Menu = require 'menu' autoUpdater = require 'auto-updater' app = require 'app' @@ -251,7 +251,7 @@ class AtomApplication bootstrapScript = require.resolve(path.join(global.devResourcePath, 'src', 'window-bootstrap')) else resourcePath = @resourcePath - bootstrapScript = require.resolve('./window-bootstrap') + bootstrapScript = require.resolve('../window-bootstrap') openedWindow = new AtomWindow({pathToOpen, initialLine, bootstrapScript, resourcePath, devMode, initialSize}) if pidToKillWhenClosed? @@ -279,8 +279,8 @@ class AtomApplication # Boolean to control the opened window's dev mode. openUrl: ({urlToOpen, devMode}) -> unless @packages? - PackageManager = require './package-manager' - fsUtils = require './fs-utils' + PackageManager = require '../package-manager' + fsUtils = require '../fs-utils' @packages = new PackageManager configDirPath: fsUtils.absolute('~/.atom') devMode: devMode @@ -314,7 +314,7 @@ class AtomApplication try bootstrapScript = require.resolve(path.resolve(global.devResourcePath, 'spec', 'spec-bootstrap')) catch error - bootstrapScript = require.resolve(path.resolve(__dirname, '..', 'spec', 'spec-bootstrap')) + bootstrapScript = require.resolve(path.resolve(__dirname, '..', '..', 'spec', 'spec-bootstrap')) isSpec = true devMode = true @@ -324,9 +324,9 @@ class AtomApplication try bootstrapScript = require.resolve(path.resolve(global.devResourcePath, 'benchmark', 'benchmark-bootstrap')) catch error - bootstrapScript = require.resolve(path.resolve(__dirname, '..', 'benchmark', 'benchmark-bootstrap')) + bootstrapScript = require.resolve(path.resolve(__dirname, '..', '..', 'benchmark', 'benchmark-bootstrap')) - isSpec = true # Needed because this flag adds the spec directory to the NODE_PATH + isSpec = true new AtomWindow({bootstrapScript, @resourcePath, isSpec}) # Private: Opens a native dialog to prompt the user for a path. diff --git a/src/atom-protocol-handler.coffee b/src/browser/atom-protocol-handler.coffee similarity index 100% rename from src/atom-protocol-handler.coffee rename to src/browser/atom-protocol-handler.coffee diff --git a/src/atom-window.coffee b/src/browser/atom-window.coffee similarity index 97% rename from src/atom-window.coffee rename to src/browser/atom-window.coffee index 81de39f38..031fcd68d 100644 --- a/src/atom-window.coffee +++ b/src/browser/atom-window.coffee @@ -1,7 +1,6 @@ BrowserWindow = require 'browser-window' Menu = require 'menu' -MenuItem = require 'menu-item' -ContextMenu = require 'context-menu' +ContextMenu = require './context-menu' dialog = require 'dialog' ipc = require 'ipc' path = require 'path' @@ -84,7 +83,7 @@ class AtomWindow when 1 then @browserWindow.restart() @browserWindow.on 'context-menu', (menuTemplate) => - new ContextMenu(menuTemplate) + new ContextMenu(menuTemplate, @browserWindow) if @isSpec # Spec window's web view should always have focus diff --git a/src/context-menu.coffee b/src/browser/context-menu.coffee similarity index 83% rename from src/context-menu.coffee rename to src/browser/context-menu.coffee index f60a7709e..6abc6a801 100644 --- a/src/context-menu.coffee +++ b/src/browser/context-menu.coffee @@ -1,12 +1,11 @@ Menu = require 'menu' -BrowserWindow = require 'browser-window' module.exports = class ContextMenu - constructor: (template) -> + constructor: (template, browserWindow) -> template = @createClickHandlers(template) menu = Menu.buildFromTemplate(template) - menu.popup(BrowserWindow.getFocusedWindow()) + menu.popup(browserWindow) # Private: It's necessary to build the event handlers in this process, otherwise # closures are drug across processes and failed to be garbage collected diff --git a/src/main.coffee b/src/browser/main.coffee similarity index 91% rename from src/main.coffee rename to src/browser/main.coffee index f6c5bf165..e2490b97c 100644 --- a/src/main.coffee +++ b/src/browser/main.coffee @@ -14,6 +14,10 @@ dialog = require 'dialog' console.log = (args...) -> nslog(args.map((arg) -> JSON.stringify(arg)).join(" ")) +process.on 'uncaughtException', (error={}) -> + nslog(error.message) if error.message? + nslog(error.stack) if error.stack? + delegate.browserMainParts.preMainMessageLoopRun = -> args = parseCommandLine() @@ -47,12 +51,9 @@ delegate.browserMainParts.preMainMessageLoopRun = -> require('coffee-script') if args.devMode require(path.join(args.resourcePath, 'src', 'coffee-cache')).register() - module.globalPaths.push(path.join(args.resourcePath, 'src')) + AtomApplication = require path.join(args.resourcePath, 'src', 'browser', 'atom-application') else - appSrcPath = path.resolve(process.argv[0], "../../Resources/app/src") - module.globalPaths.push(appSrcPath) - - AtomApplication = require 'atom-application' + AtomApplication = require './atom-application' AtomApplication.open(args) console.log("App load time: #{new Date().getTime() - startTime}ms") @@ -112,6 +113,6 @@ parseCommandLine = -> fs.statSync resourcePath catch e devMode = false - resourcePath = path.dirname(__dirname) + resourcePath = path.dirname(path.dirname(__dirname)) {resourcePath, pathsToOpen, executedFrom, test, version, pidToKillWhenClosed, devMode, newWindow, specDirectory}