From 0bc7070cf8f49eab6a2ab4fd6fbae651962f340a Mon Sep 17 00:00:00 2001 From: Dean Chen <51218137+locker95@users.noreply.github.com> Date: Thu, 16 Jul 2026 22:43:42 +0500 Subject: [PATCH] fix(desktop): gate image copy on decoded contents --- .../electron/image-context-menu.test.ts | 26 ++++++++++++++++--- apps/desktop/electron/image-context-menu.ts | 2 +- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/apps/desktop/electron/image-context-menu.test.ts b/apps/desktop/electron/image-context-menu.test.ts index ad82c5a125..e9e8b9e98b 100644 --- a/apps/desktop/electron/image-context-menu.test.ts +++ b/apps/desktop/electron/image-context-menu.test.ts @@ -25,7 +25,11 @@ function createActions() { test('keeps Copy Image available when Chromium omits a large image srcURL', () => { const { actions, calls } = createActions() - const items = imageContextMenuItems({ mediaType: 'image', srcURL: '', x: 100, y: 120 }, actions) + + const items = imageContextMenuItems( + { mediaType: 'image', hasImageContents: true, srcURL: '', x: 100, y: 120 }, + actions + ) assert.deepEqual( items.map(item => item.label), @@ -39,7 +43,11 @@ test('keeps Copy Image available when Chromium omits a large image srcURL', () = test('keeps URL-dependent image actions when srcURL is available', () => { const { actions, calls } = createActions() const url = 'https://example.com/image.png' - const items = imageContextMenuItems({ mediaType: 'image', srcURL: url, x: 5, y: 8 }, actions) + + const items = imageContextMenuItems( + { mediaType: 'image', hasImageContents: true, srcURL: url, x: 5, y: 8 }, + actions + ) assert.deepEqual( items.map(item => item.label), @@ -60,5 +68,17 @@ test('keeps URL-dependent image actions when srcURL is available', () => { test('does not add image actions for a non-image target', () => { const { actions } = createActions() - assert.deepEqual(imageContextMenuItems({ mediaType: 'none', srcURL: '', x: 0, y: 0 }, actions), []) + assert.deepEqual( + imageContextMenuItems({ mediaType: 'none', hasImageContents: false, srcURL: '', x: 0, y: 0 }, actions), + [] + ) +}) + +test('does not offer Copy Image when the target has no decoded image contents', () => { + const { actions } = createActions() + + assert.deepEqual( + imageContextMenuItems({ mediaType: 'image', hasImageContents: false, srcURL: '', x: 0, y: 0 }, actions), + [] + ) }) diff --git a/apps/desktop/electron/image-context-menu.ts b/apps/desktop/electron/image-context-menu.ts index 3d7e20b341..de817024c0 100644 --- a/apps/desktop/electron/image-context-menu.ts +++ b/apps/desktop/electron/image-context-menu.ts @@ -1,5 +1,5 @@ export function imageContextMenuItems(params, actions) { - if (params.mediaType !== 'image') { + if (params.mediaType !== 'image' || !params.hasImageContents) { return [] }