Skip to content

Commit

Permalink
Merge branch 'master' into 5498-puppeteer-v21
Browse files Browse the repository at this point in the history
  • Loading branch information
ioanmo226 authored May 20, 2024
2 parents 6443a4b + 7d77245 commit 243233f
Show file tree
Hide file tree
Showing 8 changed files with 235 additions and 37 deletions.
59 changes: 38 additions & 21 deletions extension/chrome/elements/compose-modules/compose-input-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ export class ComposeInputModule extends ViewModule<ComposeView> {
this.squire = new window.Squire(el, { addLinks });
this.initShortcuts();
this.handlePaste();
this.handleDragImages();
this.handlePasteImages();
this.resizeReplyBox();
this.scrollIntoView();
Expand All @@ -136,35 +137,51 @@ export class ComposeInputModule extends ViewModule<ComposeView> {
});
};

private handlePasteImages = () => {
private loadImageFromFile = (file: File, callback: (result: string) => void) => {
const reader = new FileReader();
reader.onload = () => callback(reader.result as string);
reader.readAsDataURL(file);
};

private insertImageIntoSquire = (imageData: string, name: string) => {
try {
this.squire.insertImage(imageData, { name, title: name });
this.view.draftModule.draftSave().catch(Catch.reportErr);
} catch (e) {
Catch.reportErr(e);
}
};

private handleDragImages = () => {
this.squire.addEventListener('drop', (ev: DragEvent) => {
try {
if (!this.isRichText()) {
return;
}
if (!ev.dataTransfer?.files.length) {
return;
}
const file = ev.dataTransfer.files[0];
const reader = new FileReader();
reader.onload = () => {
try {
this.squire.insertImage(reader.result?.toString() ?? '', { name: file.name, title: file.name });
this.view.draftModule.draftSave().catch(Catch.reportErr);
} catch (e) {
Catch.reportErr(e);
}
};
reader.readAsDataURL(file);
} catch (e) {
Catch.reportErr(e);
if (!this.isRichText() || !ev.dataTransfer?.files.length) {
return;
}
const file = ev.dataTransfer.files[0];
this.loadImageFromFile(file, imageData => {
this.insertImageIntoSquire(imageData, file.name);
});
});
this.squire.addEventListener('dragover', (e: DragEvent) => {
e.preventDefault(); // this is needed for 'drop' event to fire
});
};

private handlePasteImages = () => {
this.squire.addEventListener('pasteImage', (ev: Event & { detail: { clipboardData: DataTransfer } }) => {
if (!this.isRichText()) return;
const items = Array.from(ev.detail.clipboardData?.items ?? []);
const imageItem = items.find(item => /image/.test(item.type));

const imageFile = imageItem?.getAsFile();
if (imageItem && imageFile) {
this.loadImageFromFile(imageFile, imageData => {
this.insertImageIntoSquire(imageData, 'Pasted Image');
});
}
});
};

private handleRTL = () => {
const checkRTL = () => {
let container = $(this.squire.getSelection().commonAncestorContainer);
Expand Down
2 changes: 1 addition & 1 deletion extension/chrome/settings/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ export class SetupView extends View {
return;
}
if (!armoredPubkey) {
await Ui.modal.warning('Public key not usable - not sumbitting to Attester');
await Ui.modal.warning('Public key not usable - not submitting to Attester');
return;
}
const pub = await KeyUtil.parse(armoredPubkey);
Expand Down
15 changes: 8 additions & 7 deletions extension/js/common/platform/catch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import { Url } from '../core/common.js';
import { FLAVOR, InMemoryStoreKeys, SHARED_TENANT_API_HOST, VERSION } from '../core/const.js';
import { GlobalStore } from './store/global-store.js';
import { InMemoryStore } from './store/in-memory-store.js';

export class UnreportableError extends Error {}
Expand Down Expand Up @@ -283,8 +284,8 @@ export class Catch {
private static formatExceptionForReport(thrown: unknown, line?: number, col?: number): ErrorReport {
if (!line || !col) {
const { line: parsedLine, col: parsedCol } = Catch.getErrorLineAndCol(thrown);
line = parsedLine;
col = parsedCol;
line = parsedLine > 0 ? parsedLine : 1;
col = parsedCol > 0 ? parsedCol : 1;
}
if (thrown instanceof Error) {
// reporting stack may differ from the stack of the actual error, both may be interesting
Expand All @@ -299,8 +300,8 @@ export class Catch {
name: exception.name.substring(0, 50),
message: exception.message.substring(0, 200),
url: location.href.split('?')[0],
line: line || 0,
col: col || 0,
line: line || 1,
col: col || 1,
trace: exception.stack || '',
version: VERSION,
environment: Catch.RUNTIME_ENVIRONMENT,
Expand All @@ -311,8 +312,8 @@ export class Catch {

private static async doSendErrorToSharedTenantFes(errorReport: ErrorReport) {
try {
const uncheckedUrlParams = Url.parse(['acctEmail']);
const acctEmail = String(uncheckedUrlParams.acctEmail);
const { acctEmail: parsedEmail } = Url.parse(['acctEmail']);
const acctEmail = parsedEmail ? String(parsedEmail) : (await GlobalStore.acctEmailsGet())?.[0];
if (!acctEmail) {
console.error('Not reporting error because user is not logged in');
return;
Expand Down Expand Up @@ -376,7 +377,7 @@ export class Catch {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
return { line: Number(matched![1]), col: Number(matched![2]) };
} catch (lineErr) {
return { line: 0, col: 0 };
return { line: 1, col: 1 };
}
}

Expand Down
188 changes: 184 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"stylelint": "16.5.0",
"stylelint-config-standard": "36.0.0",
"typescript": "5.4.5",
"undici-types": "^6.14.0",
"undici-types": "^6.17.0",
"web-ext": "7.11.0",
"webpack-cli": "^5.1.1"
},
Expand Down
2 changes: 1 addition & 1 deletion test/source/tests/compose.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3271,7 +3271,7 @@ export const defineComposeTests = (testVariant: TestVariant, testWithBrowser: Te
const acct = '[email protected]';
const settingsPage = await BrowserRecipe.openSettingsLoginApprove(t, browser, acct);
await SetupPageRecipe.autoSetupWithEKM(settingsPage, {
expectWarnModal: 'Public key not usable - not sumbitting to Attester',
expectWarnModal: 'Public key not usable - not submitting to Attester',
});
})
);
Expand Down
2 changes: 1 addition & 1 deletion test/source/tests/flaky.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export const defineFlakyTests = (testVariant: TestVariant, testWithBrowser: Test
clickOn: 'confirm',
});
await SettingsPageRecipe.waitForModalAndRespond(settingsPage, 'warning', {
contentToCheck: 'Public key not usable - not sumbitting to Attester',
contentToCheck: 'Public key not usable - not submitting to Attester',
clickOn: 'confirm',
});
await settingsPage.waitAndClick('@action-step4done-account-settings');
Expand Down
2 changes: 1 addition & 1 deletion test/source/tests/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -888,7 +888,7 @@ AN8G3r5Htj8olot+jm9mIa5XLXWzMNUZgg==
},
});
const settingsPage = await BrowserRecipe.openSettingsLoginApprove(t, browser, acctEmail);
await SetupPageRecipe.autoSetupWithEKM(settingsPage, { expectWarnModal: 'Public key not usable - not sumbitting to Attester' });
await SetupPageRecipe.autoSetupWithEKM(settingsPage, { expectWarnModal: 'Public key not usable - not submitting to Attester' });
const gmailPage = await openMockGmailPage(t, browser, acctEmail);
// Check if notification presents
let warningMsg =
Expand Down

0 comments on commit 243233f

Please sign in to comment.