ChemPal Documentation - v1.6.0
    Preparing search index...

    Function shouldApplyToBadge

    • Decides whether an output actually needs to be written to the badge, given the badge's current on-screen text. This is what prevents the open-with-results flicker: the toolbar badge persists across popup opens, so if it already shows the desired text (or is already empty), re-applying would blank-then-rewrite it (BadgeAnimator.setText clears before setting) — a visible flash.

      animate always returns true because a single text read can't tell whether the ellipsis is already cycling; the in-session isSameBadgeOutput guard handles repeated animate instead.

      Parameters

      • current: string

        The badge's current text (from chrome.action.getBadgeText).

      • output: BadgeOutput

        The output about to be applied.

      Returns boolean

      Whether the output should be written.

      shouldApplyToBadge("5", { kind: "text", value: "5" }); // false — already shown
      shouldApplyToBadge("5", { kind: "text", value: "6" }); // true
      shouldApplyToBadge("", { kind: "clear" }); // false — already empty
      export function shouldApplyToBadge(current: string, output: BadgeOutput): boolean {
      switch (output.kind) {
      case 'text':
      return current !== output.value;
      case 'clear':
      return current !== '';
      case 'animate':
      return true;
      }
      }