// Copyright 2014 The Flutter Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. /** * This script installs service_worker.js to provide PWA functionality to * application. For more information, see: * https://developers.google.com/web/fundamentals/primers/service-workers */ if (!_flutter) { var _flutter = {}; } _flutter.loader = null; (function() { "use strict"; class FlutterLoader { /** * Creates a FlutterLoader, and initializes its instance methods. */ constructor() { // TODO: Move the below methods to "#private" once supported by all the browsers // we support. In the meantime, we use the "revealing module" pattern. // Watchdog to prevent injecting the main entrypoint multiple times. this._scriptLoaded = null; // Resolver for the pending promise returned by loadEntrypoint. this._didCreateEngineInitializerResolve = null; // Called by Flutter web. // Bound to `this` now, so "this" is preserved across JS <-> Flutter jumps. this.didCreateEngineInitializer = this._didCreateEngineInitializer.bind(this); } /** * Initializes the main.dart.js with/without serviceWorker. * @param {*} options * @returns a Promise that will eventually resolve with an EngineInitializer, * or will be rejected with the error caused by the loader. */ loadEntrypoint(options) { const { entrypointUrl = "main.dart.js", serviceWorker, } = (options || {}); return this._loadWithServiceWorker(entrypointUrl, serviceWorker); } /** * Resolves the promise created by loadEntrypoint. * Called by Flutter through the public `didCreateEngineInitializer` method, * which is bound to the correct instance of the FlutterLoader on the page. * @param {*} engineInitializer */ _didCreateEngineInitializer(engineInitializer) { if (typeof this._didCreateEngineInitializerResolve != "function") { console.warn("Do not call didCreateEngineInitializer by hand. Start with loadEntrypoint instead."); } this._didCreateEngineInitializerResolve(engineInitializer); // Remove the public method after it's done, so Flutter Web can hot restart. delete this.didCreateEngineInitializer; } _loadEntrypoint(entrypointUrl) { if (!this._scriptLoaded) { console.debug("Injecting