FlowCrypt / flowcrypt-browser

FlowCrypt Browser extension for Chrome and Firefox
https://flowcrypt.com
Other
372 stars 48 forks source link

issue 5747 refactor content scripts for Thunderbird #5748

Closed tomholub closed 1 month ago

tomholub commented 1 month ago

This PR attempts to clean up content script code and make it easier to add another environment (like another webmail, or Thunderbird)

Further, test logging output was cleaned up a bit, and debug html files are uploaded to artifacts again.

close #5747 issue #5396


Tests (delete all except exactly one):


To be filled by reviewers

I have reviewed that this PR... (tick whichever items you personally focused on during this review):

tomholub commented 1 month ago

After this PR, Thunderbird could be added like so:

Catch.try(async () => {
+if(this is thunderbird) {
+  await new ThunderbirdWebmailStartup().asyncConstructor();
+} else {
  await new GmailWebmailStartup().asyncConstructor();
+}
})();
// content_scripts/webmail/thunderbird/thunderbird-webmail-startup.ts

export class ThunderbirdWebmailStartup {
  private replacePgpElsInterval: number;
  private replacer: GmailElementReplacer;

  public asyncConstructor = async () => {
    await contentScriptSetupIfVacant({
      name: 'thunderbird',
      variant: undefined,
      getUserAccountEmail: () => undefined, // todo, but can start with undefined
      getUserFullName: () => undefined // todo, but can start with undefined
      getReplacer: () => new ThunderbirdElementReplacer(), // todo - add this class empty, methods do nothing
      start: this.start
    });
  }

    private start = async (
      acctEmail: string,
      clientConfiguration: ClientConfiguration,
      injector: Injector,
      notifications: Notifications,
      factory: XssSafeFactory,
      relayManager: RelayManager
    ) => {
      // injector.btns(); // todo in another issue - add compose button
      this.replacer.runIntervalFunctionsPeriodically();
      await notifications.showInitial(acctEmail);
      await notifications.show('FlowCrypt Thunderbird support is still in early development, and not expected to function properly yet. Support will be gradually added in upcoming versions.');
    }
  };
};