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.

Dc13d329db98a4ff44d52013b80e3bf4?s=128

Cheng Zhao

June 21, 2014
Tweet

Transcript

  1. 2.

    • 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. 4.

    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. 5.

    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. 6.

    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. 8.
  6. 11.

    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
  7. 14.

    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
  8. 16.

    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()
  9. 18.

    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
  10. 19.

    Event Loop of Native GUI Programs Main Thread [NSApp run]

    WaitMessage() Main Thread Windows Mac OS X
  11. 23.

    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