Contents

Updating Application

This page describes how to enable the automatic update functionality in your application on macOS and Windows.

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.

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

  1. You can check for updates in the background. When a new version of your application is available, you can download and install it automatically and ask the user to restart the application to apply the update.
  2. You can check for updates at the application startup, download and install them, and programmatically restart the application to make sure the user launches the latest version of your application.
  3. You can check for updates on demand when user selects “Check for updates” from the application menu or clicks a button in the settings dialog. If a new version of your application is available, you can ask the user if they want to download and install it.

To let your application check for updates, download and install them, follow the instructions below.

Configuring an update server

First, you need to set up an update server that will host the update files. The update server is a simple HTTP server that hosts the files and allow everyone to download them using a direct link. You can use a third-party service like Amazon S3 or Google Cloud Storage as an update server.

Once you set up the update server, remember its URL. You will need it in the next step.

Checking for updates

Now, let’s add functionality to the application source code that checks for the application updates and installs the new version of the application if it’s available:

std::string kUpdateServerUrl = "https://storage.googleapis.com/app/updates";

// Check for updates.
app->checkForUpdate(kUpdateServerUrl, [](const CheckForUpdateResult &result) {
  // If an update is available, download and install it.
  auto app_update = result.app_update;
  if (app_update) {
    // Get notifications when the update is installed.
    app_update->onAppUpdateInstalled += [](const AppUpdateInstalled &event) {
      // Ask the user to restart the app to apply the update.
    };
    // Download and install the update.
    app_update->install();
  }
});

You decide when and how often your application should check for updates. You can check for updates at the application startup, in the background, or on demand when the user selects “Check for updates” from the application menu or clicks a button in the settings dialog.

The code snippet above shows only a few possibilities of the API you can use to check for updates and install them. The Molybden API allows you to get notifications about the update installation progress, errors, and other events. You can get information about the update, like the app version number. You can dismiss the update if you don’t want to install it and more.

Building the application

Now, you are ready to build your application with the automatic update functionality enabled. To build the application for the current platform, run the following command:

npm run molybden build

This command will build the application, pack it into a native executable, create a native installer, and create the update files you need to upload to the update server.

Uploading the update files

Molybden supports the automatic update functionality on macOS and Windows only. So, it will generate the update files for these platforms only.

Windows

When you build your application on Windows, Molybden will generate the following update files in the ./build-dist/pack directory:

build-dist/
|-- pack/
|   `-- <APP_NAME>-<APP_VERSION>-full.nupkg
|   `-- RELEASES

You need to manually upload the following files to the update server:

  • <APP_NAME>-<APP_VERSION>-full.nupkg — this is the installer for the new version of your application.
  • RELEASES — this file contains the information about the available updates for Windows. It’s a text file with the list of the available updates and their download URLs. You need to update this file on your update server every time you release a new version of your application.

macOS

On macOS Molybden will generate the following update files in the ./build-dist/pack directory:

build-dist/
|-- pack/
|   `-- appcast.xml
|   `-- <APP_NAME>-<APP_VERSION>-<ARCH>.dmg

You need to manually upload the following files to the update server:

  • appcast.xml — this file contains the information about the available updates for macOS. It’s an XML file with the list of the available updates and their download URLs. You need to update this file on your update server every time you release a new version of your application.
  • <APP_NAME>-<APP_VERSION>-<ARCH>.dmg — this is the disk image file with the new version of your application.
On this page
Top