Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Practice on embedding Node.js into Atom Editor

Practice on embedding Node.js into Atom Editor

This presentation introduces techniques used on integrating node.js into atom-shell.

Cheng Zhao

June 21, 2014
Tweet

More Decks by Cheng Zhao

Other Decks in Programming

Transcript

  1. • Atom is a text editor written by GitHub
 https://github.com/atom/atom

    • Atom Shell is a desktop application shell based on Chromium and Node.js
 https://github.com/atom/atom- shell • Atom is built upon Atom Shell Atom Editor and Atom Shell
  2. Chromium Browser Browser Window Window Window … Tray Menu Dialog

    Controlled by C++ Renderer HTML JavaScript (DOM) Renderer HTML JavaScript (DOM) Renderer HTML JavaScript (DOM) IPC
  3. Atom Shell Browser Window Window Window … Tray Menu Dialog

    Controlled by Node.js Renderer HTML JavaScript (DOM) Node.js Renderer HTML JavaScript (DOM) Node.js Renderer HTML JavaScript (DOM) Node.js IPC
  4. Node.js in Atom Shell • Atom Shell has embedded Node.js

    in both Chromium browser’s browser process and renderer process • JavaScript in browser process can do GUI related operations like creating windows and menus. • JavaScript in renderer process can use Node.js APIs in addition to standard DOM.
  5. Node.js <= 0.10.x main(int argc, char *argv[]) context = Context::New()

    SetupProcessObject(argc, argv); Load(process_l); uv_run(); Load environment Event loop Create context Program entrance
  6. Node.js >= 0.11.x main(int argc, char *argv[]) context = Context::New()

    env = CreateEnvironment(context) uv_run(); Load environment Event loop Create context Program entrance
  7. Node.js in Atom Shell main(int argc, char *argv[]) Context::New() CreateEnvironment()

    pump->Run(); Load Node.js Event loop Create context Program entrance content::xxxxx(…) Init Chromium Context::New() CreateEnvironment()
  8. Event Loop of Node.js timers, idle IO poll deal with

    IO events uv_check uv_prepare Main Thread process.nextTick produced events setImmediate produced events
  9. Event Loop of Native GUI Programs Main Thread [NSApp run]

    WaitMessage() Main Thread Windows Mac OS X
  10. Event Loop of Atom Shell Main Thread Windows WaitMessage() New

    Thread IO poll 提 ⽰示主 线 程 有 Node.js事 件 timers, idle IO poll once deal with IO events uv_check uv_prepare