Update notification for service workers
npm install ember-service-worker-update-notifyAdds a service-worker-update-notify service and
component which displays a reload link if the service-worker has found an update.
The component will show a message to the user when the availability of an update
has been detected. Overwrite the default message using the component in block form:
``handlebars`
A new version is available, click here to update.
The service allows you to react to an app update in a more programmatic manner, e.g.
you could force reload the app. The service emits an update event once an update
has been detected. Here is an example of an application route that reloads the app
automatically:
`js
import Route from '@ember/routing/route';
import { inject as service } from '@ember/service';
export default class ApplicationRoute extends Route {
@service
serviceWorkerUpdateNotify;
beforeModel() {
this.serviceWorkerUpdateNotify.on('update', () => {
window.location.reload();
});
}
}
`
The poll interval can be configured in your config/environment.js with:
`js
module.exports = function(environment) {
let ENV = {
'ember-service-worker-update-notify': {
pollingInterval: 1200000 // Default is 20min
}
};
return ENV;
};
`
Testing this in your app should mainly be concerned with presence
and and what it looks like.
During testing, the polling will be disabled,
and the reveal of the "New version available" content
is controlled by a promise set on the window.setupServiceWorkerUpdater
In your tests, two helpers will aid you in asserting
presence and appearance: ,hasServiceWorkerUpdate
and .
`js
// ...
import {
setupServiceWorkerUpdater,
hasServiceWorkerUpdate
} from 'ember-service-worker-update-notify/test-support/updater';
module('Application | Index', function(hooks) {
setupApplicationTest(hooks);
setupServiceWorkerUpdater(hooks);
test('the update is shown', async function(assert) {
// assert that the content is not shown
await serviceWorkerUpdate();
// assert that the content is shown
});
});
`
`bash`
yarn add --dev ember-concurrency # peer-dependency
yarn add --dev ember-service-worker-update-notify
- git clone this repositorycd ember-service-worker-update-notify
- npm install
-
- npm run lint:hbsnpm run lint:js
- npm run lint:js -- --fix
-
- ember test – Runs the test suite on the current Ember versionember test --server
- – Runs the test suite in "watch mode"ember try:each
- – Runs the test suite against multiple Ember versions
- ember serve`
- Visit the dummy application at http://localhost:4200.
For more information on using ember-cli, visit https://ember-cli.com/.
This project is licensed under the MIT License.