Skip to content

Commit

Permalink
Use the new "reporttelemetry" in more viewer components
Browse files Browse the repository at this point in the history
By utilizing the recently added "reporttelemetry" event, we can avoid having to manually pass in `externalServices` to a number of viewer components.
  • Loading branch information
Snuffleupagus committed Sep 20, 2023
1 parent f2d75d9 commit 9008985
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 18 deletions.
7 changes: 2 additions & 5 deletions web/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -615,8 +615,7 @@ const PDFViewerApplication = {
appConfig.toolbar,
eventBus,
l10n,
await this._nimbusDataPromise,
externalServices
await this._nimbusDataPromise
);
} else {
this.toolbar = new Toolbar(appConfig.toolbar, eventBus, l10n);
Expand All @@ -626,8 +625,7 @@ const PDFViewerApplication = {
if (appConfig.secondaryToolbar) {
this.secondaryToolbar = new SecondaryToolbar(
appConfig.secondaryToolbar,
eventBus,
externalServices
eventBus
);
}

Expand Down Expand Up @@ -2141,7 +2139,6 @@ const PDFViewerApplication = {
eventBus._off("fileinputchange", webViewerFileInputChange);
eventBus._off("openfile", webViewerOpenFile);
}

if (typeof PDFJSDev !== "undefined" && PDFJSDev.test("MOZCENTRAL")) {
eventBus._off("reporttelemetry", webViewerReportTelemetry);
}
Expand Down
12 changes: 7 additions & 5 deletions web/secondary_toolbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class SecondaryToolbar {
* @param {SecondaryToolbarOptions} options
* @param {EventBus} eventBus
*/
constructor(options, eventBus, externalServices) {
constructor(options, eventBus) {
this.toolbar = options.toolbar;
this.toggleButton = options.toggleButton;
this.buttons = [
Expand Down Expand Up @@ -155,7 +155,6 @@ class SecondaryToolbar {
};

this.eventBus = eventBus;
this.externalServices = externalServices;
this.opened = false;

// Bind the event listeners for click, cursor tool, and scroll/spread mode
Expand Down Expand Up @@ -214,9 +213,12 @@ class SecondaryToolbar {
if (close) {
this.close();
}
this.externalServices.reportTelemetry({
type: "buttons",
data: { id: element.id },
this.eventBus.dispatch("reporttelemetry", {
source: this,
details: {
type: "buttons",
data: { id: element.id },
},
});
});
}
Expand Down
15 changes: 7 additions & 8 deletions web/toolbar-geckoview.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,14 @@ class Toolbar {

#eventBus;

#externalServices;

/**
* @param {ToolbarOptions} options
* @param {EventBus} eventBus
* @param {IL10n} _l10n - Localization service.
* @param {Object} nimbusData - Nimbus configuration.
* @param {Object} externalServices - Interface for external services.
*/
constructor(options, eventBus, _l10n, nimbusData, externalServices) {
constructor(options, eventBus, _l10n, nimbusData) {
this.#eventBus = eventBus;
this.#externalServices = externalServices;
const buttons = [
{
element: options.download,
Expand Down Expand Up @@ -88,9 +84,12 @@ class Toolbar {
element.addEventListener("click", evt => {
if (eventName !== null) {
this.#eventBus.dispatch(eventName, { source: this, ...eventDetails });
this.#externalServices.reportTelemetry({
type: "gv-buttons",
data: { id: `${element.id}_tapped` },
this.#eventBus.dispatch("reporttelemetry", {
source: this,
details: {
type: "gv-buttons",
data: { id: `${element.id}_tapped` },
},
});
}
});
Expand Down

0 comments on commit 9008985

Please sign in to comment.