File tree Expand file tree Collapse file tree 7 files changed +35
-28
lines changed
invokeai/frontend/web/src
app/store/middleware/listenerMiddleware/listeners Expand file tree Collapse file tree 7 files changed +35
-28
lines changed Original file line number Diff line number Diff line change @@ -3,7 +3,7 @@ import { startAppListening } from '..';
33import { $logger } from 'app/logging/logger' ;
44import { getBaseLayerBlob } from 'features/canvas/util/getBaseLayerBlob' ;
55import { addToast } from 'features/system/store/systemSlice' ;
6- import { copyBlobToClipboard } from 'features/canvas /util/copyBlobToClipboard' ;
6+ import { copyBlobToClipboard } from 'features/system /util/copyBlobToClipboard' ;
77import { t } from 'i18next' ;
88
99export const addCanvasCopiedToClipboardListener = ( ) => {
@@ -15,10 +15,12 @@ export const addCanvasCopiedToClipboardListener = () => {
1515 . child ( { namespace : 'canvasCopiedToClipboardListener' } ) ;
1616 const state = getState ( ) ;
1717
18- const blob = await getBaseLayerBlob ( state ) ;
18+ try {
19+ const blob = getBaseLayerBlob ( state ) ;
1920
20- if ( ! blob ) {
21- moduleLog . error ( 'Problem getting base layer blob' ) ;
21+ copyBlobToClipboard ( blob ) ;
22+ } catch ( err ) {
23+ moduleLog . error ( String ( err ) ) ;
2224 dispatch (
2325 addToast ( {
2426 title : t ( 'toast.problemCopyingCanvas' ) ,
@@ -29,8 +31,6 @@ export const addCanvasCopiedToClipboardListener = () => {
2931 return ;
3032 }
3133
32- copyBlobToClipboard ( blob ) ;
33-
3434 dispatch (
3535 addToast ( {
3636 title : t ( 'toast.canvasCopiedClipboard' ) ,
Original file line number Diff line number Diff line change @@ -15,10 +15,11 @@ export const addCanvasDownloadedAsImageListener = () => {
1515 . child ( { namespace : 'canvasSavedToGalleryListener' } ) ;
1616 const state = getState ( ) ;
1717
18- const blob = await getBaseLayerBlob ( state ) ;
19-
20- if ( ! blob ) {
21- moduleLog . error ( 'Problem getting base layer blob' ) ;
18+ let blob ;
19+ try {
20+ blob = await getBaseLayerBlob ( state ) ;
21+ } catch ( err ) {
22+ moduleLog . error ( String ( err ) ) ;
2223 dispatch (
2324 addToast ( {
2425 title : t ( 'toast.problemDownloadingCanvas' ) ,
Original file line number Diff line number Diff line change @@ -14,10 +14,11 @@ export const addCanvasImageToControlNetListener = () => {
1414 const log = logger ( 'canvas' ) ;
1515 const state = getState ( ) ;
1616
17- const blob = await getBaseLayerBlob ( state ) ;
18-
19- if ( ! blob ) {
20- log . error ( 'Problem getting base layer blob' ) ;
17+ let blob ;
18+ try {
19+ blob = await getBaseLayerBlob ( state ) ;
20+ } catch ( err ) {
21+ log . error ( String ( err ) ) ;
2122 dispatch (
2223 addToast ( {
2324 title : t ( 'toast.problemSavingCanvas' ) ,
Original file line number Diff line number Diff line change @@ -13,10 +13,11 @@ export const addCanvasSavedToGalleryListener = () => {
1313 const log = logger ( 'canvas' ) ;
1414 const state = getState ( ) ;
1515
16- const blob = await getBaseLayerBlob ( state ) ;
17-
18- if ( ! blob ) {
19- log . error ( 'Problem getting base layer blob' ) ;
16+ let blob ;
17+ try {
18+ blob = await getBaseLayerBlob ( state ) ;
19+ } catch ( err ) {
20+ log . error ( String ( err ) ) ;
2021 dispatch (
2122 addToast ( {
2223 title : t ( 'toast.problemSavingCanvas' ) ,
Original file line number Diff line number Diff line change @@ -9,7 +9,7 @@ export const getBaseLayerBlob = async (state: RootState) => {
99 const canvasBaseLayer = getCanvasBaseLayer ( ) ;
1010
1111 if ( ! canvasBaseLayer ) {
12- return ;
12+ throw new Error ( 'Problem getting base layer blob' ) ;
1313 }
1414
1515 const {
Original file line number Diff line number Diff line change 11/**
22 * Copies a blob to the clipboard by calling navigator.clipboard.write().
33 */
4- export const copyBlobToClipboard = ( blob : Blob ) => {
4+ export const copyBlobToClipboard = (
5+ blob : Promise < Blob > ,
6+ type = 'image/png'
7+ ) => {
58 navigator . clipboard . write ( [
69 new ClipboardItem ( {
7- [ blob . type ] : blob ,
10+ [ type ] : blob ,
811 } ) ,
912 ] ) ;
1013} ;
Original file line number Diff line number Diff line change 11import { useAppToaster } from 'app/components/Toaster' ;
22import { useCallback , useMemo } from 'react' ;
33import { useTranslation } from 'react-i18next' ;
4+ import { copyBlobToClipboard } from 'features/system/util/copyBlobToClipboard' ;
45
56export const useCopyImageToClipboard = ( ) => {
67 const toaster = useAppToaster ( ) ;
@@ -22,13 +23,13 @@ export const useCopyImageToClipboard = () => {
2223 } ) ;
2324 }
2425 try {
25- const response = await fetch ( image_url ) ;
26- const blob = await response . blob ( ) ;
27- await navigator . clipboard . write ( [
28- new ClipboardItem ( {
29- [ blob . type ] : blob ,
30- } ) ,
31- ] ) ;
26+ const getImageBlob = async ( ) => {
27+ const response = await fetch ( image_url ) ;
28+ return await response . blob ( ) ;
29+ } ;
30+
31+ copyBlobToClipboard ( getImageBlob ( ) ) ;
32+
3233 toaster ( {
3334 title : t ( 'toast.imageCopied' ) ,
3435 status : 'success' ,
You can’t perform that action at this time.
0 commit comments