UNPKG

ember-cli-new-version

Version:

A convention based update notification for Ember. With this addon, you can detect a new version and notify the user to refresh the page

45 lines (37 loc) 1.29 kB
import Component from '@glimmer/component'; import { tracked } from '@glimmer/tracking'; import { inject as service } from '@ember/service'; import { action } from '@ember/object'; export default class NewVersionNotifier extends Component { /** @type {import("ember-cli-new-version/services/new-version").default} */ @service newVersion; @tracked updateMessage = this.args.updateMessage ?? 'This application has been updated from version {oldVersion} to {newVersion}. Please save any work, then refresh browser to see changes.'; @tracked showReload = this.args.showReload ?? true; @tracked reloadButtonText = this.args.reloadButtonText ?? 'Reload'; /** * @returns {string | undefined} */ get message() { if (this.newVersion.isNewVersionAvailable) { return this.updateMessage .replace('{oldVersion}', this.newVersion.currentVersion) .replace('{newVersion}', this.newVersion.latestVersion); } return undefined; } @action close(event) { event.preventDefault(); this.newVersion.ignoreVersion(this.newVersion.latestVersion); return false; } @action reload(event) { event.preventDefault(); if (typeof window !== 'undefined' && window.location) { window.location.reload(true); } } }