<commit_before># electron-updater 
Cross platform auto-updater for electron apps

[![Build Status](https://travis-ci.org/EvolveLabs/electron-updater.svg?branch=master)](https://travis-ci.org/EvolveLabs/electron-updater)

# Install
There are two separate packages that make up the `electron-updater`. The updater itself runs in your app's main process while the plugins project loads the plugins downloaded by the updater into the render process. If you don't use plugins, then you don't need the second project.

    $ npm install electron-updater --save
    $ npm install electron-plugins --save
    
### Related
See the [`electron-builder`](https://www.npmjs.com/package/electron-builder) project for creating installers for
various platforms.

See the [`sinopia`](https://www.npmjs.com/package/sinopia) project for hosting your own npm packages.

## Features
 * Cross platform (win32, darwin, linux)
 * Update notifications
 * Update electron binaries in place
 * Update your application and dependencies in place
 * Download prebuilt binaries per-platform
 * Side-by-Side update of plugins
 * Leverages npm for distribution
 * Fully based on javascript and node
 * Designed for [`electron`](https://github.com/atom/electron)
 
## Example main.js
```JavaScript
var app = require('app'),
    ipc = require('ipc'),
    util = require('util'),
    BrowserWindow = require('browser-window'),
    updater = require('electron-updater')
  
require('crash-reporter').start()

var mainWindow = null

app.on('window-all-closed', function() {
    if (process.platform != 'darwin')
        app.quit()
})

app.on('ready', function() {
    // Instead of launching your window right away, start the updater
    // to check to see if the app is valid or not.
    // An app is invalid if any of its dependencies or plugins are missing.
    // In this case the updater will begin a 'full' update. Once updated
    // your app will be re-launched.

    updater.on('ready', function () {        
        // This event is called if your app is currently valid.
        // It may be out-of-date but it has all of the necessary
        // dependencies and plugins to launch right now.
        // Your app maybe also receive an update-available event following this

        mainWindow = new BrowserWindow({width: 800, height: 600})
        mainWindow.loadUrl('file://' + __dirname + '/index.html')
        mainWindow.openDevTools({detach:true})        
        mainWindow.on('closed', function() {
            mainWindow = null;
        });
    })
    updater.on('updateRequired', function () {
        // This event is fired if your app is not currently valid at startup.
        // The app must be exited immediately and the auto-updater will be run instead.
        // After the auto-update runs the app will be re-run.
        
        app.quit();
    })
    updater.on('updateAvailable', function () {
        // This event is fired after new versions of plugins have been downloaded and
        // before the app and dependencies are downloaded. Plugins are installed side-by-side
        // so they can be downloaded while the app is running.
        
        // After the app is restarted it will watch for updates and fire the updated required
        // event when newer versions are available.

        if(mainWindow) {
            // Send a message to your view(s)
            mainWindow.webContents.send('update-available');
        }
    })

    updater.start()
})
```

## Example index.js (running in render process)
```JavaScript
var plugins = require('electron-plugins'),
	util = require('util'),
	ipc = require('ipc')

document.addEventListener('DOMContentLoaded', function () {
	var context = { document: document }
	plugins.load(context, function (err, loaded) {
		if(err) return console.error(err)
		console.log('Plugins loaded successfully.')
	})
})

ipc.on('update-available', function () {<commit_msg>Simplifying the  example in the readme.<commit_after># electron-updater 
Cross platform auto-updater for electron apps

[![Build Status](https://travis-ci.org/EvolveLabs/electron-updater.svg?branch=master)](https://travis-ci.org/EvolveLabs/electron-updater)

# Install
There are two separate packages that make up the `electron-updater`. The updater itself runs in your app's main process while the plugins project loads the plugins downloaded by the updater into the render process. If you don't use plugins, then you don't need the second project.

    $ npm install electron-updater --save
    $ npm install electron-plugins --save
    
### Related
See the [`electron-builder`](https://www.npmjs.com/package/electron-builder) project for creating installers for
various platforms.

See the [`sinopia`](https://www.npmjs.com/package/sinopia) project for hosting your own npm packages.

## Features
 * Cross platform (win32, darwin, linux)
 * Update notifications
 * Update electron binaries in place
 * Update your application and dependencies in place
 * Download prebuilt binaries per-platform
 * Side-by-Side update of plugins
 * Leverages npm for distribution
 * Fully based on javascript and node
 * Designed for [`electron`](https://github.com/atom/electron)
 * Works well with [`electron-builder`](https://npmjs.org/package/electron-builder)
 
## Example main.js
```JavaScript
var app = require('app'),
    BrowserWindow = require('browser-window'),
    updater = require('electron-updater')

var mainWindow = null

app.on('ready', function() {
    updater.on('ready', function () {
        mainWindow = new BrowserWindow({width: 800, height: 600})
        mainWindow.loadUrl('file://' + __dirname + '/index.html')
        mainWindow.openDevTools({detach:true})        
        mainWindow.on('closed', function() {
            mainWindow = null;
        })
    })
    updater.on('updateRequired', function () {        
        app.quit();
    })
    updater.on('updateAvailable', function () {
        mainWindow.webContents.send('update-available');
    })
    updater.start()
})
```

## Example index.js (running in render process)
```JavaScript
var plugins = require('electron-plugins'),
	ipc = require('ipc')

document.addEventListener('DOMContentLoaded', function () {
	var context = { document: document }
	plugins.load(context, function (err, loaded) {
		if(err) return console.error(err)
		console.log('Plugins loaded successfully.')
	})
})

ipc.on('update-available', function () {
{'fraction_non_alphanumeric': 0.1150843222985634, 'fraction_numerical': 0.0024984384759525295, 'mean_word_length': 3.3364928909952605, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 11, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 7, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5226407', 'n_tokens_mistral': 1821, 'n_tokens_neox': 1733, 'n_words': 598}