目录

AppUpdate

An available application update.

import { AppUpdate } from '@mobrowser/api';

Example 

import { app, AppUpdate } from '@mobrowser/api';

const result = await app.checkForUpdate('https://app.com/updates')
if (!result) {
  // No update is available or do nothing.
} else if (typeof result === 'string') {
  // An error occurred while checking for updates.
} else {
  // An update is available.
  const appUpdate: AppUpdate = result
  console.log('Update available: ', appUpdate.version)
}

Properties 

version 

readonly version: string;

The version of the available update.

Example 

import { app } from '@mobrowser/api';

const appUpdate = await app.checkForUpdate('https://app.com/updates')
if (appUpdate && typeof appUpdate !== 'string') {
  console.log('Update available: ', appUpdate.version)
}

Methods 

download() 

download(): Promise<AppUpdateDownloadResult>;

Downloads the application update.

To apply the update, you need to restart or quit the application.

On Windows, the method downloads and extracts the update inside the application directory (AppData\Local\<AppName>\packages). The application directory (AppData\Local\<AppName>\current) is updated after the restart or quit of the application.

On macOS, the method downloads and extracts the update to a temporary directory. The application bundle updates only after quit or restart.

The promise resolves when the update is downloaded. It rejects if the download fails or if the update is dismissed before downloading.

Example 

import { app, AppUpdate } from '@mobrowser/api';

const appUpdate = await app.checkForUpdate('https://app.com/updates')
if (appUpdate && typeof appUpdate !== 'string') {
  const downloadResult = await appUpdate.download()
}

dismiss() 

dismiss(): void;

Dismisses the application update if it is not needed.

This method does nothing if the application update is already downloaded or dismissed.

Example 

import { app } from '@mobrowser/api';

const appUpdate = await app.checkForUpdate('https://app.com/updates')
if (appUpdate && typeof appUpdate !== 'string') {
  console.log('Update available: ', appUpdate.version)
  if (isPatchUpdate(appUpdate.version, app.version)) {
    console.log('Dismissing patch update')
    appUpdate.dismiss()
  }
}

Events 

‘progressChanged’ 

on(event: 'progressChanged', listener: (progress: number) => void): void;
off(event: 'progressChanged', listener: (progress: number) => void): void;

Emitted when the application update progress is changed.

Example 

appUpdate.on('progressChanged', (progress) => {
  console.log(`Download: ${progress}%`)
})
const downloadResult = await appUpdate.download()