Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MM-62709] Patched electron-context-menu to use WebContentsView, avoid using electron-dl #3291

Merged
merged 2 commits into from
Jan 30, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
105 changes: 105 additions & 0 deletions patches/electron-context-menu+4.0.4.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
diff --git a/node_modules/electron-context-menu/index.d.ts b/node_modules/electron-context-menu/index.d.ts
index 468e48b..e182878 100644
--- a/node_modules/electron-context-menu/index.d.ts
+++ b/node_modules/electron-context-menu/index.d.ts
@@ -5,6 +5,7 @@ import {
type MenuItemConstructorOptions,
type Event as ElectronEvent,
type WebContents,
+ type WebContentsView,
} from 'electron';

export type Labels = {
@@ -135,7 +136,7 @@ export type Options = {
Window or WebView to add the context menu to.
When not specified, the context menu will be added to all existing and new windows.
*/
- readonly window?: BrowserWindow | BrowserView | Electron.WebviewTag | WebContents;
+ readonly window?: BrowserWindow | BrowserView | Electron.WebviewTag | WebContents | WebContentsView;

/**
Should return an array of [menu items](https://electronjs.org/docs/api/menu-item) to be prepended to the context menu.
@@ -145,7 +146,7 @@ export type Options = {
readonly prepend?: (
defaultActions: Actions,
parameters: ContextMenuParams,
- browserWindow: BrowserWindow | BrowserView | Electron.WebviewTag | WebContents,
+ browserWindow: BrowserWindow | BrowserView | Electron.WebviewTag | WebContents | WebContentsView,
event: ElectronEvent
) => MenuItemConstructorOptions[];

@@ -157,7 +158,7 @@ export type Options = {
readonly append?: (
defaultActions: Actions,
parameters: ContextMenuParams,
- browserWindow: BrowserWindow | BrowserView | Electron.WebviewTag | WebContents,
+ browserWindow: BrowserWindow | BrowserView | Electron.WebviewTag | WebContents | WebContentsView,
event: ElectronEvent
) => MenuItemConstructorOptions[];

@@ -343,7 +344,7 @@ export type Options = {
readonly menu?: (
defaultActions: Actions,
parameters: ContextMenuParams,
- browserWindow: BrowserWindow | BrowserView | Electron.WebviewTag | WebContents,
+ browserWindow: BrowserWindow | BrowserView | Electron.WebviewTag | WebContents | WebContentsView,
dictionarySuggestions: MenuItemConstructorOptions[],
event: ElectronEvent
) => MenuItemConstructorOptions[];
diff --git a/node_modules/electron-context-menu/index.js b/node_modules/electron-context-menu/index.js
index b10daea..ea2f891 100644
--- a/node_modules/electron-context-menu/index.js
+++ b/node_modules/electron-context-menu/index.js
@@ -1,7 +1,6 @@
import process from 'node:process';
import electron from 'electron';
import cliTruncate from 'cli-truncate';
-import {download} from 'electron-dl';
import isDev from 'electron-is-dev';

const webContents = win => win.webContents ?? (win.id && win);
@@ -130,7 +129,7 @@ const create = (win, options) => {
visible: properties.mediaType === 'image',
click(menuItem) {
properties.srcURL = menuItem.transform ? menuItem.transform(properties.srcURL) : properties.srcURL;
- download(win, properties.srcURL);
+ win.webContents.downloadURL(properties.srcURL);
},
}),
saveImageAs: decorateMenuItem({
@@ -139,7 +138,7 @@ const create = (win, options) => {
visible: properties.mediaType === 'image',
click(menuItem) {
properties.srcURL = menuItem.transform ? menuItem.transform(properties.srcURL) : properties.srcURL;
- download(win, properties.srcURL, {saveAs: true});
+ win.webContents.downloadURL(properties.srcURL, {saveAs: true});
},
}),
saveVideo: decorateMenuItem({
@@ -148,7 +147,7 @@ const create = (win, options) => {
visible: properties.mediaType === 'video',
click(menuItem) {
properties.srcURL = menuItem.transform ? menuItem.transform(properties.srcURL) : properties.srcURL;
- download(win, properties.srcURL);
+ win.webContents.downloadURL(properties.srcURL);
},
}),
saveVideoAs: decorateMenuItem({
@@ -157,7 +156,7 @@ const create = (win, options) => {
visible: properties.mediaType === 'video',
click(menuItem) {
properties.srcURL = menuItem.transform ? menuItem.transform(properties.srcURL) : properties.srcURL;
- download(win, properties.srcURL, {saveAs: true});
+ win.webContents.downloadURL(properties.srcURL, {saveAs: true});
},
}),
copyLink: decorateMenuItem({
@@ -179,7 +178,7 @@ const create = (win, options) => {
visible: properties.linkURL.length > 0 && properties.mediaType === 'none',
click(menuItem) {
properties.linkURL = menuItem.transform ? menuItem.transform(properties.linkURL) : properties.linkURL;
- download(win, properties.linkURL, {saveAs: true});
+ win.webContents.downloadURL(properties.linkURL, {saveAs: true});
},
}),
copyImage: decorateMenuItem({
2 changes: 1 addition & 1 deletion src/main/contextMenu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export default class ContextMenu {
reload = () => {
this.dispose();

const options = {window: this.view.webContents, ...this.menuOptions};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What other areas that use context menu could this affect so we can keep in mind when we test this fix?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's anywhere that you right-click in the app and you get that little menu. This includes right-clicking on links and such.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@DHaussermann heads up that we want to also smoke test other context menu to make sure there are no other issues.

const options = {window: this.view, ...this.menuOptions};
this.menuDispose = electronContextMenu(options);
};
}
Loading