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(queue): shift-click the topbar cancel to cancel all jobs

Josh Corbett83b39e29678b
diff --git a/invokeai/frontend/webv2/public/locales/en.json b/invokeai/frontend/webv2/public/locales/en.json
index e67f87d640..091fbb6b08 100644
--- a/invokeai/frontend/webv2/public/locales/en.json
+++ b/invokeai/frontend/webv2/public/locales/en.json
@@ -396,6 +396,7 @@
"remaining_one": "{{count}} image remaining. Open queue",
"remaining_other": "{{count}} images remaining. Open queue",
"route": "{{source}} to {{destination}} · {{graph}}",
+ "shiftCancelsAll": "Shift-click cancels all",
"waitingForProgress": "Backend accepted batch; waiting for progress event.",
"waitingToStart": "Waiting to start"
},
diff --git a/invokeai/frontend/webv2/src/workbench/shell/topbar/QueueCluster.tsx b/invokeai/frontend/webv2/src/workbench/shell/topbar/QueueCluster.tsx
index 50c1597a25..ae1e770391 100644
--- a/invokeai/frontend/webv2/src/workbench/shell/topbar/QueueCluster.tsx
+++ b/invokeai/frontend/webv2/src/workbench/shell/topbar/QueueCluster.tsx
@@ -1,7 +1,6 @@
import type { ModelLoadInfo } from '@features/models';
import type { QueueItem } from '@features/queue/contracts';
import type { QueueItemProgress } from '@features/queue/react';
-import type { ReactNode } from 'react';
import { Badge, chakra, HStack, Icon, Menu, Portal, Progress, Stack, Text } from '@chakra-ui/react';
import { useModelLoads } from '@features/models';
@@ -12,6 +11,7 @@ import {
} from '@features/queue/contracts';
import { QueueMenuItems, useQueueMenuActions } from '@features/queue/menu';
import { useIsProcessorPaused } from '@features/queue/react';
+import { useMountEffect } from '@platform/react/useMountEffect';
import { Button, IconButton } from '@platform/ui/Button';
import { Group } from '@platform/ui/Group';
import { MenuContent } from '@platform/ui/Menu';
@@ -21,8 +21,8 @@ import { getDestinationLabel, getSourceLabel } from '@workbench/invocation';
import { useActiveQueueProgress } from '@workbench/queue-integration/useActiveQueueProgress';
import { useOpenWorkbenchWidget } from '@workbench/useOpenWorkbenchWidget';
import { useWorkbenchSelector } from '@workbench/WorkbenchContext';
-import { ChevronDownIcon, ListOrderedIcon, PauseIcon, XIcon } from 'lucide-react';
-import { useCallback, useMemo } from 'react';
+import { ChevronDownIcon, ListOrderedIcon, ListXIcon, PauseIcon, XIcon } from 'lucide-react';
+import { useCallback, useMemo, useState, type MouseEvent, type PointerEvent, type ReactNode } from 'react';
import { useTranslation } from 'react-i18next';
const TOOLTIP_CONTENT_PROPS = { maxW: '22rem', p: '0' };
@@ -41,7 +41,9 @@ export const QueueCluster = () => {
const modelLoads = useModelLoads();
const openWorkbenchWidget = useOpenWorkbenchWidget();
const actions = useQueueMenuActions({ includeOpenQueue: true });
- const cancelCurrent = actions[0];
+ const [cancelCurrent, cancelAll] = actions;
+ const [isCancelHovered, setIsCancelHovered] = useState(false);
+ const [isShiftHeld, setIsShiftHeld] = useState(false);
const { progress: runningProgress, queueItems, summary } = useActiveQueueProgress();
const { current, remaining, total } = summary;
@@ -55,8 +57,41 @@ export const QueueCluster = () => {
const tone: QueueTone = isPaused && hasOpenWork ? 'paused' : hasOpenWork && isConnected ? 'running' : 'idle';
const progressValue = getDeterminateProgressFraction(runningProgress?.percentage);
const isCancellable = !cancelCurrent?.disabled;
+ const [lastCancellable, setLastCancellable] = useState(isCancellable);
+
+ // The "x" unmounts while hovered when the running job finishes, so its
+ // pointer-leave never fires; reset the gesture state with it.
+ if (isCancellable !== lastCancellable) {
+ setLastCancellable(isCancellable);
+
+ if (!isCancellable) {
+ setIsCancelHovered(false);
+ setIsShiftHeld(false);
+ }
+ }
+
+ const isCancelAllArmed = isCancelHovered && isShiftHeld && cancelAll !== undefined && !cancelAll.disabled;
const handleOpenQueue = useCallback(() => openWorkbenchWidget('queue'), [openWorkbenchWidget]);
+ const handleCancelPointerEnter = useCallback((event: PointerEvent<HTMLButtonElement>) => {
+ setIsCancelHovered(true);
+ setIsShiftHeld(event.shiftKey);
+ }, []);
+ const handleCancelPointerLeave = useCallback(() => {
+ setIsCancelHovered(false);
+ setIsShiftHeld(false);
+ }, []);
+ const handleCancelClick = useCallback(
+ (event: MouseEvent<HTMLButtonElement>) => {
+ if (event.shiftKey && cancelAll && !cancelAll.disabled) {
+ cancelAll.onClick();
+ return;
+ }
+
+ cancelCurrent?.onClick();
+ },
+ [cancelAll, cancelCurrent]
+ );
return (
<Menu.Root>
@@ -90,18 +125,31 @@ export const QueueCluster = () => {
</QueueButtonTooltip>
{isCancellable && cancelCurrent ? (
- <Tooltip content={cancelCurrent.label} showArrow>
+ <Tooltip
+ content={
+ isCancelAllArmed && cancelAll
+ ? cancelAll.label
+ : `${cancelCurrent.label} · ${t('topbar.queue.shiftCancelsAll')}`
+ }
+ showArrow
+ >
<IconButton
- aria-label={cancelCurrent.label}
+ aria-label={isCancelAllArmed && cancelAll ? cancelAll.label : cancelCurrent.label}
color="fg.error"
size="xs"
variant="outline"
- onClick={cancelCurrent.onClick}
+ onClick={handleCancelClick}
+ onPointerEnter={handleCancelPointerEnter}
+ onPointerLeave={handleCancelPointerLeave}
>
- <Icon as={XIcon} />
+ <Icon as={isCancelAllArmed ? ListXIcon : XIcon} />
</IconButton>
</Tooltip>
) : null}
+ {/* Shift over the hovered button swaps it to cancel-all live; pointer
+ events alone cannot see a bare shift press, so watch the keyboard
+ only while hovered. */}
+ {isCancelHovered ? <ShiftKeyWatcher onChange={setIsShiftHeld} /> : null}
<Menu.Trigger asChild>
<IconButton
@@ -130,6 +178,24 @@ export const QueueCluster = () => {
);
};
+const ShiftKeyWatcher = ({ onChange }: { onChange: (isShiftHeld: boolean) => void }) => {
+ useMountEffect(() => {
+ const readShift = (event: KeyboardEvent) => onChange(event.shiftKey);
+ const clearShift = () => onChange(false);
+
+ window.addEventListener('keydown', readShift);
+ window.addEventListener('keyup', readShift);
+ window.addEventListener('blur', clearShift);
+ return () => {
+ window.removeEventListener('keydown', readShift);
+ window.removeEventListener('keyup', readShift);
+ window.removeEventListener('blur', clearShift);
+ };
+ });
+
+ return null;
+};
+
const QueueButtonTooltip = ({
children,
current,