(event: ExtendableEvent)
| 372 | } |
| 373 | |
| 374 | private async ensureInitialized(event: ExtendableEvent): Promise<void> { |
| 375 | // Since the SW may have just been started, it may or may not have been initialized already. |
| 376 | // `this.initialized` will be `null` if initialization has not yet been attempted, or will be a |
| 377 | // `Promise` which will resolve (successfully or unsuccessfully) if it has. |
| 378 | if (this.initialized !== null) { |
| 379 | return this.initialized; |
| 380 | } |
| 381 | |
| 382 | // Initialization has not yet been attempted, so attempt it. This should only ever happen once |
| 383 | // per SW instantiation. |
| 384 | try { |
| 385 | this.initialized = this.initialize(); |
| 386 | await this.initialized; |
| 387 | } catch (error) { |
| 388 | // If initialization fails, the SW needs to enter a safe state, where it declines to respond |
| 389 | // to network requests. |
| 390 | this.state = DriverReadyState.SAFE_MODE; |
| 391 | this.stateMessage = `Initialization failed due to error: ${errorToString(error)}`; |
| 392 | |
| 393 | throw error; |
| 394 | } finally { |
| 395 | // Regardless if initialization succeeded, background tasks still need to happen. |
| 396 | event.waitUntil(this.idle.trigger()); |
| 397 | } |
| 398 | } |
| 399 | |
| 400 | private async handleMessage(msg: MsgAny & {action: string}, from: Client): Promise<void> { |
| 401 | if (isMsgCheckForUpdates(msg)) { |
no test coverage detected