vdonkey
vdonkey

Reputation: 106

How to upgrade a meteor app

My App created by Meteor is now doing upgrading by Meteor's HCP(Hot Code Push), which means the user will get a new version as soon as he restarts the App, without any information or confirm dialog.

HCP is great, but there are two reasons some users don't want the App be upgraded quietly:

  1. New version may have degrades or other risks.
  2. Old version is enough for theirs uses.

So I want to know if there is a way, I can show user a new-version-available dialog describing features of the new version, and ask him whether to upgrade or not. When he agreed, use HCP to do the upgrade work or, download the necessary package by writing code if HCP not usable in this occasion.

By the way I have another question related: Why HCP only work on android phone, how to make it work on iOS phone.

Many thanks in advance for answering any one of the two questions, or both. Thank you.

Upvotes: 0

Views: 114

Answers (1)

dr.dimitru
dr.dimitru

Reputation: 2702

By the way I have another question related: Why HCP only work on android phone, how to make it work on iOS phone.

HCP should work on all platforms in the same way.

To show prompt dialog you have to intercept HCP in Reload._onMigrate hook:

import { Reload } from 'meteor/reload';

Reload._onMigrate(() => {
  const decision = confirm("New version is available, would you like to upgrade now?")
  return [decision]; // Return [false] to manually handle HCP
});

This is a very simple example, you can trigger nice UI/UX element to handle it.

For example we always return [false] in _onMigrate hook. Show to the user nice pop-up. And if user choose to update now, we trigger next function (pick options you need):

// Purge and reload cache for AppCache package
window.applicationCache.swapCache();
window.applicationCache.update();

// Drop ServiceWorker cache
window.caches.keys().then((keys) => {
  keys.forEach((name) => {
    window.caches.delete(name);
  });
}).catch((err) => {
  console.error('window.caches.delete', err);
});

// Unregister Service Worker
SWRegistration.unregister();

// Reload the page
if (window.location.hash || window.location.href.endsWith("#")) {
  window.location.reload();
} else {
  window.location.replace(window.location.href);
}

Upvotes: 1

Related Questions