MCPcopy
hub / github.com/angular/angular / setupUpdate

Method setupUpdate

packages/service-worker/worker/src/driver.ts:1008–1051  ·  view source on GitHub ↗
(manifest: Manifest, hash: string)

Source from the content-addressed store, hash-verified

1006 }
1007
1008 private async setupUpdate(manifest: Manifest, hash: string): Promise<void> {
1009 try {
1010 const newVersion = new AppVersion(
1011 this.scope,
1012 this.adapter,
1013 this.db,
1014 this.idle,
1015 this.debugger,
1016 manifest,
1017 hash,
1018 );
1019
1020 // Firstly, check if the manifest version is correct.
1021 if (manifest.configVersion !== SUPPORTED_CONFIG_VERSION) {
1022 await this.deleteAllCaches();
1023 await this.scope.registration.unregister();
1024 throw new Error(
1025 `Invalid config version: expected ${SUPPORTED_CONFIG_VERSION}, got ${manifest.configVersion}.`,
1026 );
1027 }
1028
1029 // Cause the new version to become fully initialized. If this fails, then the
1030 // version will not be available for use.
1031 await newVersion.initializeFully(this);
1032
1033 // Install this as an active version of the app.
1034 this.versions.set(hash, newVersion);
1035 // Future new clients will use this hash as the latest version.
1036 this.latestHash = hash;
1037
1038 // If we are in `EXISTING_CLIENTS_ONLY` mode (meaning we didn't have a clean copy of the last
1039 // latest version), we can now recover to `NORMAL` mode and start accepting new clients.
1040 if (this.state === DriverReadyState.EXISTING_CLIENTS_ONLY) {
1041 this.state = DriverReadyState.NORMAL;
1042 this.stateMessage = '(nominal)';
1043 }
1044
1045 await this.sync();
1046 await this.notifyClientsAboutVersionReady(manifest, hash);
1047 } catch (e) {
1048 await this.notifyClientsAboutVersionInstallationFailed(manifest, hash, e);
1049 throw e;
1050 }
1051 }
1052
1053 async checkForUpdate(): Promise<boolean> {
1054 let hash: string = '(unknown)';

Callers 1

checkForUpdateMethod · 0.95

Calls 7

deleteAllCachesMethod · 0.95
initializeFullyMethod · 0.95
syncMethod · 0.95
unregisterMethod · 0.80
setMethod · 0.65

Tested by

no test coverage detected