Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions extension/chrome/elements/pgp_block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { PgpBlockViewPrintModule } from './pgp_block_modules/pgp-block-print-mod
import { PgpBlockViewQuoteModule } from './pgp_block_modules/pgp-block-quote-module.js';
import { PgpBlockViewRenderModule } from './pgp_block_modules/pgp-block-render-module.js';
import { CommonHandlers, Ui } from '../../js/common/browser/ui.js';
import { Catch } from '../../js/common/platform/catch.js';
import { View } from '../../js/common/view.js';
import { BrowserMsg } from '../../js/common/browser/browser-msg.js';

Expand Down Expand Up @@ -67,6 +68,17 @@ export class PgpBlockView extends View {
BrowserMsg.addListener('confirmation_result', CommonHandlers.createAsyncResultHandler());
BrowserMsg.listen(this.getDest());
BrowserMsg.send.pgpBlockReady(this, { frameId: this.frameId, messageSender: this.getDest() });
// Proactively re-send readiness a few times in case the relay/association isn't ready yet,
// to ensure printMailInfo is delivered reliably
let resendAttempts = 0;
const resendInterval = Catch.setHandledInterval(() => {
if (this.printModule.printMailInfoHtml || resendAttempts >= 6) {
clearInterval(resendInterval);
return;
}
resendAttempts++;
BrowserMsg.send.pgpBlockReady(this, { frameId: this.frameId, messageSender: this.getDest() });
}, 500);
// Added this listener to handle cases where 'inbox_page/setup-webmail-content-script' is not ready to retrieve 'pgpBlockReady' events.
// This can occur if 'setHandlers' is called before 'Inbox.setHandlers' is fully initialized.
// https://github.com/FlowCrypt/flowcrypt-browser/pull/5783#discussion_r1663636264
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,23 @@

import { Time } from '../../../js/common/browser/time.js';
import { Catch } from '../../../js/common/platform/catch.js';
import { Ui } from '../../../js/common/browser/ui.js';
import { Xss } from '../../../js/common/platform/xss.js';

export class PgpBlockViewPrintModule {
public printMailInfoHtml: string | undefined;

public printPGPBlock = async () => {
// If printMailInfoHtml is not yet prepared, wait briefly to handle race conditions
if (!this.printMailInfoHtml) {
for (let i = 0; i < 6 && !this.printMailInfoHtml; i++) {
await Time.sleep(200);
}
}
// If still not prepared, skip printing entirely
if (!this.printMailInfoHtml) {
// Last resort: inform the user
void Ui.modal.error('Unable to get metadata for this email. Please refresh the page and try again.');
Catch.reportErr('printMailInfoHtml not prepared!');
return;
}
Expand Down
Loading