Handling application updates

At this point, you should have at least one application with a tracking ID in your Nucleus account.

In this chapter, you have an app called My App whose current version is 0.0.1, as shown in the following screenshot:

Your application can track version changes and execute certain pieces of code each time an update happens.

The API is in the following format:

Nucleus.onUpdate = version => {
// do something with the vesion
}

For the sake of simplicity, let's raise a standard JavaScript alert message on each version update:

  1. Update the main.js file according to the following code:
const { app, BrowserWindow } = require('electron');

const Nucleus = require('electron-nucleus')('Your App ID', {
onlyMainProcess: true,
version:'0.0.1'
});

function createWindow() {
const win = new BrowserWindow({
width: 800,
height: 600,
webPreferences: {
nodeIntegration: true
},
resizable: false
});

win.loadFile('index.html');

// Optional: report an event
Nucleus.track('APP_LAUNCHED');

Nucleus.onUpdate = version => {
win.webContents.executeJavaScript(`
alert('There is a new version available: ${version}');
`);
};}

app.on('ready', createWindow);
Note that we have provided an explicit version of the application this time.
  1. Save these changes and launch the application using the npm start command.
  2. Wait a few seconds before navigating to Analytics and reloading the page. You should see a counter increase in the Real-time users chart. If you don't see these changes, wait a little bit longer and reload the page from time to time.
  3. Go to Account and click the Edit button for the My App entry.
  1. Change the version value to 0.0.2, as shown in the following screenshot:

As you can see, we can only change the version field. The form allows you to notify every client application that a new version of the application has been registered.

  1. Click the Save button and switch back to your Electron application.
  2. You should see a simple dialog saying that there is a new version available:

Note that you can build a more sophisticated user interface with extra buttons to take a look at the release notes, for example, or navigate to your website.

In the next section, we are going to learn how to introduce global server settings.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.135.185.194