1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-19 06:38:07 +02:00

[Editor] Add some telemetry for the signature editor (bug 1945827)

This commit is contained in:
Calixte Denizet 2025-02-24 19:50:40 +01:00
parent fef706233d
commit 9e672ff05e
4 changed files with 100 additions and 16 deletions

View file

@ -111,6 +111,22 @@ class SignatureEditor extends DrawingEditor {
return false; return false;
} }
/** @inheritdoc */
get telemetryFinalData() {
return {
type: "signature",
hasDescription: !!this.#description,
};
}
static computeTelemetryFinalData(data) {
const hasDescriptionStats = data.get("hasDescription");
return {
hasAltText: hasDescriptionStats.get(true) ?? 0,
hasNoAltText: hasDescriptionStats.get(false) ?? 0,
};
}
/** @inheritdoc */ /** @inheritdoc */
get isResizable() { get isResizable() {
return true; return true;
@ -279,6 +295,14 @@ class SignatureEditor extends DrawingEditor {
this._uiManager.addToAnnotationStorage(this); this._uiManager.addToAnnotationStorage(this);
this.setUuid(uuid); this.setUuid(uuid);
this._reportTelemetry({
action: "pdfjs.signature.inserted",
data: {
hasBeenSaved: !!uuid,
hasDescription: !!description,
},
});
this.div.hidden = false; this.div.hidden = false;
} }

View file

@ -537,7 +537,11 @@ class SignatureStorage {
async isFull() { async isFull() {
// We want to store at most 5 signatures. // We want to store at most 5 signatures.
return (await this.getAll()).size === 5; return (await this.size()) === 5;
}
async size() {
return (await this.getAll()).size;
} }
async create(data) { async create(data) {

View file

@ -70,7 +70,11 @@ class SignatureStorage {
async isFull() { async isFull() {
// Only allow 5 signatures to be saved. // Only allow 5 signatures to be saved.
return (await this.getAll()).size === 5; return (await this.size()) === 5;
}
async size() {
return (await this.getAll()).size;
} }
async create(data) { async create(data) {

View file

@ -176,6 +176,12 @@ class SignatureManager {
clearButton.addEventListener( clearButton.addEventListener(
"click", "click",
() => { () => {
this.#reportTelemetry({
action: "pdfjs.signature.clear",
data: {
type: this.#currentTab,
},
});
this.#initTab(null); this.#initTab(null);
}, },
{ passive: true } { passive: true }
@ -253,7 +259,9 @@ class SignatureManager {
#resetCommon() { #resetCommon() {
this.#hasDescriptionChanged = false; this.#hasDescriptionChanged = false;
this.#description.value = ""; this.#description.value = "";
this.#tabsToAltText.set(this.#currentTab, ""); if (this.#currentTab) {
this.#tabsToAltText.get(this.#currentTab).value = "";
}
} }
#resetTab(name) { #resetTab(name) {
@ -283,7 +291,7 @@ class SignatureManager {
return; return;
} }
if (this.#currentTab) { if (this.#currentTab) {
this.#tabsToAltText.set(this.#currentTab, this.#description.value); this.#tabsToAltText.get(this.#currentTab).value = this.#description.value;
} }
if (name) { if (name) {
this.#currentTab = name; this.#currentTab = name;
@ -294,7 +302,7 @@ class SignatureManager {
if (reset) { if (reset) {
this.#resetCommon(); this.#resetCommon();
} else { } else {
this.#description.value = this.#tabsToAltText.get(this.#currentTab); this.#description.value = this.#tabsToAltText.get(this.#currentTab).value;
} }
this.#clearDescription.disabled = this.#description.value === ""; this.#clearDescription.disabled = this.#description.value === "";
this.#currentTabAC?.abort(); this.#currentTabAC?.abort();
@ -335,7 +343,8 @@ class SignatureManager {
() => { () => {
const { value } = this.#typeInput; const { value } = this.#typeInput;
if (!this.#hasDescriptionChanged) { if (!this.#hasDescriptionChanged) {
this.#description.value = value; this.#tabsToAltText.get("type").default = this.#description.value =
value;
this.#clearDescription.disabled = value === ""; this.#clearDescription.disabled = value === "";
} }
this.#disableButtons(value); this.#disableButtons(value);
@ -398,6 +407,7 @@ class SignatureManager {
this.#l10n this.#l10n
.get(SignatureManager.#l10nDescription.signature) .get(SignatureManager.#l10nDescription.signature)
.then(description => { .then(description => {
this.#tabsToAltText.get("draw").default = description;
this.#description.value ||= description; this.#description.value ||= description;
this.#clearDescription.disabled = this.#description.value === ""; this.#clearDescription.disabled = this.#description.value === "";
}); });
@ -609,6 +619,7 @@ class SignatureManager {
this.#imageSVG.setAttribute("preserveAspectRatio", "xMidYMid meet"); this.#imageSVG.setAttribute("preserveAspectRatio", "xMidYMid meet");
this.#imageSVG.append(path); this.#imageSVG.append(path);
path.setAttribute("d", outline.toSVGPath()); path.setAttribute("d", outline.toSVGPath());
this.#tabsToAltText.get("image").default = file.name;
if (this.#description.value === "") { if (this.#description.value === "") {
this.#description.value = file.name || ""; this.#description.value = file.name || "";
this.#clearDescription.disabled = this.#description.value === ""; this.#clearDescription.disabled = this.#description.value === "";
@ -633,6 +644,16 @@ class SignatureManager {
); );
} }
#reportTelemetry(data) {
this.#eventBus.dispatch("reporttelemetry", {
source: this,
details: {
type: "editing",
data,
},
});
}
#addToolbarButton(signatureData, uuid, description) { #addToolbarButton(signatureData, uuid, description) {
const { curves, areContours, thickness, width, height } = signatureData; const { curves, areContours, thickness, width, height } = signatureData;
const maxDim = Math.max(width, height); const maxDim = Math.max(width, height);
@ -716,6 +737,12 @@ class SignatureManager {
deleteButton.addEventListener("click", async () => { deleteButton.addEventListener("click", async () => {
if (await this.#signatureStorage.delete(uuid)) { if (await this.#signatureStorage.delete(uuid)) {
div.remove(); div.remove();
this.#reportTelemetry({
action: "pdfjs.signature.delete_saved",
data: {
savedCount: await this.#signatureStorage.size(),
},
});
} }
}); });
const deleteSpan = document.createElement("span"); const deleteSpan = document.createElement("span");
@ -805,7 +832,7 @@ class SignatureManager {
async open({ uiManager, editor }) { async open({ uiManager, editor }) {
this.#tabsToAltText ||= new Map( this.#tabsToAltText ||= new Map(
this.#tabButtons.keys().map(name => [name, ""]) this.#tabButtons.keys().map(name => [name, { value: "", default: "" }])
); );
this.#uiManager = uiManager; this.#uiManager = uiManager;
this.#currentEditor = editor; this.#currentEditor = editor;
@ -851,7 +878,8 @@ class SignatureManager {
async #add() { async #add() {
let data; let data;
switch (this.#currentTab) { const type = this.#currentTab;
switch (type) {
case "type": case "type":
data = this.#getOutlineForType(); data = this.#getOutlineForType();
break; break;
@ -863,8 +891,8 @@ class SignatureManager {
break; break;
} }
let uuid = null; let uuid = null;
const description = this.#description.value;
if (this.#saveCheckbox.checked) { if (this.#saveCheckbox.checked) {
const description = this.#description.value;
const { newCurves, areContours, thickness, width, height } = data; const { newCurves, areContours, thickness, width, height } = data;
const signatureData = await SignatureExtractor.compressSignature({ const signatureData = await SignatureExtractor.compressSignature({
outlines: newCurves, outlines: newCurves,
@ -893,6 +921,18 @@ class SignatureManager {
console.warn("SignatureManager.add: cannot save the signature."); console.warn("SignatureManager.add: cannot save the signature.");
} }
} }
const altText = this.#tabsToAltText.get(type);
this.#reportTelemetry({
action: "pdfjs.signature.created",
data: {
type,
saved: !!uuid,
savedCount: await this.#signatureStorage.size(),
descriptionChanged: description !== altText.default,
},
});
this.#currentEditor.addSignature( this.#currentEditor.addSignature(
data, data,
DEFAULT_HEIGHT_IN_PAGE, DEFAULT_HEIGHT_IN_PAGE,
@ -940,7 +980,7 @@ class EditDescriptionDialog {
e.preventDefault(); e.preventDefault();
} }
}); });
cancelButton.addEventListener("click", this.#finish.bind(this)); cancelButton.addEventListener("click", this.#cancel.bind(this));
updateButton.addEventListener("click", this.#update.bind(this)); updateButton.addEventListener("click", this.#update.bind(this));
const clearDescription = description.lastElementChild; const clearDescription = description.lastElementChild;
@ -983,12 +1023,24 @@ class EditDescriptionDialog {
} }
async #update() { async #update() {
const description = this.#description.value; // The description has been changed because the button isn't disabled.
if (this.#previousDescription === description) { this.#currentEditor._reportTelemetry({
this.#finish(); action: "pdfjs.signature.edit_description",
return; data: {
} hasBeenChanged: true,
this.#currentEditor.description = description; },
});
this.#currentEditor.description = this.#description.value;
this.#finish();
}
#cancel() {
this.#currentEditor._reportTelemetry({
action: "pdfjs.signature.edit_description",
data: {
hasBeenChanged: false,
},
});
this.#finish(); this.#finish();
} }