Handles Electron application updates, IN THE MOST BASIC WAY.
npm install electron-basic-updater
$ npm install --save electron-basic-updater
`
Now, inside the main.js file, call it like this:
`
const Electron = require('electron');
const Application = Electron.app;
const EBU = require('electron-basic-updater');
Application.on('ready', function(){
// Initiate the module
EBU.init({
'api': 'http:// .... ' // The API EBU will talk to
});
});
`
That's it. Now, you can use `EBU.check()` to trigger the update process; EBU will first check for updates, if there was a new update, EBU will download it and extract it to the application folder. Inside a window you can use it like this:
`
`
---
API
$3
* setup (object) The module setup
* api (string) The URL EBU will call to check for updates.
logFile (string) [optional] The file to log the update process updates and errors to it, pass FALSE* to omit logging . Defaults to "updater-log.txt".
* requestOptions (object) [optional] The global options for the HTTP requests EBU will make to check for updates and download them. EBU uses the cool restler for these requests, and the requestOptions will be used for all the requests (the full options list). You can use this option to pass an accessToken or a username and password along with the request, or even send some extra data along with the request through the data property.
`
EBU.init({
'api': 'http:// ...',
'requestOptions': {'accessToken': ..., 'data': {'group': 'friends'}}
});
`
* callback (function) [optional] The callback that will be trigger at the end of the process, whether the update was a success or not. You can set the callback here, or you can pass it directly to check( ... ), I use the later option, to be able to console.log() the error in the DevTools.
`
EBU.init({
'callback': function(error){ ... }
});
`
$3
Will check for an update, if an update was found, will download it and install it! As mentioned, this method must be tirggerd, EBU wont check for updates on its own.
* callback The update result callback
---
The update server
And I mean this in the most simple way possible. This server/API will recieve one request, which is the check for updates, and will send one response of :
* New update: {"last": " [the new version] ", "source": " [the .zip file url] "} EBU wont make any version comparsions, it will simply download the source url and extract it. So, you will need to handle this on your side, EBU sends (POST-type request) you the client's current version (as current), you can use this to send the correct update!
* Any other value, to cancel the update
My current update server (for the app I descriped above) is simple:
`
print json_encode([
'last' => '1.0.1',
'source' => 'http:// ... /update.zip'
]);
`
I change this manually and tell the guys to hit the "update" button, which will trigger .check()`