npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@capawesome/capacitor-app-update

v6.0.0

Published

Capacitor plugin that assists with app updates.

Downloads

64,230

Readme

@capawesome/capacitor-app-update

Capacitor plugin that assists with app updates. It supports retrieving app update information on Android and iOS and supports in-app updates on Android.

Installation

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

Android Variables

This plugin will use the following project variables (defined in your app’s variables.gradle file):

  • $androidPlayAppUpdateVersion version of com.google.android.play:app-update (default: 2.1.0)
  • $androidPlayServicesBaseVersion version of com.google.android.gms:play-services-base (default: 18.0.1)

Configuration

No configuration required for this plugin.

Demo

A working example can be found here: robingenz/capacitor-plugin-demo

Usage

import { Capacitor } from '@capacitor/core';
import { AppUpdate } from '@capawesome/capacitor-app-update';

const getCurrentAppVersion = async () => {
  const result = await AppUpdate.getAppUpdateInfo();
  if (Capacitor.getPlatform() === 'android') {
    return result.currentVersionCode;
  } else {
    return result.currentVersionName;
  }
};

const getAvailableAppVersion = async () => {
  const result = await AppUpdate.getAppUpdateInfo();
  if (Capacitor.getPlatform() === 'android') {
    return result.availableVersionCode;
  } else {
    return result.availableVersionName;
  }
};

const openAppStore = async () => {
  await AppUpdate.openAppStore();
};

const performImmediateUpdate = async () => {
  const result = await AppUpdate.getAppUpdateInfo();
  if (result.updateAvailability !== AppUpdateAvailability.UPDATE_AVAILABLE) {
    return;
  }
  if (result.immediateUpdateAllowed) {
    await AppUpdate.performImmediateUpdate();
  }
};

const startFlexibleUpdate = async () => {
  const result = await AppUpdate.getAppUpdateInfo();
  if (result.updateAvailability !== AppUpdateAvailability.UPDATE_AVAILABLE) {
    return;
  }
  if (result.flexibleUpdateAllowed) {
    await AppUpdate.startFlexibleUpdate();
  }
};

const completeFlexibleUpdate = async () => {
  await AppUpdate.completeFlexibleUpdate();
};

API

getAppUpdateInfo(...)

getAppUpdateInfo(options?: GetAppUpdateInfoOptions | undefined) => Promise<AppUpdateInfo>

Returns app update informations.

Only available on Android and iOS.

| Param | Type | | ------------- | --------------------------------------------------------------------------- | | options | GetAppUpdateInfoOptions |

Returns: Promise<AppUpdateInfo>


openAppStore(...)

openAppStore(options?: OpenAppStoreOptions | undefined) => Promise<void>

Opens the app store entry of the app in the Play Store (Android) or App Store (iOS).

Only available on Android and iOS.

| Param | Type | | ------------- | ------------------------------------------------------------------- | | options | OpenAppStoreOptions |


performImmediateUpdate()

performImmediateUpdate() => Promise<AppUpdateResult>

Performs an immediate in-app update.

Only available on Android.

Returns: Promise<AppUpdateResult>


startFlexibleUpdate()

startFlexibleUpdate() => Promise<AppUpdateResult>

Starts a flexible in-app update.

Only available on Android.

Returns: Promise<AppUpdateResult>


completeFlexibleUpdate()

completeFlexibleUpdate() => Promise<void>

Completes a flexible in-app update by restarting the app.

Only available on Android.


addListener('onFlexibleUpdateStateChange', ...)

addListener(eventName: 'onFlexibleUpdateStateChange', listenerFunc: (state: FlexibleUpdateState) => void) => Promise<PluginListenerHandle>

Adds a flexbile in-app update state change listener.

Only available on Android.

| Param | Type | | ------------------ | --------------------------------------------------------------------------------------- | | eventName | 'onFlexibleUpdateStateChange' | | listenerFunc | (state: FlexibleUpdateState) => void |

Returns: Promise<PluginListenerHandle>


removeAllListeners()

removeAllListeners() => Promise<void>

Remove all listeners for this plugin.


Interfaces

AppUpdateInfo

| Prop | Type | Description | Since | | --------------------------------- | ----------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----- | | currentVersionName | string | The current version name of the app. On Android, this is the versionName from the android/app/build.gradle file. On iOS, this is the CFBundleShortVersionString from the Info.plist file. Only available on Android and iOS. | 5.1.0 | | availableVersionName | string | The available version name of the update. On iOS, this is the CFBundleShortVersionString from the Info.plist file. Only available on iOS. | 5.1.0 | | currentVersionCode | string | The current version code of the app. On Android, this is the versionCode from the android/app/build.gradle file. On iOS, this is the CFBundleVersion from the Info.plist file. Only available on Android and iOS. | 5.1.0 | | availableVersionCode | string | The available version code of the update. On Android, this is the versionCode from the android/app/build.gradle file. Only available on Android. | 5.1.0 | | availableVersionReleaseDate | string | Release date of the update in ISO 8601 (UTC) format. Only available on iOS. | | | updateAvailability | AppUpdateAvailability | The app update availability. Only available on Android and iOS. | | | updatePriority | number | In-app update priority for this update, as defined by the developer in the Google Play Developer API. Only available on Android. | | | immediateUpdateAllowed | boolean | true if an immediate update is allowed, otherwise false. Only available on Android. | | | flexibleUpdateAllowed | boolean | true if a flexible update is allowed, otherwise false. Only available on Android. | | | clientVersionStalenessDays | number | Number of days since the Google Play Store app on the user's device has learnt about an available update if an update is available or in progress. Only available on Android. | | | installStatus | FlexibleUpdateInstallStatus | Flexible in-app update install status. Only available on Android. | | | minimumOsVersion | string | The minimum version of the operating system required for the app to run in iOS. Only available on iOS. | |

GetAppUpdateInfoOptions

| Prop | Type | Description | | ------------- | ------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | country | string | The two-letter country code for the store you want to search. See http://en.wikipedia.org/wiki/ISO_3166-1_alpha-2 for a list of ISO Country Codes. Only available on iOS. |

OpenAppStoreOptions

| Prop | Type | Description | | ------------- | ------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | country | string | The two-letter country code for the store you want to search. See http://en.wikipedia.org/wiki/ISO_3166-1_alpha-2 for a list of ISO Country Codes. Only available on iOS. |

AppUpdateResult

| Prop | Type | | ---------- | ------------------------------------------------------------------- | | code | AppUpdateResultCode |

PluginListenerHandle

| Prop | Type | | ------------ | ----------------------------------------- | | remove | () => Promise<void> |

FlexibleUpdateState

| Prop | Type | Description | | -------------------------- | ----------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------- | | installStatus | FlexibleUpdateInstallStatus | Flexible in-app update install status. | | bytesDownloaded | number | Returns the number of bytes downloaded so far. undefined if the install status is other than DOWNLOADING. | | totalBytesToDownload | number | Returns the total number of bytes to be downloaded for this update. undefined if the install status is other than DOWNLOADING. |

Enums

AppUpdateAvailability

| Members | Value | | -------------------------- | -------------- | | UNKNOWN | 0 | | UPDATE_NOT_AVAILABLE | 1 | | UPDATE_AVAILABLE | 2 | | UPDATE_IN_PROGRESS | 3 |

FlexibleUpdateInstallStatus

| Members | Value | | ----------------- | --------------- | | UNKNOWN | 0 | | PENDING | 1 | | DOWNLOADING | 2 | | INSTALLING | 3 | | INSTALLED | 4 | | FAILED | 5 | | CANCELED | 6 | | DOWNLOADED | 11 |

AppUpdateResultCode

| Members | Value | Description | | ------------------- | -------------- | ------------------------------------------------------------------------------------------- | | OK | 0 | The user has accepted the update. | | CANCELED | 1 | The user has denied or cancelled the update. | | FAILED | 2 | Some other error prevented either the user from providing consent or the update to proceed. | | NOT_AVAILABLE | 3 | No update available. | | NOT_ALLOWED | 4 | Update type not allowed. | | INFO_MISSING | 5 | App update info missing. You must call getAppUpdateInfo() before requesting an update. |

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/test

Changelog

See CHANGELOG.md.

License

See LICENSE.

Credits

This plugin is based on the Capacitor App Update plugin. Thanks to everyone who contributed to the project!