Code Monkey home page Code Monkey logo

node-webkit-updater's Introduction

node-webkit-updater

This is node-webkit autoupdater.

npm install node-webkit-updater

Covered by tests and works for linux, windows and mac.

How to run the tests

git clone [email protected]:edjafarov/updater.git
cd updater
npm install
cd app
npm install
cd ..
npm test

Quick Start

var pkg = require('../package.json'); // Insert your app's manifest here
var updater = require('node-webkit-updater');
var upd = new updater(pkg);

/* Checks the remote manifest for latest available version and calls the autoupgrading function */
upd.checkNewVersion(function(error, manifest) {
	if (!error) {
		// Insert your user download choice/version comparison code here
		upgradeNow();
	}
});

/* Downloads the new version, unpacks it, replaces the existing files, runs the new version, and exits the old app */
function upgradeNow() {
	var newVersion = upd.download(function(error, filename) {
		if (!error) {
			upd.unpack(filename, function(error, newAppPath) {
				if (!error) {
					upd.runInstaller(newAppPath, [upd.getAppPath(), upd.getAppExec()],{});
					process.exit();
				}
			});
		}
	});
}

API

As a reference you can use the example.

new updater(manifest)

Creates new instance of updater. Manifest could be a package.json of project.

{
    "name": "updapp",
    "version": "0.0.2",
    "author": "Eldar Djafarov <[email protected]>",
    "manifestUrl": "http://localhost:3000/package.json",
    "packages": {
        "mac": "http://localhost:3000/releases/updapp/mac/updapp.dmg",
        "win": "http://localhost:3000/releases/updapp/win/updapp.zip",
        "linux32": "http://localhost:3000/releases/updapp/linux32/updapp.tar.gz"
    }
}

Inside the app manifest, you need to specify where to download packages from for all supported OS'es, a manifest url where this manifest can be found and the current version of the app.

Note that compressed apps are assumed to be downloaded in the format produced by grunt-node-webkit-builder.

updater:checkNewVersion(cb)

Will check the latest available version of the application by requesting the manifest specified in manufestUrl. The callback will be executed if the version was changed.

Callback arguments: error, remote version

updater:download(cb)

Will download the new app version in a temporary folder.

Callback arguments: error, downloaded filepath

updater:unpack(filename, cb)

Will unpack the filename in temporary folder.

Callback arguments: error, unpacked directory

updater:runInstaller(appPath, args, options)

Runs installer

updater:getAppPath()

Returns executed application path

updater:getAppExec()

Returns current application executable

updater:install(copyPath, cb)

Installs the app (copies current application to copyPath)

Callback arguments: error

updater:run(execPath, args, options)

Runs the app from original path.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.