Skip to content

Commit

Permalink
fixup! Added SW param check to shouldInstallWorker
Browse files Browse the repository at this point in the history
  • Loading branch information
jkasten2 committed Feb 23, 2021
1 parent 873a47a commit f83aa76
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions src/managers/ServiceWorkerManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,9 @@ export class ServiceWorkerManager {
}
}

// 4. Is a OneSignal ServiceWorker not installed now?, if not and
// notification permissions are enabled we should install.
// This prevents an unnecessary install which saves bandwidth
// 4. Is a OneSignal ServiceWorker not installed now?
// If not and notification permissions are enabled we should install.
// This prevents an unnecessary install of the OneSignal worker which saves bandwidth
const workerState = await this.getActiveState();
Log.debug("[shouldInstallWorker] workerState", workerState);
if (workerState === ServiceWorkerActiveState.None || workerState === ServiceWorkerActiveState.ThirdParty) {
Expand All @@ -173,15 +173,15 @@ export class ServiceWorkerManager {
}

// 5. We have a OneSignal ServiceWorker installed, but did the path or scope of the ServiceWorker change?
if (await this.changedServiceWorkerParams()) {
if (await this.haveParamsChanged()) {
return true;
}

// 6. We have a OneSignal ServiceWorker installed, is there an update?
return this.workerNeedsUpdate();
}

private async changedServiceWorkerParams(): Promise<boolean> {
private async haveParamsChanged(): Promise<boolean> {
// 1. No workerRegistration
const workerRegistration = await this.context.serviceWorkerManager.getRegistration();
if (!workerRegistration) {
Expand Down Expand Up @@ -209,8 +209,12 @@ export class ServiceWorkerManager {
this.config,
this.context.appConfig.appId
);
// We don't care if the only differences is between OneSignal's A(Worker) vs B(WorkerUpdater) filename.
if (serviceWorkerHrefs.indexOf(availableWorker?.scriptURL || "") === -1) {
// 3.1 If we can't get a scriptURL assume it is different
if (!availableWorker?.scriptURL) {
return true;
}
// 3.2 We don't care if the only differences is between OneSignal's A(Worker) vs B(WorkerUpdater) filename.
if (serviceWorkerHrefs.indexOf(availableWorker.scriptURL) === -1) {
Log.info(
"[changedServiceWorkerParams] ServiceWorker herf changing:",
{ a_old: availableWorker?.scriptURL, b_new: serviceWorkerHrefs }
Expand Down

0 comments on commit f83aa76

Please sign in to comment.