2018-03-14 23:21:02 +03:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
"use strict";
|
|
|
|
|
2019-01-17 21:18:31 +03:00
|
|
|
const { BrowserLoader } = ChromeUtils.import(
|
|
|
|
"resource://devtools/client/shared/browser-loader.js"
|
|
|
|
);
|
2018-04-05 22:39:10 +03:00
|
|
|
const require = BrowserLoader({
|
2018-03-14 23:21:02 +03:00
|
|
|
baseURI: "resource://devtools/client/application/",
|
|
|
|
window,
|
|
|
|
}).require;
|
|
|
|
|
|
|
|
const { createFactory } = require("devtools/client/shared/vendor/react");
|
|
|
|
const {
|
|
|
|
render,
|
|
|
|
unmountComponentAtNode,
|
|
|
|
} = require("devtools/client/shared/vendor/react-dom");
|
2018-04-05 22:39:10 +03:00
|
|
|
const Provider = createFactory(
|
|
|
|
require("devtools/client/shared/vendor/react-redux").Provider
|
|
|
|
);
|
|
|
|
const { bindActionCreators } = require("devtools/client/shared/vendor/redux");
|
2019-06-04 17:50:39 +03:00
|
|
|
const { l10n } = require("./src/modules/l10n");
|
2018-04-05 22:39:10 +03:00
|
|
|
|
|
|
|
const { configureStore } = require("./src/create-store");
|
|
|
|
const actions = require("./src/actions/index");
|
2018-03-14 23:21:02 +03:00
|
|
|
|
2019-06-04 16:59:39 +03:00
|
|
|
const { WorkersListener } = require("devtools/client/shared/workers-listener");
|
|
|
|
|
2019-06-07 15:58:16 +03:00
|
|
|
const {
|
2019-07-29 15:59:25 +03:00
|
|
|
addDebugServiceWorkersListener,
|
|
|
|
canDebugServiceWorkers,
|
|
|
|
removeDebugServiceWorkersListener,
|
|
|
|
} = require("devtools/shared/service-workers-debug-helper");
|
2019-06-07 15:58:16 +03:00
|
|
|
|
2019-07-29 15:53:18 +03:00
|
|
|
const { services } = require("./src/modules/services");
|
|
|
|
|
2018-03-14 23:21:02 +03:00
|
|
|
const App = createFactory(require("./src/components/App"));
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Global Application object in this panel. This object is expected by panel.js and is
|
|
|
|
* called to start the UI for the panel.
|
|
|
|
*/
|
|
|
|
window.Application = {
|
2018-04-05 22:39:10 +03:00
|
|
|
async bootstrap({ toolbox, panel }) {
|
|
|
|
this.updateWorkers = this.updateWorkers.bind(this);
|
2018-04-25 10:49:13 +03:00
|
|
|
this.updateDomain = this.updateDomain.bind(this);
|
2019-06-07 15:58:16 +03:00
|
|
|
this.updateCanDebugWorkers = this.updateCanDebugWorkers.bind(this);
|
2018-04-05 22:39:10 +03:00
|
|
|
|
2018-03-14 23:21:02 +03:00
|
|
|
this.mount = document.querySelector("#mount");
|
2018-04-05 22:39:10 +03:00
|
|
|
this.toolbox = toolbox;
|
|
|
|
this.client = toolbox.target.client;
|
|
|
|
|
|
|
|
this.store = configureStore();
|
|
|
|
this.actions = bindActionCreators(actions, this.store.dispatch);
|
2019-01-10 20:26:35 +03:00
|
|
|
this.serviceWorkerRegistrationFronts = [];
|
2018-04-05 22:39:10 +03:00
|
|
|
|
2019-07-29 15:53:18 +03:00
|
|
|
services.init(this.toolbox);
|
2019-06-04 16:59:39 +03:00
|
|
|
|
|
|
|
this.workersListener = new WorkersListener(this.client.mainRoot);
|
|
|
|
this.workersListener.addListener(this.updateWorkers);
|
2018-04-25 10:49:13 +03:00
|
|
|
this.toolbox.target.on("navigate", this.updateDomain);
|
2019-07-29 15:59:25 +03:00
|
|
|
addDebugServiceWorkersListener(this.updateCanDebugWorkers);
|
2018-04-05 22:39:10 +03:00
|
|
|
|
2019-06-07 15:58:16 +03:00
|
|
|
// start up updates for the initial state
|
2018-04-25 10:49:13 +03:00
|
|
|
this.updateDomain();
|
2019-06-07 15:58:16 +03:00
|
|
|
this.updateCanDebugWorkers();
|
2018-04-05 22:39:10 +03:00
|
|
|
await this.updateWorkers();
|
2018-05-09 17:39:55 +03:00
|
|
|
|
2019-06-04 17:50:39 +03:00
|
|
|
await l10n.init(["devtools/application.ftl"]);
|
2018-05-28 11:51:58 +03:00
|
|
|
|
2018-05-09 17:39:55 +03:00
|
|
|
// Render the root Application component.
|
2019-06-04 17:50:39 +03:00
|
|
|
const app = App({
|
|
|
|
client: this.client,
|
|
|
|
fluentBundles: l10n.getBundles(),
|
|
|
|
});
|
2018-05-09 17:39:55 +03:00
|
|
|
render(Provider({ store: this.store }, app), this.mount);
|
2018-04-05 22:39:10 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
async updateWorkers() {
|
2018-06-01 13:36:09 +03:00
|
|
|
const { service } = await this.client.mainRoot.listAllWorkers();
|
2018-04-05 22:39:10 +03:00
|
|
|
this.actions.updateWorkers(service);
|
2018-03-14 23:21:02 +03:00
|
|
|
},
|
|
|
|
|
2018-04-25 10:49:13 +03:00
|
|
|
updateDomain() {
|
|
|
|
this.actions.updateDomain(this.toolbox.target.url);
|
|
|
|
},
|
|
|
|
|
2019-06-07 15:58:16 +03:00
|
|
|
updateCanDebugWorkers() {
|
2019-07-29 15:59:25 +03:00
|
|
|
const canDebugWorkers = canDebugServiceWorkers();
|
2019-06-07 15:58:16 +03:00
|
|
|
this.actions.updateCanDebugWorkers(canDebugWorkers);
|
|
|
|
},
|
|
|
|
|
2018-03-14 23:21:02 +03:00
|
|
|
destroy() {
|
2019-06-04 16:59:39 +03:00
|
|
|
this.workersListener.removeListener();
|
2018-04-25 10:49:13 +03:00
|
|
|
this.toolbox.target.off("navigate", this.updateDomain);
|
2019-07-29 15:59:25 +03:00
|
|
|
removeDebugServiceWorkersListener(this.updateCanDebugWorkers);
|
2018-04-25 10:49:13 +03:00
|
|
|
|
2018-03-14 23:21:02 +03:00
|
|
|
unmountComponentAtNode(this.mount);
|
|
|
|
this.mount = null;
|
2018-04-05 22:39:10 +03:00
|
|
|
this.toolbox = null;
|
|
|
|
this.client = null;
|
2018-03-14 23:21:02 +03:00
|
|
|
},
|
|
|
|
};
|