• Stars
    star
    474
  • Rank 92,640 (Top 2 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 10 years ago
  • Updated about 2 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Update NW.js applications.

node-webkit-updater

npm Join the chat at https://gitter.im/nwjs/nwjs

npm i -D node-webkit-updater

It gives you low-level API to:

  1. Check the manifest for version (from your running "old" app).
  2. If the version is different from the running one, download new package to a temp directory.
  3. Unpack the package in temp.
  4. Run new app from temp and kill the old one (i.e. still all from the running app).
  5. The new app (in temp) will copy itself to the original folder, overwriting the old app.
  6. The new app will run itself from original folder and exit the process.

You should build this logic by yourself though. As a reference you can use example.

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

Examples

API

new updater(manifest, options)

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

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

Params

  • manifest object - See the manifest schema below.
  • options object - Optional

updater.checkNewVersion(cb)

Will check the latest available version of the application by requesting the manifest specified in manifestUrl.

The callback will always be called; the second parameter indicates whether or not there's a newer version. This function assumes you use Semantic Versioning and enforces it; if your local version is 0.2.0 and the remote one is 0.1.23456 then the callback will be called with false as the second paramter. If on the off chance you don't use semantic versioning, you could manually download the remote manifest and call download if you're happy that the remote version is newer.

Params

  • cb function - Callback arguments: error, newerVersionExists (Boolean), remoteManifest

updater.download(cb, newManifest)

Downloads the new app to a template folder

Params

  • cb function - called when download completes. Callback arguments: error, downloaded filepath
  • newManifest Object - see manifest schema below

Returns: Request - Request - stream, the stream contains manifest property with new manifest and 'content-length' property with the size of package.

updater.getAppPath()

Returns executed application path

Returns: string

updater.getAppExec()

Returns current application executable

Returns: string

updater.unpack(filename, cb, manifest)

Will unpack the filename in temporary folder. For Windows, unzip is used (which is not signed).

Params

  • filename string
  • cb function - Callback arguments: error, unpacked directory
  • manifest object

updater.runInstaller(appPath, args, options)

Runs installer

Params

  • appPath string
  • args array - Arguments which will be passed when running the new app
  • options object - Optional

Returns: function

updater.install(copyPath, cb)

Installs the app (copies current application to copyPath)

Params

  • copyPath string
  • cb function - Callback arguments: error

updater.run(execPath, args, options)

Runs the app from original app executable path.

Params

  • execPath string
  • args array - Arguments passed to the app being ran.
  • options object - Optional. See spawn from nodejs docs.

Note: if this doesn't work, try gui.Shell.openItem(execPath) (see node-webkit Shell).


Manifest Schema

An example manifest:

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

The manifest could be a package.json of project, but doesn't have to be.

manifest.name

The name of your app. From time, it is assumed your Mac app is called <manifest.name>.app, your Windows executable is <manifest.name>.exe, etc.

manifest.version

semver version of your app.

manifest.manifestUrl

The URL where your latest manifest is hosted; where node-webkit-updater looks to check if there is a newer version of your app available.

manifest.packages

An "object" containing an object for each OS your app (at least this version of your app) supports; mac, win, linux32, linux64.

manifest.packages.{mac, win, linux32, linux64}.url

Each package has to contain a url property pointing to where the app (for the version & OS in question) can be downloaded.

manifest.packages.{mac, win, linux32, linux64}.execPath (Optional)

It's assumed your app is stored at the root of your package, use this to override that and specify a path (relative to the root of your package).

This can also be used to override manifest.name; e.g. if your manifest.name is helloWorld (therefore helloWorld.app on Mac) but your Windows executable is named nw.exe. Then you'd set execPath to nw.exe


Troubleshooting

Mac

If you get an error on Mac about too many files being open, run ulimit -n 10240

Windows

On Windows, there is no "unzip" command built in by default. As a result, this project uses a third party "unzip.exe" in order to extract the downloaded update. On the NWJS site, in the "How to package and distribute your apps" file, one of the recommended methods of distribution is using EnigmaVirtualBox to package the app, nw.exe, and required DLLs into a single EXE file. This method works great for distribution, but unfortunately breaks node-webkit-updater, because it wraps the required unzip.exe file inside of the created EnigmaVirtualBox EXE. As a result, it is not possible to use EnigmaVirtualBox to distribute your app if you plan on using node-webkit-updater. Try using InnoSetup instead.

Contributing

See CONTRIBUTING.md

More Repositories

1

nw-sample-apps

Sample Apps
JavaScript
1,945
star
2

nw-builder

Build NW.js applications for Linux, MacOS and Windows
JavaScript
1,683
star
3

Web2Executable

Uses NW.js to generate "native" apps for already existing web apps.
Python
900
star
4

nw-vue-cli-example

NW.js, Vue-CLI 4, Vue-DevTools
JavaScript
104
star
5

nwjs-shell-builder

NW.js (node-webkit) shell script builder and packager scripts
Shell
82
star
6

nw-vue3-boilerplate

NW.js + Vue 3 + Vite + Pinia + Vue-Router + Vitest
JavaScript
58
star
7

create-desktop-shortcuts

Easy API to create desktop shortcuts with Node
JavaScript
47
star
8

nw-dev

A drop-in library for nw.js development
32
star
9

nw-angular-example

An example of integrating Angular with NW.js
TypeScript
27
star
10

nw-local-server-example

An example of using a local webserver in NW.js
HTML
22
star
11

nwjs-packager

Build your NW.js app and generate archives, packages, setup files and more!
JavaScript
19
star
12

nw-vue-devtools

devDependency to add Vue-DevTools into NW.js
JavaScript
14
star
13

find-in-nw

Adds "Ctrl+F" find box to highlight text in the DOM
HTML
13
star
14

nwjs-print-server

Websocket server to interface a website with a printer
JavaScript
11
star
15

nw-tray-example

Example tray app in NW.js
JavaScript
10
star
16

nw-splash-screen-example

Show splash screen until main application loads.
HTML
9
star
17

nw-img-vue

Caches copies of online images locally and loads them first if available
Vue
9
star
18

nw-splasher

Small library to show a splash screen until main application loads.
JavaScript
9
star
19

window-communication-example

Example of communication between windows in NW.js
HTML
7
star
20

nw-electron-adapter

An adapter for Electron's API inside NW.js
JavaScript
6
star
21

nwdc

NW.js debug console for Windows
JavaScript
6
star
22

node-default-application-protocol

A cross-platform, Node tool for setting a custom URI protocol handler on an OS
JavaScript
6
star
23

get-windows-shortcut-properties

A Node.js library to get the properties of a Windows .lnk or .url shortcut file
JavaScript
6
star
24

nw-programmatic-folder-select

Programmatically open a native "Folder select" dialog
JavaScript
5
star
25

nwutils.github.io

NW Utils website
Vue
4
star
26

frameless-example

NW.js frameless window example
HTML
4
star
27

electron-to-nwjs

Build an Electron app as a NW.js app
JavaScript
4
star
28

nw-utils-builder

WIP: Do not use | Experimental NW.js build tool
JavaScript
4
star
29

SnowPack-nw

Boilerplate for start multi desktop App development using SnowPack
CSS
4
star
30

nw-bg-script-example

A demo of how JavaScript runs in NW.js
HTML
4
star
31

nw-global-installer

NW.js global install tool (WIP)
4
star
32

nw-jquery-example

An example of integrating JQuery with NW.js
JavaScript
4
star
33

nw-splasher-auto-update

WIP: A tool to automate checking for updates and downloading newer versions
JavaScript
3
star
34

nw-utils

Utilities and helper functions for NW.js
JavaScript
3
star
35

nw-utils-settings

WIP: Utility for Saving/Loading app settings
2
star
36

nw-selenium-python-example

An example of using Selenium for end-to-end testing of NW.js apps via Python
Python
2
star
37

nw-dev-keybindings

Open dev tools and refresh keybindings for NW.js
JavaScript
2
star
38

nw-react-cra-example

An example of integrating Create React App with NW.js
JavaScript
2
star
39

nw-window-manager

WIP: NW.js Window Management library
2
star
40

nw-test-suite

WIP: Testing suite for NW.js API
HTML
2
star
41

nw-react-next-example

An example of integrating Next with NW.js
JavaScript
2
star
42

nw-node-addon-example

Examples of building NW.js Node Addons via node-gyp (nan, cmake and ffi coming soon!)
JavaScript
2
star
43

faux-notifications

WIP - Library to create custom desktop notifications in NW.js
1
star
44

nw-cypress-example

NW.js + Cypress (WIP)
JavaScript
1
star
45

nw-selenium-javascript-example

An example of using Selenium for end-to-end testing of NW.js apps via JavaScript
JavaScript
1
star
46

nw-puppeteer-example

An example of using NW.js via Puppeteer.
JavaScript
1
star
47

base-volta-off-of-nwjs

Tool to update the Volta config in package.json so Node match's your NW.js version
JavaScript
1
star
48

limited-node-access-example

WIP: Example of a project with an iframe that has limited access to Node.js in NW.js
1
star
49

.github

1
star
50

nw-screen-capture

WIP: A library for setting up a screen capture menu in NW.js
1
star
51

nw-rich-tray-example

WIP: This is an example repo for a frameless window popup for a tray app in NW.js
1
star
52

nw-patches

Understand how NW.js changes upstream behaviour
1
star
53

nw-subdir-example

Example repo for having a parent package.json file that runs NW.js pointed to a child folder with its own package.json
HTML
1
star