This module allows to automatically update your application. You only need to install this module and write two lines of code! To publish your updates you just need a simple file hosting, it does not require a dedicated server.
Supported OS:
Install with npm:
npm install --save electron-simple-updater
Insert a link to a hosting where you will store updates.json to main.js. You can find a sample of updates.json in the example
// Just place this code at the entry point of your application:
const updater = require('src/index');
updater.init('https://raw.githubusercontent.com/megahertz/electron-simple-updater/master/example/updates.json');
You can set this link in package.json:updater.url instead of init() argument.
Build your release using electron-builder or another tool. Note: Your application must be signed for automatic updates on macOS. This is a requirement of Squirrel.Mac.
Upload your release with update.json to a hosting. You can
do it manually or use
electron-simple-publisher
to simplify this process. Note: Squirrel.Mac requires a properly prepared
release.json
file. A release in the property url
must be zipped .app file.
That's it!
Now your application will check for updates on start and download it automatically if an update is available. After app is restarted a new version will be loaded. But you can customize it to ask a user if he would like to install updates. See the example for details.
You can set options when calling init() method or in package.json:updater section.
Name | Default | Description |
---|---|---|
autoDownload | true | Automatically download an update when it's found in updates.json |
channel | 'prod' | An application which is built for channel like 'beta' will receive updates only from this channel |
checkUpdateOnStart | true | Check for updates immediately when init() is called |
disabled | false | Disable update feature. This option is set to true automatically for applications built for Mac App Store or Windows Store |
logger | console | You can pass electron-log, winston or another logger with the following interface: { debug(), info(), warn() }. Set it to false if you would like to disable a logging feature |
version | app.getVersion() | Current app version. In most cases, you should not pass this options manually, it is read by electron from version at package.json |
url* | undefined | The only required parameter. This is a URL to updates.json file. You can use templates '{platform}', '{arch}' and '{channel}' in a file name. |
Initialize a package. By default it finish the process if is run by Squirrel.Windows installer.
Sets the url and initialize the electron-simple-updater. Instead of built-in auto-updater init(), this method receives a URL to updates.json.
Return the current updates.json URL.
Asks the server whether there is an update. url must be set before this call. Instead of built-in auto-updater, this method does not start downloading if autoDownload options is set to false.
Start downloading update manually. You can use this method if autoDownload option is set to false
Restarts the app and installs the update after it has been downloaded. It should only be called after update-downloaded has been emitted.
Set one or a few options. Pass an object as the name for multiple set.
These properties are mapped to options
meta object of some events is a data from updates.json
Emitted when there is an error while updating.
Emitted when start downloading update.json file.
Emitted when there is an available update.
Emitted when there is no available update.
Emitted when star downloading an update.
Emitted when an update has been downloaded.
Emitted when the app is run by Squirrel.Windows when installing. The SimpleUpdater creates/removes shortcuts and finishes the process by default.
Licensed under MIT.
Logo was designed by prolko base on the original electron logo.