How does main process start render process in Atom?


#1

I’m trying to trace the startup sequence in Atom and it’s pretty straightforward for the main process, following (in the src/browser folder) main.coffee to atom-application to atom-window where the path is loaded and the browserwindow object is created. What I haven’t been able to figure out is how this then interact with the render process.

Can someone please explain specifically how the main process triggers the render process? What is the entry point into the render process? For example, where are the initial window and panes created? And how are the load paths in the main process then causing new text-editors to be created?

Thanks for your help.

Andrew


#2

Of course after I posted this I found where src/browser/atom-application.coffee calls src/initialize-application-window.coffee (lines 415-418, in the openPaths method), which then creates the AtomEnvironment and ApplicationDelegate classes on the render method. That answers the entry point question. Now I just need to find the connection between the open paths event on the main process and the render process.

Andrew


#3

I have a whole breakdown of the startup process of Atom here:

The openURIInPane method is where the opening magic happens:


#4

Thanks. I swear I searched for the answer for quite a while before posting. Best - Andrew


#5

Just FYI, it looks like the load process has changed since you wrote that post “Browser and Node Integration concepts.” The window-bootstrap.coffee has been replaced with the initialize-application-window.coffee script, and is invoked in a different place.


#6

Actually I was mistaken earlier. The src/initialize-application-window.coffee script is only loaded in the src/browser/atom-application.coffee (not run), where it is passed through to the atom-window.coffee file and encoded in the url call that loads the static/index.html file. This runs index.js, where the load settings are parsed, and the initialize-application-window.coffee script is finally run on line 86.


#7

For posterity, here are the results of my tracing the load process. Please point out any mistakes and I will fix them.

MAIN PROCESS


###main.coffee

  • parses command line args and creates AtomApplication (line 39) by calling AtomApplication.open(args)

###atom-application.coffee

  • open(options) method
    • “static” factory method where actual AtomApplication object is created
    • registers ‘application:*’ events
    • checks if app is running tests, opening a file, or opening a url
    • openPaths() is the method that opens files
      • requires the src/initialize-application-window.coffee script, which is passed on to the AtomWindow obj
      • either creates a new AtomWindow with the locations to open or tells an existing window to open the locations

###atom-window.coffee

  • creates the BrowserWindow object
  • collects the load settings
  • tells the browser window to load the static/index.html file, passing the load settings as url encoded json
  • THIS KICKS OFF THE SEPARATE RENDER PROCESS

RENDER PROCESS


###index.html

  • basically just an html shell that calls index.js

###index.js

  • entry point for the render process
  • receives the encoded load settings from the main process (via atom-application and atom-window) in the query string
  • pre-load:
    • parses load settings
    • sets the process.env.ATOM_HOME global var as passed in via load settings
    • sets window background styling
  • onLoad()
    • creates the FileSystemBlobStore blobStore for path ATOM_HOME/blob-store
    • calls setupWindow(loadsSettings), which:
      • sets up caches and crash reporter
      • retrieves the initialize-application-window.coffee script from loadSettings.windowInitializationScript
      • runs the initialize script, passing in the blobStore

###initialize-application-window.coffee (render, in src directory)

  • creates the AtomEnvironment
  • creates the ApplicationDelegate object
  • assigns the AtomEnvironment object to ‘window.atom’ in the global context and assigns the ApplicationDelegate object to the applicationDelegate property of the AtomEnvironment
  • calls atom.displayWindow(), which sets window dimensions, shows the window, and sets it to have focus
    • displayWindow() actually calls the show() method, which calls the applicationDelegate.showWindow() method, which sends an ipc message with the command: ipc.send(“call-window-method”, “show”). This is received in the browser AtomApplication class, which passes the show command to the appropriate BrowserWindow object
  • calls atom.startEditorWindow(), which is where the workspace & editor environment that the user interacts with is created
    • loads default keymaps
    • loads packages
    • adds the workspace view to the document.body
    • activates the loaded packages
    • runs the user init script
    • updates the menu
    • opens an initial empty editor