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.
TypeScript ai-artartificial-intelligencegenerative-artimage-generationimg2imginpaintinglatent-diffusionlinuxmacosoutpaintingstable-diffusiontxt2imgwindows
feat(shell): show a one-time alpha notice
Josh Corbett6c8121a760a4
diff --git a/invokeai/frontend/webv2/public/locales/en.json b/invokeai/frontend/webv2/public/locales/en.jsonindex e8a5629d5e..12498a092d 100644--- a/invokeai/frontend/webv2/public/locales/en.json+++ b/invokeai/frontend/webv2/public/locales/en.json@@ -1,4 +1,11 @@{+ "alphaNotice": {+ "body": "This is an alpha build of the new Invoke interface. Expect rough edges, missing features, and behavior that changes between releases.",+ "dismiss": "Got it",+ "reportLink": "file an issue on GitHub",+ "reportPrefix": "When something breaks or looks wrong, please",+ "title": "Alpha build"+ },"commandPalette": {"title": "Command palette","buttonLabel": "Command palette",diff --git a/invokeai/frontend/webv2/scripts/mock-backend.mjs b/invokeai/frontend/webv2/scripts/mock-backend.mjsindex 764d62a877..f1c8407e86 100644--- a/invokeai/frontend/webv2/scripts/mock-backend.mjs+++ b/invokeai/frontend/webv2/scripts/mock-backend.mjs@@ -100,7 +100,9 @@ const createState = (profile) => {return {boards: new Map(fixture.boards.map((board) => [board.board_id, clone(board)])),- clientState: new Map(),+ // An existing account: the one-time alpha notice was dismissed already, so+ // journeys and verification scripts land on the page, not a modal.+ clientState: new Map([['webv2:workbench-settings', JSON.stringify({ alphaNoticeAcknowledged: true })]]),images: new Map(fixture.images.map((image) => [image.image_name, clone(image)])),models: new Map(fixture.models.map((model) => [model.key, clone(model)])),mutationClock: 0,diff --git a/invokeai/frontend/webv2/src/app/App.tsx b/invokeai/frontend/webv2/src/app/App.tsxindex 268f620404..e9b6b2325e 100644--- a/invokeai/frontend/webv2/src/app/App.tsx+++ b/invokeai/frontend/webv2/src/app/App.tsx@@ -3,18 +3,41 @@ import { ChakraProvider } from '@chakra-ui/react';import { AppToaster } from '@platform/ui/toaster';import { RouterProvider } from '@tanstack/react-router';import { system } from '@theme/system';+import { useWorkbenchSettingsSelector } from '@workbench/settings/store';+import { lazy, Suspense } from 'react';import { FeatureHintsAdapterProvider } from './FeatureHintsProvider';import { I18nController } from './I18nController';import { router } from './router';import { ThemeController } from './ThemeController';+const AlphaNoticeDialog = lazy(() =>+ import('@workbench/shell/AlphaNoticeDialog').then((module) => ({ default: module.AlphaNoticeDialog }))+);++/**+ * The one-time alpha notice loads only for an account that has not dismissed+ * it: every other start pays neither the module nor a request for it.+ */+const AlphaNoticeGate = () => {+ const isDue = useWorkbenchSettingsSelector(+ (snapshot) => snapshot.status === 'ready' && !snapshot.preferences.alphaNoticeAcknowledged+ );++ return isDue ? (+ <Suspense fallback={null}>+ <AlphaNoticeDialog />+ </Suspense>+ ) : null;+};+export const App = () => (<AppProviders><ChakraProvider value={system}><ThemeController /><I18nController /><AppToaster />+ <AlphaNoticeGate /><FeatureHintsAdapterProvider><RouterProvider router={router} /></FeatureHintsAdapterProvider>diff --git a/invokeai/frontend/webv2/src/workbench/settings/contracts.ts b/invokeai/frontend/webv2/src/workbench/settings/contracts.tsindex 8ad12228a9..cfa01d2a75 100644--- a/invokeai/frontend/webv2/src/workbench/settings/contracts.ts+++ b/invokeai/frontend/webv2/src/workbench/settings/contracts.ts@@ -54,6 +54,8 @@ export interface StoredGeneratePreset {/** User-tunable appearance + behavior preferences surfaced in the Settings modal. */export interface WorkbenchPreferences {+ /** The alpha-build notice was dismissed; shown once per account until then. */+ alphaNoticeAcknowledged: boolean;themeId: WorkbenchThemeId;reduceMotion: boolean;showFocusRegionHighlight: boolean;diff --git a/invokeai/frontend/webv2/src/workbench/settings/store.ts b/invokeai/frontend/webv2/src/workbench/settings/store.tsindex 2e737a8d37..cbc9307879 100644--- a/invokeai/frontend/webv2/src/workbench/settings/store.ts+++ b/invokeai/frontend/webv2/src/workbench/settings/store.ts@@ -53,6 +53,7 @@ export const DEFAULT_PROJECT_SETTINGS: ProjectSettings = {};export const DEFAULT_PREFERENCES: WorkbenchPreferences = {+ alphaNoticeAcknowledged: false,autoSwitchInvocationRoute: true,confirmImageDeletion: true,customHotkeys: {},@@ -345,6 +346,10 @@ export const normalizeWorkbenchPreferences = (preferences?: WorkbenchPreferences: DEFAULT_PREFERENCES.queueJobsScope,highContrast:typeof preferences?.highContrast === 'boolean' ? preferences.highContrast : DEFAULT_PREFERENCES.highContrast,+ alphaNoticeAcknowledged:+ typeof preferences?.alphaNoticeAcknowledged === 'boolean'+ ? preferences.alphaNoticeAcknowledged+ : DEFAULT_PREFERENCES.alphaNoticeAcknowledged,reduceMotion:typeof preferences?.reduceMotion === 'boolean' ? preferences.reduceMotion : DEFAULT_PREFERENCES.reduceMotion,showFocusRegionHighlight:diff --git a/invokeai/frontend/webv2/src/workbench/shell/AlphaNoticeDialog.browser.test.tsx b/invokeai/frontend/webv2/src/workbench/shell/AlphaNoticeDialog.browser.test.tsxnew file mode 100644index 0000000000..082e2d223a--- /dev/null+++ b/invokeai/frontend/webv2/src/workbench/shell/AlphaNoticeDialog.browser.test.tsx@@ -0,0 +1,103 @@+import { ChakraProvider } from '@chakra-ui/react';+import { system } from '@theme/system';+import { isHotkeyModalLayerActive } from '@workbench/hotkeys/modalLayer';+import { createInstance } from 'i18next';+import { act } from 'react';+import { createRoot, type Root } from 'react-dom/client';+import { I18nextProvider, initReactI18next } from 'react-i18next';+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';+import { page } from 'vitest/browser';++import { AlphaNoticeDialog } from './AlphaNoticeDialog';++const settings = vi.hoisted(() => ({+ snapshot: { preferences: { alphaNoticeAcknowledged: false }, status: 'idle' as 'idle' | 'ready' },+ listeners: new Set<() => void>(),+ patchWorkbenchPreferences: vi.fn(),+}));++vi.mock('@workbench/settings/store', async () => {+ const { useSyncExternalStore } = await import('react');++ return {+ patchWorkbenchPreferences: settings.patchWorkbenchPreferences,+ useWorkbenchSettingsSelector: (selector: (snapshot: typeof settings.snapshot) => unknown) =>+ useSyncExternalStore(+ (listener) => {+ settings.listeners.add(listener);+ return () => settings.listeners.delete(listener);+ },+ () => selector(settings.snapshot)+ ),+ };+});++const i18n = createInstance();+await i18n.use(initReactI18next).init({+ lng: 'en',+ resources: { en: { translation: await fetch('/locales/en.json').then((response) => response.json()) } },+ interpolation: { escapeValue: false },+});++(globalThis as typeof globalThis & { IS_REACT_ACT_ENVIRONMENT: boolean }).IS_REACT_ACT_ENVIRONMENT = true;++const setSnapshot = (next: typeof settings.snapshot) =>+ act(() => {+ settings.snapshot = next;+ settings.listeners.forEach((listener) => listener());+ });++describe('AlphaNoticeDialog', () => {+ let host: HTMLDivElement;+ let root: Root;++ beforeEach(async () => {+ settings.patchWorkbenchPreferences.mockReset();+ settings.snapshot = { preferences: { alphaNoticeAcknowledged: false }, status: 'idle' };+ host = document.createElement('div');+ document.body.append(host);+ root = createRoot(host);+ await act(() =>+ root.render(+ <ChakraProvider value={system}>+ <I18nextProvider i18n={i18n}>+ <AlphaNoticeDialog />+ </I18nextProvider>+ </ChakraProvider>+ )+ );+ });++ afterEach(async () => {+ await act(() => root.unmount());+ host.remove();+ });++ it('waits for preferences, then shows once with focus on the dismiss action, and records the acknowledgement', async () => {+ // Not before the account's preferences are known: an acknowledged account must not see it flash.+ expect(document.querySelector('[role="alertdialog"]')).toBeNull();++ await setSnapshot({ preferences: { alphaNoticeAcknowledged: false }, status: 'ready' });+ await expect.element(page.getByRole('alertdialog', { name: i18n.t('alphaNotice.title') })).toBeVisible();+ await expect.element(page.getByRole('button', { name: i18n.t('alphaNotice.dismiss') })).toHaveFocus();+ expect(isHotkeyModalLayerActive()).toBe(true);+ expect(page.getByRole('link', { name: i18n.t('alphaNotice.reportLink') }).element()).toHaveAttribute(+ 'rel',+ 'noreferrer'+ );++ await page.getByRole('button', { name: i18n.t('alphaNotice.dismiss') }).click();+ expect(settings.patchWorkbenchPreferences).toHaveBeenCalledExactlyOnceWith({ alphaNoticeAcknowledged: true });++ await setSnapshot({ preferences: { alphaNoticeAcknowledged: true }, status: 'ready' });+ await expect.element(page.getByRole('alertdialog')).not.toBeInTheDocument();+ expect(isHotkeyModalLayerActive()).toBe(false);+ });++ it('stays closed for an account that already acknowledged it', async () => {+ await setSnapshot({ preferences: { alphaNoticeAcknowledged: true }, status: 'ready' });++ expect(document.querySelector('[role="alertdialog"]')).toBeNull();+ expect(isHotkeyModalLayerActive()).toBe(false);+ });+});diff --git a/invokeai/frontend/webv2/src/workbench/shell/AlphaNoticeDialog.tsx b/invokeai/frontend/webv2/src/workbench/shell/AlphaNoticeDialog.tsxnew file mode 100644index 0000000000..1674f9d9a4--- /dev/null+++ b/invokeai/frontend/webv2/src/workbench/shell/AlphaNoticeDialog.tsx@@ -0,0 +1,77 @@+import { Dialog, Link, Portal, Stack, Text } from '@chakra-ui/react';+import { useMountEffect } from '@platform/react/useMountEffect';+import { Button } from '@platform/ui/Button';+import { registerHotkeyModalLayer } from '@workbench/hotkeys/modalLayer';+import { patchWorkbenchPreferences, useWorkbenchSettingsSelector } from '@workbench/settings/store';+import { useCallback, useRef } from 'react';+import { useTranslation } from 'react-i18next';++const ISSUES_URL = 'https://github.com/invoke-ai/InvokeAI/issues';++const acknowledge = () => void patchWorkbenchPreferences({ alphaNoticeAcknowledged: true });++/** Mounted only while the notice is open: workbench hotkeys stay quiet under it, as under the other dialogs. */+const AlphaNoticeModalLayer = () => {+ useMountEffect(() => registerHotkeyModalLayer('alpha-notice'));++ return null;+};++/**+ * One-time alpha disclaimer, shown once the account's preferences have loaded+ * so a fresh session does not flash it at someone who already dismissed it.+ * Dismissal is a preference, so it follows the account rather than the browser.+ */+export const AlphaNoticeDialog = () => {+ const { t } = useTranslation();+ const isOpen = useWorkbenchSettingsSelector(+ (snapshot) => snapshot.status === 'ready' && !snapshot.preferences.alphaNoticeAcknowledged+ );+ const dismissRef = useRef<HTMLButtonElement | null>(null);+ const handleOpenChange = useCallback((event: { open: boolean }) => {+ if (!event.open) {+ acknowledge();+ }+ }, []);+ // The dismiss button is the primary action; the issues link stays reachable by Tab.+ const getInitialFocusEl = useCallback(() => dismissRef.current, []);++ return (+ <Dialog.Root+ initialFocusEl={getInitialFocusEl}+ open={isOpen}+ role="alertdialog"+ size="sm"+ onOpenChange={handleOpenChange}+ >+ {isOpen ? <AlphaNoticeModalLayer /> : null}+ <Portal>+ <Dialog.Backdrop />+ <Dialog.Positioner>+ <Dialog.Content>+ <Dialog.Header>+ <Dialog.Title>{t('alphaNotice.title')}</Dialog.Title>+ </Dialog.Header>+ <Dialog.Body>+ <Stack gap="2">+ <Text fontSize="xs">{t('alphaNotice.body')}</Text>+ <Text fontSize="xs">+ {t('alphaNotice.reportPrefix')}{' '}+ <Link color="accent.fg" href={ISSUES_URL} rel="noreferrer" target="_blank">+ {t('alphaNotice.reportLink')}+ </Link>+ .+ </Text>+ </Stack>+ </Dialog.Body>+ <Dialog.Footer>+ <Button ref={dismissRef} colorPalette="accent" size="xs" variant="solid" onClick={acknowledge}>+ {t('alphaNotice.dismiss')}+ </Button>+ </Dialog.Footer>+ </Dialog.Content>+ </Dialog.Positioner>+ </Portal>+ </Dialog.Root>+ );+};