hemangsk / capacitor-app-update

⚡️ Capacitor plugin that assists with app updates.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

capacitor-app-update

maintenance GitHub Workflow Status (branch) npm version license

⚡️ Capacitor plugin that assists with app updates.

🚧 This project is currently under active development and has not yet been sufficiently tested.

This plugin supports retrieving app update information on Android and iOS.
Additionally, this plugin supports in-app updates on Android.

Installation

npm install @robingenz/capacitor-app-update
npx cap sync

On iOS, no further steps are needed.

On Android, register the plugin in your main activity:

import dev.robingenz.capacitor.appupdate.AppUpdate;

public class MainActivity extends BridgeActivity {

  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Initializes the Bridge
    this.init(
        savedInstanceState,
        new ArrayList<Class<? extends Plugin>>() {

          {
            // Additional plugins you've installed go here
            // Ex: add(TotallyAwesomePlugin.class);
            add(AppUpdate.class);
          }
        }
      );
  }
}

Configuration

No configuration required for this plugin.

Usage

import { Plugins } from '@capacitor/core';
import '@robingenz/capacitor-app-update';

/**
 * Supported platform(s): Android, iOS
 * Returns current app version.
 */
const getCurrentAppVersion = async () => {
  const info = await Plugins.AppUpdate.getAppUpdateInfo();
  return info.currentVersion;
};

/**
 * Supported platform(s): Android, iOS
 * Returns available app version.
 */
const getAvailableAppVersion = async () => {
  const info = await Plugins.AppUpdate.getAppUpdateInfo();
  return info.availableVersion;
};

/**
 * Supported platform(s): Android, iOS
 * Opens the app store entry of the app in the Play Store (Android) or App Store (iOS).
 */
const openAppStore = async () => {
  await Plugins.AppUpdate.openAppStore();
};

/**
 * Supported platform(s): Android
 * Performs an immediate in-app update.
 */
const performImmediateUpdate = async () => {
  const info = await Plugins.AppUpdate.getAppUpdateInfo();
  if (info.updateAvailability !== AppUpdateAvailability.UPDATE_AVAILABLE) {
    return;
  }
  if (!info.immediateUpdateAllowed) {
    return;
  }
  await Plugins.AppUpdate.performImmediateUpdate();
};

/**
 * Supported platform(s): Android
 * Starts a flexible in-app update.
 */
const startFlexibleUpdate = async () => {
  const info = await Plugins.AppUpdate.getAppUpdateInfo();
  if (info.updateAvailability !== AppUpdateAvailability.UPDATE_AVAILABLE) {
    return;
  }
  if (!info.flexibleUpdateAllowed) {
    return;
  }
  await Plugins.AppUpdate.startFlexibleUpdate();
};

/**
 * Supported platform(s): Android
 * Completes a flexible in-app update by restarting the app.
 */
const completeFlexibleUpdate = async () => {
  await Plugins.AppUpdate.completeFlexibleUpdate();
};

Test with internal app-sharing

The Android Developers documentation describes how to test in-app updates using internal app sharing: https://developer.android.com/guide/playcore/in-app-updates#internal-app-sharing

API

🚧 WIP

For now, you can take a look at the definitions.ts file.

Changelog

See CHANGELOG.md.

License

See LICENSE.

About

⚡️ Capacitor plugin that assists with app updates.

License:MIT License


Languages

Language:Java 42.3%Language:Swift 25.2%Language:TypeScript 21.8%Language:Objective-C 4.3%Language:Ruby 4.3%Language:JavaScript 2.1%