From 59e188c445985fce5e65a9a21f1078559f0ad39d Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Thu, 15 Jan 2026 09:07:36 +0000 Subject: [PATCH] Refactor context menu implementation - Replaced hacky `prepend` solution with `menu` option in `electron-context-menu`. - Explicitly defined menu items to ensure correct order and visibility. - Added `saveImageAs` option to the context menu. - Applied `stripTrackingFromUrl` transform to `copyLink` action properly. --- source/index.ts | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/source/index.ts b/source/index.ts index 9480c04..4b45eec 100644 --- a/source/index.ts +++ b/source/index.ts @@ -45,18 +45,30 @@ electronDebug({ electronDl(); electronContextMenu({ - showCopyImageAddress: true, - prepend(defaultActions) { - /* - TODO: Use menu option or use replacement of options (https://github.com/sindresorhus/electron-context-menu/issues/70) - See explanation for this hacky solution here: https://github.com/sindresorhus/caprine/pull/1169 - */ - defaultActions.copyLink({ + menu: (actions, _params, _browserWindow, dictionarySuggestions) => [ + ...dictionarySuggestions, + actions.separator(), + actions.learnSpelling({}), + actions.separator(), + actions.lookUpSelection({}), + actions.separator(), + actions.searchWithGoogle({}), + actions.separator(), + actions.cut({}), + actions.copy({}), + actions.paste({}), + ...(is.macos ? [] : [actions.selectAll({})]), + actions.separator(), + actions.saveImageAs({}), + actions.copyImage({}), + actions.copyImageAddress({}), + actions.separator(), + actions.copyLink({ transform: stripTrackingFromUrl, - }); - - return []; - }, + }), + actions.separator(), + ...(is.development ? [actions.inspect()] : []), + ], }); app.setAppUserModelId('com.sindresorhus.caprine');