Skip to content

Invoke is a leading creative engine that uses image and video generation models to empower professionals, artists, and enthusiasts to generate and create visual media using the latest AI-driven technologies. The solution offers an industry-leading application interface, and serves as the foundation for multiple commercial products.

feat(webv2): show generation progress in the tab title

joshistoastfa31ea0c92c3
diff --git a/invokeai/frontend/webv2/src/workbench/shell/DocumentTitleProgress.tsx b/invokeai/frontend/webv2/src/workbench/shell/DocumentTitleProgress.tsx
new file mode 100644
index 0000000000..396dfb43d1
--- /dev/null
+++ b/invokeai/frontend/webv2/src/workbench/shell/DocumentTitleProgress.tsx
@@ -0,0 +1,47 @@
+import { getQueueSummary } from '@features/queue/contracts';
+import { useQueueItemProgress } from '@features/queue/react';
+import { useMountEffect } from '@platform/react/useMountEffect';
+import { useActiveProjectSelector } from '@workbench/WorkbenchContext';
+import { useEffect, useMemo } from 'react';
+import { useTranslation } from 'react-i18next';
+
+import { DOCUMENT_TITLE_BASE, formatDocumentTitle } from './documentTitle';
+
+/**
+ * Writes generation progress into the browser tab. Renders nothing — it is the
+ * effect adapter for a piece of chrome React does not own.
+ *
+ * Percent is rounded before it reaches the title so a batch writes `document.title`
+ * about a hundred times instead of once per progress frame.
+ */
+export const DocumentTitleProgress = () => {
+ const { t } = useTranslation();
+ const queueItems = useActiveProjectSelector((project) => project.queue.items);
+ const baseSummary = getQueueSummary(queueItems);
+ const progress = useQueueItemProgress(baseSummary.runningQueueItemId ?? '');
+ const { current, total } = getQueueSummary(queueItems, progress);
+ const percent = typeof progress?.percentage === 'number' ? Math.round(progress.percentage * 100) : null;
+
+ const title = useMemo(
+ () =>
+ formatDocumentTitle({
+ current,
+ labels: { generating: t('common.generating'), queued: t('widgets.queueStatus.queued', { count: total }) },
+ percent,
+ total,
+ }),
+ [current, percent, t, total]
+ );
+
+ useEffect(() => {
+ document.title = title;
+ }, [title]);
+
+ // Separate from the write above so switching titles does not flash the base
+ // one in between; this only runs when the shell itself goes away.
+ useMountEffect(() => () => {
+ document.title = DOCUMENT_TITLE_BASE;
+ });
+
+ return null;
+};
diff --git a/invokeai/frontend/webv2/src/workbench/shell/WorkbenchShell.tsx b/invokeai/frontend/webv2/src/workbench/shell/WorkbenchShell.tsx
index f0d86c3968..b6ee98a355 100644
--- a/invokeai/frontend/webv2/src/workbench/shell/WorkbenchShell.tsx
+++ b/invokeai/frontend/webv2/src/workbench/shell/WorkbenchShell.tsx
@@ -40,6 +40,7 @@ import { useTranslation } from 'react-i18next';
import { BottomPanel } from './BottomPanel';
import { CenterArea } from './CenterArea';
+import { DocumentTitleProgress } from './DocumentTitleProgress';
import { WorkbenchNotificationToaster } from './notifications';
import { LeftPanel, RightPanel } from './Panels';
import { StatusBar } from './StatusBar';
@@ -235,6 +236,7 @@ export const WorkbenchShell = () => {
>
<Flex direction="column" h="100vh" w="100vw">
<WorkbenchNotificationToaster />
+ <DocumentTitleProgress />
<TopBar />
<Flex aria-labelledby="workbench-project-heading" as="main" flex="1" minH="0" overflow="hidden">
diff --git a/invokeai/frontend/webv2/src/workbench/shell/documentTitle.test.ts b/invokeai/frontend/webv2/src/workbench/shell/documentTitle.test.ts
new file mode 100644
index 0000000000..adeff676a6
--- /dev/null
+++ b/invokeai/frontend/webv2/src/workbench/shell/documentTitle.test.ts
@@ -0,0 +1,37 @@
+import { describe, expect, it } from 'vitest';
+
+import { DOCUMENT_TITLE_BASE, formatDocumentTitle } from './documentTitle';
+
+const labels = { generating: 'Generating', queued: '3 queued' };
+
+describe('formatDocumentTitle', () => {
+ it('leaves the title alone when the queue is empty', () => {
+ expect(formatDocumentTitle({ current: 0, labels, percent: 42, total: 0 })).toBe(DOCUMENT_TITLE_BASE);
+ });
+
+ it('reports the backlog before anything starts running', () => {
+ expect(formatDocumentTitle({ current: 0, labels, percent: null, total: 3 })).toBe(
+ `3 queued · ${DOCUMENT_TITLE_BASE}`
+ );
+ });
+
+ it('leads with percent and position for a multi-image batch', () => {
+ expect(formatDocumentTitle({ current: 2, labels, percent: 42, total: 8 })).toBe(
+ `42% · 2/8 · ${DOCUMENT_TITLE_BASE}`
+ );
+ });
+
+ it('drops the position for a single image', () => {
+ expect(formatDocumentTitle({ current: 1, labels, percent: 42, total: 1 })).toBe(`42% · ${DOCUMENT_TITLE_BASE}`);
+ });
+
+ it('falls back to a word when a single image has no percentage yet', () => {
+ expect(formatDocumentTitle({ current: 1, labels, percent: null, total: 1 })).toBe(
+ `Generating · ${DOCUMENT_TITLE_BASE}`
+ );
+ });
+
+ it('still shows the position when a batch has no percentage yet', () => {
+ expect(formatDocumentTitle({ current: 2, labels, percent: null, total: 8 })).toBe(`2/8 · ${DOCUMENT_TITLE_BASE}`);
+ });
+});
diff --git a/invokeai/frontend/webv2/src/workbench/shell/documentTitle.ts b/invokeai/frontend/webv2/src/workbench/shell/documentTitle.ts
new file mode 100644
index 0000000000..3f518719fa
--- /dev/null
+++ b/invokeai/frontend/webv2/src/workbench/shell/documentTitle.ts
@@ -0,0 +1,46 @@
+/**
+ * Generation progress in the browser tab, for the batch you walked away from.
+ *
+ * Batches run for minutes and people switch tabs while they do; every other
+ * progress surface in the app is invisible the moment this document is not the
+ * foreground one. Tab titles truncate hard and from the right, so the numbers
+ * lead and the product name trails.
+ */
+
+/** Mirrors the static `<title>` in index.html, which is what we restore to. */
+export const DOCUMENT_TITLE_BASE = 'Invoke V7 Workbench';
+
+export interface DocumentTitleLabels {
+ /** Fallback for "running, but nothing quantified yet", e.g. "Generating". */
+ generating: string;
+ /** Already-interpolated count, e.g. "4 queued". */
+ queued: string;
+}
+
+export const formatDocumentTitle = ({
+ baseTitle = DOCUMENT_TITLE_BASE,
+ current,
+ labels,
+ percent,
+ total,
+}: {
+ baseTitle?: string;
+ /** One-based ordinal of the image being generated; 0 when nothing has started. */
+ current: number;
+ labels: DocumentTitleLabels;
+ /** Whole percent for the active image, or null while indeterminate. */
+ percent: number | null;
+ total: number;
+}): string => {
+ if (total === 0) {
+ return baseTitle;
+ }
+
+ if (current === 0) {
+ return `${labels.queued} · ${baseTitle}`;
+ }
+
+ const parts = [percent === null ? null : `${percent}%`, total > 1 ? `${current}/${total}` : null].filter(Boolean);
+
+ return `${parts.length > 0 ? parts.join(' · ') : labels.generating} · ${baseTitle}`;
+};