old_contents: var app = require('app'),
    BrowserWindow = require('browser-window'),
    Menu = require('menu'),
    dialog = require('dialog'),
    config = {},
    fs = require('fs');
  //
  // report crashes to atom-shell
  require('crash-reporter').start();
  
  //--------------------------------------------------------------------------------
  // Add Project Dialog
  //--------------------------------------------------------------------------------
  
  var showAddExistingProjectDialog = (function(){
  
    var options = {
      title: "Select an existing project (project.clj)",
      properties: ["openFile"],
      filters: [
        {
          name: "Leiningen project config",
          extensions: ["clj"],
        }
      ],
    };
  
    function callback(filenames) {
      mainWindow.webContents.send('add-existing-project', filenames[0]);
    }
  
    return function() {
      dialog.showOpenDialog(options, callback);
    };
  
  })();
  
  //--------------------------------------------------------------------------------
  // Menu Builder
  //--------------------------------------------------------------------------------
  
  menu_template = [
    {
      label: "File", // NOTE: On Mac, the first menu item is always the name of the Application
      submenu: [
        {
          label: "Add Existing Project",
          click: showAddExistingProjectDialog,
        },
      ],
    }
  ];
  
  menu = Menu.buildFromTemplate(menu_template);
  Menu.setApplicationMenu(menu);
  
  //--------------------------------------------------------------------------------
  // Main
  //--------------------------------------------------------------------------------
  
  // load config
  // NOTE: this is mostly for development purposes
  if (fs.existsSync(__dirname + '/config.json')) {
    config = require(__dirname + '/config.json');
  }
  
  // Keep a global reference of the window object, if you don't, the window will
  // be closed automatically when the javascript object is GCed.
  var mainWindow = null;
  
  // Quit when all windows are closed.
  app.on('window-all-closed', function() {
    if (process.platform !== 'darwin') {
      app.quit();
    }
  });
  
  function onWindowClose() {
    // dereference the window object
    mainWindow = null;
  }
  
  // send the OS-normalized app data path to the webpage
  // NOTE: this event triggers the "global app init" on the webpage side
  function onFinishLoad() {
    mainWindow.webContents.send('config-file-location', app.getDataPath());
  }
  
  // NOTE: a lot of the browserWindow options listed on the docs page aren't
  // working - need to investigate
  var browserWindowOptions = {
    height: 850,
    icon: __dirname + '/img/clojure-logo.png',
    title: 'ClojureScript Compiler',
    width: 1000
  };
  
  function startApp() {
    // create the browser window
    mainWindow = new BrowserWindow(browserWindowOptions);
  
    // load index.html
    mainWindow.loadUrl('file://' + __dirname + '/index.html');
  
    // send info to the webpage
    mainWindow.webContents.on('did-finish-load', onFinishLoad);
  
    // Emitted when the window is closed.
    mainWindow.on('closed', onWindowClose);
  
    // optionally launch dev tools
    if (config.hasOwnProperty("dev-tools") && config["dev-tools"] === true) {
      mainWindow.openDevTools();
    }
  }
  
  // This method will be called when atom-shell has done everything
  // initialization and ready for creating browser windows.
  app.on('ready', startApp);
  
new_contents: var app = require('app'),
    BrowserWindow = require('browser-window'),
    path = require('path'),
    Menu = require('menu'),
    dialog = require('dialog'),
    config = {},
    fs = require('fs');
  //
  // report crashes to atom-shell
  require('crash-reporter').start();
  
  //--------------------------------------------------------------------------------
  // Add Project Dialog
  //--------------------------------------------------------------------------------
  
  var showAddExistingProjectDialog = (function(){
  
    var options = {
      title: "Select an existing project (project.clj)",
      properties: ["openFile"],
      filters: [
        {
          name: "Leiningen project config",
          extensions: ["clj"],
        }
      ],
    };
  
    function addToProjectsJson(filename) {
      var projectsFilename = path.join(app.getDataPath(), "projects.json");
  
      var projects = JSON.parse(fs.readFileSync(projectsFilename, 'utf8'));
      projects.push(filename);
  
      fs.writeFileSync(
        projectsFilename,
        JSON.stringify(projects, null, 2),
        {encoding: "utf8"});
    }
  
    function callback(filenames) {
      var filename = filenames[0];
      addToProjectsJson(filename);
      mainWindow.webContents.send('add-existing-project', filename);
    }
  
    return function() {
      dialog.showOpenDialog(options, callback);
    };
  
  })();
  
  //--------------------------------------------------------------------------------
  // Menu Builder
  //--------------------------------------------------------------------------------
  
  menu_template = [
    {
      label: "File", // NOTE: On Mac, the first menu item is always the name of the Application
      submenu: [
        {
          label: "Add Existing Project",
          click: showAddExistingProjectDialog,
        },
      ],
    }
  ];
  
  menu = Menu.buildFromTemplate(menu_template);
  Menu.setApplicationMenu(menu);
  
  //--------------------------------------------------------------------------------
  // Main
  //--------------------------------------------------------------------------------
  
  // load config
  // NOTE: this is mostly for development purposes
  if (fs.existsSync(__dirname + '/config.json')) {
    config = require(__dirname + '/config.json');
  }
  
  // Keep a global reference of the window object, if you don't, the window will
  // be closed automatically when the javascript object is GCed.
  var mainWindow = null;
  
  // Quit when all windows are closed.
  app.on('window-all-closed', function() {
    if (process.platform !== 'darwin') {
      app.quit();
    }
  });
  
  function onWindowClose() {
    // dereference the window object
    mainWindow = null;
  }
  
  // send the OS-normalized app data path to the webpage
  // NOTE: this event triggers the "global app init" on the webpage side
  function onFinishLoad() {
    mainWindow.webContents.send('config-file-location', app.getDataPath());
  }
  
  // NOTE: a lot of the browserWindow options listed on the docs page aren't
  // working - need to investigate
  var browserWindowOptions = {
    height: 850,
    icon: __dirname + '/img/clojure-logo.png',
    title: 'ClojureScript Compiler',
    width: 1000
  };
  
  function startApp() {
    // create the browser window
    mainWindow = new BrowserWindow(browserWindowOptions);
  
    // load index.html
    mainWindow.loadUrl('file://' + __dirname + '/index.html');
  
    // send info to the webpage
    mainWindow.webContents.on('did-finish-load', onFinishLoad);
  
    // Emitted when the window is closed.
    mainWindow.on('closed', onWindowClose);
  
    // optionally launch dev tools
    if (config.hasOwnProperty("dev-tools") && config["dev-tools"] === true) {
      mainWindow.openDevTools();
    }
  }
  
  // This method will be called when atom-shell has done everything
  // initialization and ready for creating browser windows.
  app.on('ready', startApp);
  
subject: update projects.json when adding existing project