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

    Function useJustUpdated

    • Announces what changed after the extension updates itself.

      Works by comparing the running __APP_VERSION__ against the last version this profile opened. The notes come from __CHANGELOG_CURRENT__ — this build's own changelog section, baked in at build time — so the prompt needs no network and shows exactly the entries published for the release.

      Two cases deliberately stay silent: a fresh install (no previous version recorded — a changelog means nothing to a first-time user) and a downgrade or re-install of the same version. The version is recorded on first sight either way, so each release announces itself at most once.

      Returns UseJustUpdated

      The pending JustUpdatedNotice plus an acknowledge action.

      const { notice, acknowledge } = useJustUpdated();
      // after updating 1.2.0 -> 1.3.0:
      // notice → { version: "1.3.0", previousVersion: "1.2.0", notes: [...] }
      export function useJustUpdated(): UseJustUpdated {
      const [notice, setNotice] = useState<JustUpdatedNotice | undefined>(undefined);

      useEffect(() => {
      let cancelled = false;

      const check = async () => {
      try {
      const stored = await cstorage.local.get([CACHE.LAST_SEEN_VERSION]);
      const previousVersion = stored[CACHE.LAST_SEEN_VERSION];

      // Record the current version regardless, so this only ever fires once
      // per release even if the user closes the popup without acknowledging.
      if (previousVersion !== __APP_VERSION__) {
      await cstorage.local.set({ [CACHE.LAST_SEEN_VERSION]: __APP_VERSION__ });
      }

      // Fresh install: nothing to compare against, and no history to summarize.
      if (typeof previousVersion !== 'string') return;

      const from = semver.valid(previousVersion);
      const to = semver.valid(__APP_VERSION__);
      if (!from || !to || !semver.gt(to, from)) return;

      const notes = parseReleaseNotes(__CHANGELOG_CURRENT__);
      // With no changelog section there is nothing worth interrupting for.
      if (notes.length === 0 || cancelled) return;

      setNotice({ version: to, previousVersion: from, notes });
      } catch (error) {
      console.error('Failed to check for a just-installed update:', { error });
      }
      };

      void check();
      return () => {
      cancelled = true;
      };
      }, []);

      const acknowledge = useCallback(() => setNotice(undefined), []);

      return { notice, acknowledge };
      }