Contents

Application Updates

This page describes how to enable automatic application update functionality in your Molybden application.

Molybden provides a built-in mechanism to check for updates, download the latest version of your application, and install it. This feature is useful when you want to distribute updates to your users without them having to manually download and install the new version of your application.

Enabling automatic updates in your application consists of several steps including:

  1. Setting up an update server.
  2. Adding update functionality to your application.
  3. Building the application.
  4. Uploading the update files to the update server.

We recommend that you read the Updating Application guide to learn more about this process.

In this guide we describe different possibilities of the automatic application update functionality in Molybden.

Overview

The automatic update functionality in Molybden is very flexible. You decide how exactly your application should check for updates, download and install them.

In the following sections, you will learn how to check for updates, download and install them, get information about the update, dismiss a particular update, get notifications about the update installation progress, errors, and other events.

Checking for updates

To check for updates, you need to know the update server URL that you should pass to the checkForUpdate() method as shown below:

std::string kUpdateServerUrl = "https://app.com/updates";
app->checkForUpdate(kUpdateServerUrl, [](const CheckForUpdateResult &result) {
  // Check for updates has been completed.
});

The CheckForUpdateResult object contains the app_update property that represents an application update. If the app_update property is not nullptr, it means that an update is available.

app->checkForUpdate(kUpdateServerUrl, [](const CheckForUpdateResult &result) {
  auto app_update = result.app_update;
  if (app_update) {
    // An update is available.
  }
});

You can get the information about a new version of the application from the app_update object:

std::string new_version = app_update->version();

If there’s an error during the update check, you can get to know about it from the error_message property of the CheckForUpdateResult object:

app->checkForUpdate(kUpdateServerUrl, [](const CheckForUpdateResult &result) {
  if (!result.error_message.empty()) {
    // An error occurred while checking for updates.
  }
});

Installing and dismissing update

If an update is available, you can download and install it by calling the install() method of the AppUpdate object:

app_update->install();

Or you can dismiss the update if you don’t want to install it:

app_update->dismiss();

Dismissing update means that you don’t want to install it right now. You can check for updates later again and the dismissed update will be available for installation again.

Installation process events

Downloading and installing an update may take some time depending on your internet connection speed and the size of the update.

You can get notifications about the update installation progress by subscribing to the onAppUpdateProgressChanged event:

app_update->onAppUpdateProgressChanged +=
    [](const AppUpdateProgressChanged &event) {
      // The progress of the application update in the range 0-100.
      uint16_t progress = event.progress;
    };

If an error occurs during the update installation, you can get to know about it from the onAppUpdateFailed event:

app_update->onAppUpdateFailed += [](const AppUpdateFailed &event) {
  std::string error_msg = event.message;
};

When the update is installed successfully, you will get the onAppUpdateInstalled event:

app_update->onAppUpdateInstalled += [](const AppUpdateInstalled &event) {
  // Ask the user to restart the app to apply the update.
};

Restarting the application

After the update is installed, you can ask the user to restart the application to apply the update or wait for the user to restart the application manually.

To restart the application programmatically, use the application restart functionality.

On this page
Top