Skip to content

Commit

Permalink
chore: bump electron to the latest version 33.2.0 (WPB-11996) (#8352)
Browse files Browse the repository at this point in the history
* chore: bump electron to 33.2.0

* chore: create helper function to send menu events to web content

* runfix: use helper function to address electron api type change

* chore: log helper function errors
  • Loading branch information
V-Gira committed Nov 15, 2024
1 parent a707f4b commit 491a312
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 51 deletions.
80 changes: 40 additions & 40 deletions electron/src/menu/system.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import {config} from '../settings/config';
import {settings} from '../settings/ConfigurationPersistence';
import {SettingsType} from '../settings/SettingsType';
import {WindowManager} from '../window/WindowManager';
import {openExternal} from '../window/WindowUtil';
import {openExternal, sendToWebContents} from '../window/WindowUtil';

const launchCmd = process.env.APPIMAGE || process.execPath;

Expand Down Expand Up @@ -75,8 +75,8 @@ const aboutTemplate: MenuItemConstructorOptions = {
};

const signOutTemplate: MenuItemConstructorOptions = {
click: (_menuItem, browserWindow) =>
browserWindow?.webContents.send(EVENT_TYPE.UI.SYSTEM_MENU, EVENT_TYPE.ACTION.SIGN_OUT),
click: (_menuItem, baseWindow) =>
sendToWebContents(baseWindow, EVENT_TYPE.UI.SYSTEM_MENU, EVENT_TYPE.ACTION.SIGN_OUT),
label: locale.getText('menuSignOut'),
};

Expand All @@ -92,55 +92,55 @@ const conversationTemplate: MenuItemConstructorOptions = {
submenu: [
{
accelerator: 'CmdOrCtrl+N',
click: (_menuItem, browserWindow) =>
browserWindow?.webContents.send(EVENT_TYPE.UI.SYSTEM_MENU, EVENT_TYPE.CONVERSATION.START),
click: (_menuItem, baseWindow) =>
sendToWebContents(baseWindow, EVENT_TYPE.UI.SYSTEM_MENU, EVENT_TYPE.CONVERSATION.START),
label: locale.getText('menuStart'),
},
{
accelerator: 'CmdOrCtrl+K',
click: (_menuItem, browserWindow) =>
browserWindow?.webContents.send(EVENT_TYPE.UI.SYSTEM_MENU, EVENT_TYPE.CONVERSATION.SEARCH),
click: (_menuItem, baseWindow) =>
sendToWebContents(baseWindow, EVENT_TYPE.UI.SYSTEM_MENU, EVENT_TYPE.CONVERSATION.SEARCH),
label: locale.getText('menuSearch'),
},
separatorTemplate,
{
click: (_menuItem, browserWindow) =>
browserWindow?.webContents.send(EVENT_TYPE.UI.SYSTEM_MENU, EVENT_TYPE.CONVERSATION.PING),
click: (_menuItem, baseWindow) =>
sendToWebContents(baseWindow, EVENT_TYPE.UI.SYSTEM_MENU, EVENT_TYPE.CONVERSATION.PING),
label: locale.getText('menuPing'),
},
{
click: (_menuItem, browserWindow) =>
browserWindow?.webContents.send(EVENT_TYPE.UI.SYSTEM_MENU, EVENT_TYPE.CONVERSATION.CALL),
click: (_menuItem, baseWindow) =>
sendToWebContents(baseWindow, EVENT_TYPE.UI.SYSTEM_MENU, EVENT_TYPE.CONVERSATION.CALL),
label: locale.getText('menuCall'),
},
{
click: (_menuItem, browserWindow) =>
browserWindow?.webContents.send(EVENT_TYPE.UI.SYSTEM_MENU, EVENT_TYPE.CONVERSATION.VIDEO_CALL),
click: (_menuItem, baseWindow) =>
sendToWebContents(baseWindow, EVENT_TYPE.UI.SYSTEM_MENU, EVENT_TYPE.CONVERSATION.VIDEO_CALL),
label: locale.getText('menuVideoCall'),
},
separatorTemplate,
{
accelerator: 'CmdOrCtrl+I',
click: (_menuItem, browserWindow) =>
browserWindow?.webContents.send(EVENT_TYPE.UI.SYSTEM_MENU, EVENT_TYPE.CONVERSATION.PEOPLE),
click: (_menuItem, baseWindow) =>
sendToWebContents(baseWindow, EVENT_TYPE.UI.SYSTEM_MENU, EVENT_TYPE.CONVERSATION.PEOPLE),
label: locale.getText('menuPeople'),
},
{
accelerator: 'Shift+CmdOrCtrl+K',
click: (_menuItem, browserWindow) =>
browserWindow?.webContents.send(EVENT_TYPE.UI.SYSTEM_MENU, EVENT_TYPE.CONVERSATION.ADD_PEOPLE),
click: (_menuItem, baseWindow) =>
sendToWebContents(baseWindow, EVENT_TYPE.UI.SYSTEM_MENU, EVENT_TYPE.CONVERSATION.ADD_PEOPLE),
label: locale.getText('menuAddPeople'),
},
separatorTemplate,
{
accelerator: 'CmdOrCtrl+D',
click: (_menuItem, browserWindow) =>
browserWindow?.webContents.send(EVENT_TYPE.UI.SYSTEM_MENU, EVENT_TYPE.CONVERSATION.ARCHIVE),
click: (_menuItem, baseWindow) =>
sendToWebContents(baseWindow, EVENT_TYPE.UI.SYSTEM_MENU, EVENT_TYPE.CONVERSATION.ARCHIVE),
label: locale.getText('menuArchive'),
},
{
click: (_menuItem, browserWindow) =>
browserWindow?.webContents.send(EVENT_TYPE.UI.SYSTEM_MENU, EVENT_TYPE.CONVERSATION.DELETE),
click: (_menuItem, baseWindow) =>
sendToWebContents(baseWindow, EVENT_TYPE.UI.SYSTEM_MENU, EVENT_TYPE.CONVERSATION.DELETE),
label: locale.getText('menuDelete'),
},
],
Expand Down Expand Up @@ -188,34 +188,34 @@ const editTemplate: MenuItemConstructorOptions = {
submenu: [
{
accelerator: 'CmdOrCtrl+Z',
click: (_menuItem, browserWindow) => browserWindow?.webContents.send(EVENT_TYPE.EDIT.UNDO),
click: (_menuItem, baseWindow) => sendToWebContents(baseWindow, EVENT_TYPE.EDIT.UNDO),
label: locale.getText('menuUndo'),
},
{
accelerator: 'Shift+CmdOrCtrl+Z',
click: (_menuItem, browserWindow) => browserWindow?.webContents.send(EVENT_TYPE.EDIT.REDO),
click: (_menuItem, baseWindow) => sendToWebContents(baseWindow, EVENT_TYPE.EDIT.REDO),
label: locale.getText('menuRedo'),
},
separatorTemplate,
{
accelerator: 'CmdOrCtrl+X',
click: (_menuItem, browserWindow) => browserWindow?.webContents.send(EVENT_TYPE.EDIT.CUT),
click: (_menuItem, baseWindow) => sendToWebContents(baseWindow, EVENT_TYPE.EDIT.CUT),
label: locale.getText('menuCut'),
},
{
accelerator: 'CmdOrCtrl+C',
click: (_menuItem, browserWindow) => browserWindow?.webContents.send(EVENT_TYPE.EDIT.COPY),
click: (_menuItem, baseWindow) => sendToWebContents(baseWindow, EVENT_TYPE.EDIT.COPY),
label: locale.getText('menuCopy'),
},
{
accelerator: 'CmdOrCtrl+V',
click: (_menuItem, browserWindow) => browserWindow?.webContents.send(EVENT_TYPE.EDIT.PASTE),
click: (_menuItem, baseWindow) => sendToWebContents(baseWindow, EVENT_TYPE.EDIT.PASTE),
label: locale.getText('menuPaste'),
},
separatorTemplate,
{
accelerator: 'CmdOrCtrl+A',
click: (_menuItem, browserWindow) => browserWindow?.webContents.send(EVENT_TYPE.EDIT.SELECT_ALL),
click: (_menuItem, baseWindow) => sendToWebContents(baseWindow, EVENT_TYPE.EDIT.SELECT_ALL),
label: locale.getText('menuSelectAll'),
},
],
Expand All @@ -236,14 +236,14 @@ const windowTemplate: MenuItemConstructorOptions = {
separatorTemplate,
{
accelerator: EnvironmentUtil.platform.IS_MAC_OS ? 'Alt+Cmd+Up' : 'Alt+Shift+Up',
click: (_menuItem, browserWindow) =>
browserWindow?.webContents.send(EVENT_TYPE.UI.SYSTEM_MENU, EVENT_TYPE.CONVERSATION.SHOW_NEXT),
click: (_menuItem, baseWindow) =>
sendToWebContents(baseWindow, EVENT_TYPE.UI.SYSTEM_MENU, EVENT_TYPE.CONVERSATION.SHOW_NEXT),
label: locale.getText('menuNextConversation'),
},
{
accelerator: EnvironmentUtil.platform.IS_MAC_OS ? 'Alt+Cmd+Down' : 'Alt+Shift+Down',
click: (_menuItem, browserWindow) =>
browserWindow?.webContents.send(EVENT_TYPE.UI.SYSTEM_MENU, EVENT_TYPE.CONVERSATION.SHOW_PREVIOUS),
click: (_menuItem, baseWindow) =>
sendToWebContents(baseWindow, EVENT_TYPE.UI.SYSTEM_MENU, EVENT_TYPE.CONVERSATION.SHOW_PREVIOUS),
label: locale.getText('menuPreviousConversation'),
},
],
Expand Down Expand Up @@ -296,8 +296,8 @@ const darwinTemplate: MenuItemConstructorOptions = {
separatorTemplate,
{
accelerator: 'Command+,',
click: (_menuItem, browserWindow) =>
browserWindow?.webContents.send(EVENT_TYPE.UI.SYSTEM_MENU, EVENT_TYPE.PREFERENCES.SHOW),
click: (_menuItem, baseWindow) =>
sendToWebContents(baseWindow, EVENT_TYPE.UI.SYSTEM_MENU, EVENT_TYPE.PREFERENCES.SHOW),
label: locale.getText('menuPreferences'),
},
separatorTemplate,
Expand Down Expand Up @@ -337,8 +337,8 @@ const win32Template: MenuItemConstructorOptions = {
submenu: [
{
accelerator: 'Ctrl+,',
click: (_menuItem, browserWindow) =>
browserWindow?.webContents.send(EVENT_TYPE.UI.SYSTEM_MENU, EVENT_TYPE.PREFERENCES.SHOW),
click: (_menuItem, baseWindow) =>
sendToWebContents(baseWindow, EVENT_TYPE.UI.SYSTEM_MENU, EVENT_TYPE.PREFERENCES.SHOW),
label: locale.getText('menuSettings'),
},
localeTemplate,
Expand Down Expand Up @@ -429,8 +429,8 @@ export const createMenu = (isFullScreen: boolean): Menu => {

const muteShortcut: MenuItemConstructorOptions = {
accelerator: muteAccelerator,
click: (_menuItem, browserWindow) =>
browserWindow?.webContents.send(EVENT_TYPE.UI.SYSTEM_MENU, EVENT_TYPE.CONVERSATION.TOGGLE_MUTE),
click: (_menuItem, baseWindow) =>
sendToWebContents(baseWindow, EVENT_TYPE.UI.SYSTEM_MENU, EVENT_TYPE.CONVERSATION.TOGGLE_MUTE),
label: 'Toggle mute',
visible: false,
};
Expand All @@ -442,7 +442,7 @@ export const createMenu = (isFullScreen: boolean): Menu => {

return {
accelerator: switchAccelerator,
click: (_menuItem, browserWindow) => browserWindow?.webContents.send(EVENT_TYPE.ACTION.SWITCH_ACCOUNT, index),
click: (_menuItem, baseWindow) => sendToWebContents(baseWindow, EVENT_TYPE.ACTION.SWITCH_ACCOUNT, index),
label: `Switch to Account ${index + 1}`,
visible: false,
};
Expand All @@ -455,8 +455,8 @@ export const createMenu = (isFullScreen: boolean): Menu => {
if (Array.isArray(editTemplate.submenu)) {
editTemplate.submenu.push(separatorTemplate, {
accelerator: 'Ctrl+,',
click: (_menuItem, browserWindow) =>
browserWindow?.webContents.send(EVENT_TYPE.UI.SYSTEM_MENU, EVENT_TYPE.PREFERENCES.SHOW),
click: (_menuItem, baseWindow) =>
sendToWebContents(baseWindow, EVENT_TYPE.UI.SYSTEM_MENU, EVENT_TYPE.PREFERENCES.SHOW),
label: locale.getText('menuPreferences'),
});
}
Expand Down
9 changes: 5 additions & 4 deletions electron/src/preload/menu/preload-context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import {
import {EVENT_TYPE} from '../../lib/eventType';
import * as locale from '../../locale';
import {config} from '../../settings/config';
import {sendToWebContents} from '../../window/WindowUtil';

const remote = require('@electron/remote');

Expand Down Expand Up @@ -72,25 +73,25 @@ const createTextMenu = (params: ContextMenuParams, webContents: WebContents): El

const template: MenuItemConstructorOptions[] = [
{
click: (_menuItem, browserWindow) => browserWindow?.webContents.send(EVENT_TYPE.EDIT.CUT),
click: (_menuItem, baseWindow) => sendToWebContents(baseWindow, EVENT_TYPE.EDIT.CUT),
enabled: editFlags.canCut,
label: locale.getText('menuCut'),
},
{
click: (_menuItem, browserWindow) => browserWindow?.webContents.send(EVENT_TYPE.EDIT.COPY),
click: (_menuItem, baseWindow) => sendToWebContents(baseWindow, EVENT_TYPE.EDIT.COPY),
enabled: editFlags.canCopy,
label: locale.getText('menuCopy'),
},
{
click: (_menuItem, browserWindow) => browserWindow?.webContents.send(EVENT_TYPE.EDIT.PASTE),
click: (_menuItem, baseWindow) => sendToWebContents(baseWindow, EVENT_TYPE.EDIT.PASTE),
enabled: editFlags.canPaste,
label: locale.getText('menuPaste'),
},
{
type: 'separator',
},
{
click: (_menuItem, browserWindow) => browserWindow?.webContents.send(EVENT_TYPE.EDIT.SELECT_ALL),
click: (_menuItem, baseWindow) => sendToWebContents(baseWindow, EVENT_TYPE.EDIT.SELECT_ALL),
enabled: editFlags.canSelectAll,
label: locale.getText('menuSelectAll'),
},
Expand Down
14 changes: 13 additions & 1 deletion electron/src/window/WindowUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*
*/

import {BrowserWindow, screen, shell} from 'electron';
import {BaseWindow, BrowserWindow, screen, shell} from 'electron';

import * as path from 'path';
import {URL} from 'url';
Expand Down Expand Up @@ -79,6 +79,18 @@ export const openExternal = async (url: string, httpsOnly: boolean = false): Pro
}
};

export const sendToWebContents = (baseWindow: BaseWindow | undefined, channel: string, ...args: any[]) => {
if (baseWindow instanceof BrowserWindow) {
try {
baseWindow.webContents.send(channel, ...args);
} catch (error) {
logger.error('Failed to send event to webContents', error);
}
} else {
logger.error("This action's target is not an instance of BrowserWindow.");
}
};

export const getNewWindowOptions = ({
parent,
title = '',
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
"cross-env": "7.0.3",
"css-loader": "7.1.2",
"dotenv": "16.4.5",
"electron": "29.4.6",
"electron": "33.2.0",
"electron-builder": "24.13.3",
"electron-mocha": "12.3.1",
"electron-packager": "17.1.2",
Expand Down
10 changes: 5 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7527,16 +7527,16 @@ __metadata:
languageName: node
linkType: hard

"electron@npm:29.4.6":
version: 29.4.6
resolution: "electron@npm:29.4.6"
"electron@npm:33.2.0":
version: 33.2.0
resolution: "electron@npm:33.2.0"
dependencies:
"@electron/get": ^2.0.0
"@types/node": ^20.9.0
extract-zip: ^2.0.1
bin:
electron: cli.js
checksum: 14f4ae506032227083e59db3188863c71cd89c9df9490cc4bb014af55c9d93bd585093e06db4f221e897aea5b01805d4ad11e5f6ae7b41cbe493d84d55e5ffbf
checksum: 4feacc8923fe4ab45da45d34823f949231da425c83ea2db2e483c2531f0320a1279a5b65913f447e145ab0a3f4e190bc192ed3a63ebe17a06347156e2ec52081
languageName: node
linkType: hard

Expand Down Expand Up @@ -17883,7 +17883,7 @@ __metadata:
cross-env: 7.0.3
css-loader: 7.1.2
dotenv: 16.4.5
electron: 29.4.6
electron: 33.2.0
electron-builder: 24.13.3
electron-dl: ^3.5.2
electron-mocha: 12.3.1
Expand Down

0 comments on commit 491a312

Please sign in to comment.