Security News
Internet Archive Hacked, 31 Million Record Compromised
The Internet Archive's "Wayback Machine" has been hacked and defaced, with 31 millions records compromised.
electron-updater
Advanced tools
The electron-updater npm package provides a way to automatically update Electron applications. It integrates with the Electron framework to enable seamless updates of desktop applications built with Electron. The package allows for easy distribution of updates by checking for new versions and downloading them in the background.
Auto Update
This feature allows the application to automatically check for updates and notify the user when an update is available. It can also download and install the updates in the background.
const { autoUpdater } = require('electron-updater');
autoUpdater.checkForUpdatesAndNotify();
Update Events
This feature allows developers to listen for specific events during the update process, such as when an update is available or when it has been downloaded. Developers can then take appropriate actions, like prompting the user or automatically restarting the application.
const { autoUpdater } = require('electron-updater');
autoUpdater.on('update-available', (info) => {
console.log('Update available.');
});
autoUpdater.on('update-downloaded', (info) => {
console.log('Update downloaded; will install in 5 seconds');
setTimeout(() => {
autoUpdater.quitAndInstall();
}, 5000);
});
Manual Update Checks
This feature allows developers to manually trigger an update check instead of relying on automatic checks. This can be useful for giving users the option to check for updates on demand.
const { autoUpdater } = require('electron-updater');
autoUpdater.checkForUpdates();
A lightweight updater for Electron apps that works with GitHub Releases. It is simpler than electron-updater but does not provide as many configuration options or features such as differential updates.
A smart release server for Electron apps that uses GitHub as a backend for serving updates. It is not an npm package but a server that you can deploy. It provides similar functionality but requires more setup compared to electron-updater.
Squirrel is a set of tools for installing and updating Windows and macOS applications. While not an npm package, it is often used in conjunction with Electron to provide update functionality. It is more complex and provides more control over the update process compared to electron-updater.
Cross platform auto-updater for electron apps
There are three main packages that make up the electron-updater
.
$ npm install electron-updater --save
$ npm install electron-plugins --save
$ npm install electron-updater-tools -g
NOTE: Requires electron version
>=0.33.3
.
The electron-updater package itself runs in your app's main process and does the actual updating. The electron-plugins project specifically loads the plugins downloaded by the updater in the render process. The third project, electron-updater-tools contains various scripts useful for building native electron addons as well as linking plugins during development time.
Integrate the electron-updater into your electron main process. Below is a simplified example of the Electron Quick Start code with the electron-updater
mixed in.
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()
})
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 () {
console.log('there is an update available for download')
})
By default errors are logged to both the console and a file. The default log file location is obtained by getting the AppDirectory.userData() folder: {userData}/logs/updater.log
. Additionally you can replace the default logger or simply handle errors manually with the below optional API's:
updater.on('error', function (err) {
// todo: manually handle errors here in addition to default logger behavior...
});
// The logger signature is essentially the same as the console.
var customLogger = {
log: console.log,
error: console.error,
info: console.info,
warn: console.warn,
debug: console.debug
};
updater.start(customLogger);
There are two kinds of updates you can publish:
Both kinds of updatable packages are distributed through npm. This means that publishing updates to your application and plugins are essentially done like this:
$ npm pack
$ npm pub
The application will periodically check npm for updates to any packages and update them when it can.
If you are developing a commercial application, or just want to control distribution yourself, you should host your own packages on your own npm server.
Add a path to your registry in the applications package.json
:
"registry": "http://npm.mycompany.com:4873",
To tell npm to use this registry also, create a .npmrc file in your application root directory containing:
registry=http://npm.mycompany.com:4873
Fortunately, hosting your own npm server is very easy to do with sinopia.
$ npm install sinopia -g
$ sinopia
To run sinopia as a service, you can use forever.
$ npm install forever -g
$ forever start sinopia
Plugins are different than normal dependencies. To establish a link to a plugin, add a plugins
entry into your applications package.json
:
"dependencies": {
# ...
},
"plugins": {
"electron-updater-example-plugin": "~0.1.0"
},
When your application runs it will download and install these plugins into your users AppDirectory.userData() folder. The main benefits of plugins is:
In the userData
folder there is also a .current
file created, which is used to maintain the list of currently installed plugins. You can add items to that file to install non-default plugins.
Until there is better documentation on this, see these issues for answers:
See the electron-builder
project for creating installers for
various platforms.
FAQs
Cross platform updater for electron applications
The npm package electron-updater receives a total of 161,853 weekly downloads. As such, electron-updater popularity was classified as popular.
We found that electron-updater demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
The Internet Archive's "Wayback Machine" has been hacked and defaced, with 31 millions records compromised.
Security News
TC39 is meeting in Tokyo this week and they have approved nearly a dozen proposals to advance to the next stages.
Security News
Our threat research team breaks down two malicious npm packages designed to exploit developer trust, steal your data, and destroy data on your machine.