Skip to content

Commit

Permalink
feat: add workbox-window (messageskipwaiting)
Browse files Browse the repository at this point in the history
  • Loading branch information
BoussonKarel committed Dec 30, 2022
1 parent 27ce84d commit 217f49b
Show file tree
Hide file tree
Showing 3 changed files with 1,007 additions and 938 deletions.
18 changes: 14 additions & 4 deletions addon/services/service-worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import Service from '@ember/service';
import Evented from '@ember/object/evented';
import { debug } from '@ember/debug';
import { getOwner } from '@ember/application';
import { Workbox } from 'workbox-window';

const EventedService = Service.extend(Evented);

Expand All @@ -22,6 +23,8 @@ const EventedService = Service.extend(Evented);
* "unregistrationComplete" - all sw are unregistered
*/
export default class ServiceWorker extends EventedService {
workbox;

get config() {
return getOwner(this).resolveRegistration('config:environment');
}
Expand All @@ -48,13 +51,20 @@ export default class ServiceWorker extends EventedService {
}
}

forceActivate() {
if (this.wb) {
this.wb.messageSkipWaiting();
}
}

async register(swFile) {
try {
const registration = await this.sw.register(
`${this.config.rootURL}${swFile}`
);
const swUrl = `${this.config.rootURL}${swFile}`;
this.wb = new Workbox(swUrl);

return this._onRegistration(registration);
return this.wb.register().then((registration) => {
return this._onRegistration(registration);
});
} catch (error) {
this.trigger('error', error);
this._log('Service Worker registration failed: ', error);
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,14 @@
"broccoli-plugin": "^4.0.7",
"chalk": "^4.1.0",
"debug": "^4.3.3",
"ember-auto-import": "^2.4.1",
"ember-cli-babel": "^7.26.11",
"ember-cli-htmlbars": "^6.0.1",
"glob": "^7.2.0",
"pretty-bytes": "^5.6.0",
"rimraf": "^3.0.1",
"workbox-build": "^5.0.0"
"workbox-build": "^6.5.4",
"workbox-window": "^6.5.4"
},
"devDependencies": {
"@commitlint/cli": "^16.1.0",
Expand All @@ -77,7 +79,6 @@
"chai": "^4.3.6",
"commitizen": "^4.2.4",
"cz-conventional-changelog": "^3.3.0",
"ember-auto-import": "^2.4.1",
"ember-cli": "~4.4.1",
"ember-cli-code-coverage": "^1.0.3",
"ember-cli-dependency-checker": "^3.3.1",
Expand Down
Loading

0 comments on commit 217f49b

Please sign in to comment.