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

@objekt/capacitor-app-updater

v1.0.3

Published

CapacitorJS plugin to update the web contents of an app from a remote content server.

Downloads

34

Readme

Introduction

Cross platform CapacitorJS plugin to update the web contents of an app from a remote content server.

How it works

The plugin exposes a single AppUpdater.sync(checksumURL, checkDelay=3600000) function that takes a URL to your hosted web server. The plugin expects a checksum.json file to be accessible on the root of the web server.

When called, the plugin performs the following steps:

  1. Check that the sync process has not already been run recently within a specified time delay.
  2. Load the checksum.json file from the web server.
  3. Compare the checksum of the local device web content files with the server checksums.
  4. If nothing has changed, then terminate the job.
  5. If any checkums differ, then create a new bundle on the device.
  6. Download all files with differing checksums fresh from the web server.
  7. Copy all files with the same checksum over from the local device web content directory.
  8. Ensure all file have downloaded successfully.
  9. Modify the local the Capacitor app config to point to the new release bundle.
  10. Reload the app

Check Delay

As the sync task may delay your app startup time, you may not want to run it everytime the user launches your app. Instead you can specify an optional check delay time in milliseconds as second argument to the sync function to skip syncing if the job ran within the set delay time already. This defaults to 60 minutes.

Running on Web vs Native

Running sync on non-native environments such as the web is simply ignored. For the web version of your Capaitor app, a Service Worker (see Workbox) should instead be used to cache your web app files locally.

Installation

npm install @objekt/capacitor-app-updater

Configuration

This plugin will work without any configuration on Android and iOS in any Capacitor 3 project.

Usage

Step 1 - Basic Implementation (index.js)

Call AppUpdater.sync in your capacitor web app root, e.g. your index.js file as follows:

import { AppUpdater } from '@objekt/capacitor-app-updater';

import { SplashScreen } from '@capacitor/splash-screen';

(async () => {

  // Check for app updates - only if the app has not been launched in the last 60 minutes.
  const didUpdate = await AppUpdater.sync("https://your-web-server-url", 1000*60*60);

  // Stop processing if there was an update, as the updated would have triggered a page reload.
  if (didUpdate) {
    return;
  }

  // Load the app shell.
  await import('./modules/AppShell.js');

  // Hide the native splash screen.
  await SplashScreen.hide();
})();

Step 2 - Build your web application

Follow your normal build process (e.g. webpack, rollup, etc.) to generate a distribution bundle of your app that contains all of the HTML, CSS, JS, and assets that you would publish to your app content server.

Step 3 - Create a checksum file for the build

Create a checksum.json file in the build folder that contains a checksum for the build overall as well as each individual file in the build. The checksums can be generated using any algorithm.

{
  "id":"9d307fdcafb3f6f2fbcd47899df78652936cea00",
  "timestamp":"2022-04-10T15:21:08.406Z",
  "files":[
    {
      "path":"index.html",
      "hash":"064c47308009992f133a44e368cf1dcfdaa9d85e"
    },
    {
      "path":"app.39b812d9.js",
      "hash":"1bd6e3344fbc3363b1faa00d1115378135aac5ce"
    },
    {
      "path":"vendors.70682963.js",
      "hash":"5b055ca612c8e6883decd76258261d85da3de644"
    }
  ]
}

API Reference

Full API documentation here.

Contributors ✨

This project follows the all-contributors specification. Contributions of any kind welcome! (emoji key)

License

MIT