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-61271] Upgrade to Electron v33.0.2 #3181

Merged
merged 3 commits into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
9 changes: 5 additions & 4 deletions e2e/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions e2e/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"electron-mocha": "12.2.0",
"fast-xml-parser": "^4.4.1",
"mochawesome": "7.1.3",
"node-abi": "3.71.0",
"playwright": "1.42.0",
"ps-node": "0.1.6",
"recursive-readdir": "2.2.3",
Expand Down
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@
"copy-webpack-plugin": "10.2.4",
"cross-env": "7.0.3",
"css-loader": "6.7.1",
"electron": "31.2.1",
"electron": "33.0.2",
"electron-builder": "24.13.3",
"electron-connect": "0.6.3",
"eslint": "8.57.0",
Expand Down
33 changes: 33 additions & 0 deletions patches/electron+33.0.2.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
diff --git a/node_modules/electron/electron.d.ts b/node_modules/electron/electron.d.ts
Copy link
Member Author

Choose a reason for hiding this comment

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

This patch is needed due to an issue in Electron's typing for this module that caused a bug. A fix is waiting to be merged, but for now we'll use this patch.
electron/electron#44391

index 2de7557..0d0fa34 100644
--- a/node_modules/electron/electron.d.ts
+++ b/node_modules/electron/electron.d.ts
@@ -9847,23 +9847,23 @@ declare namespace Electron {
*
* @platform darwin,win32
*/
- on(event: 'speed-limit-change', listener: () => void): this;
+ on(event: 'speed-limit-change', listener: (limit: number) => void): this;
/**
* @platform darwin,win32
*/
- off(event: 'speed-limit-change', listener: () => void): this;
+ off(event: 'speed-limit-change', listener: (limit: number) => void): this;
/**
* @platform darwin,win32
*/
- once(event: 'speed-limit-change', listener: () => void): this;
+ once(event: 'speed-limit-change', listener: (limit: number) => void): this;
/**
* @platform darwin,win32
*/
- addListener(event: 'speed-limit-change', listener: () => void): this;
+ addListener(event: 'speed-limit-change', listener: (limit: number) => void): this;
/**
* @platform darwin,win32
*/
- removeListener(event: 'speed-limit-change', listener: () => void): this;
+ removeListener(event: 'speed-limit-change', listener: (limit: number) => void): this;
/**
* Emitted when the system is suspending.
*/
20 changes: 11 additions & 9 deletions src/main/menus/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// See LICENSE.txt for license information.
'use strict';

import type {MenuItemConstructorOptions, MenuItem, BrowserWindow} from 'electron';
import type {MenuItemConstructorOptions, MenuItem} from 'electron';
import {app, ipcMain, Menu, session, shell, clipboard} from 'electron';
import log from 'electron-log';

Expand Down Expand Up @@ -149,14 +149,16 @@ export function createTemplate(config: Config, updateManager: UpdateManager) {
}
return 'Ctrl+Shift+I';
})(),
click(item: Electron.MenuItem, focusedWindow?: BrowserWindow) {
if (focusedWindow) {
// toggledevtools opens it in the last known position, so sometimes it goes below the browserview
if (focusedWindow.webContents.isDevToolsOpened()) {
focusedWindow.webContents.closeDevTools();
} else {
focusedWindow.webContents.openDevTools({mode: 'detach'});
}
click() {
Copy link
Member Author

Choose a reason for hiding this comment

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

This used to matter when we had the Settings and Main windows, but now we just have the main one so we can assume we're using that one.

const mainWindow = MainWindow.get();
if (!mainWindow) {
return;
}

if (mainWindow.webContents.isDevToolsOpened()) {
mainWindow.webContents.closeDevTools();
} else {
mainWindow.webContents.openDevTools({mode: 'detach'});
}
},
},
Expand Down
26 changes: 14 additions & 12 deletions src/main/views/MattermostBrowserView.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,14 @@ jest.mock('electron', () => ({
on: jest.fn(),
getTitle: () => 'title',
getURL: () => 'http://server-1.com',
clearHistory: jest.fn(),
send: jest.fn(),
canGoBack: jest.fn(),
canGoForward: jest.fn(),
goToOffset: jest.fn(),
canGoToOffset: jest.fn(),
navigationHistory: {
clear: jest.fn(),
canGoBack: jest.fn(),
canGoForward: jest.fn(),
goToOffset: jest.fn(),
canGoToOffset: jest.fn(),
},
},
})),
ipcMain: {
Expand Down Expand Up @@ -206,18 +208,18 @@ describe('main/views/MattermostBrowserView', () => {
});

it('should only go to offset if it can', () => {
mattermostView.browserView.webContents.canGoToOffset.mockReturnValue(false);
mattermostView.browserView.webContents.navigationHistory.canGoToOffset.mockReturnValue(false);
mattermostView.goToOffset(1);
expect(mattermostView.browserView.webContents.goToOffset).not.toBeCalled();
expect(mattermostView.browserView.webContents.navigationHistory.goToOffset).not.toBeCalled();

mattermostView.browserView.webContents.canGoToOffset.mockReturnValue(true);
mattermostView.browserView.webContents.navigationHistory.canGoToOffset.mockReturnValue(true);
mattermostView.goToOffset(1);
expect(mattermostView.browserView.webContents.goToOffset).toBeCalled();
expect(mattermostView.browserView.webContents.navigationHistory.goToOffset).toBeCalled();
});

it('should call reload if an error occurs', () => {
mattermostView.browserView.webContents.canGoToOffset.mockReturnValue(true);
mattermostView.browserView.webContents.goToOffset.mockImplementation(() => {
mattermostView.browserView.webContents.navigationHistory.canGoToOffset.mockReturnValue(true);
mattermostView.browserView.webContents.navigationHistory.goToOffset.mockImplementation(() => {
throw new Error('hi');
});
mattermostView.goToOffset(1);
Expand Down Expand Up @@ -355,7 +357,7 @@ describe('main/views/MattermostBrowserView', () => {
it('should erase history and set isAtRoot when navigating to root URL', () => {
mattermostView.atRoot = false;
mattermostView.updateHistoryButton();
expect(mattermostView.browserView.webContents.clearHistory).toHaveBeenCalled();
expect(mattermostView.browserView.webContents.navigationHistory.clear).toHaveBeenCalled();
expect(mattermostView.isAtRoot).toBe(true);
});
});
Expand Down
10 changes: 5 additions & 5 deletions src/main/views/MattermostBrowserView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,9 @@ export class MattermostBrowserView extends EventEmitter {
};

goToOffset = (offset: number) => {
if (this.browserView.webContents.canGoToOffset(offset)) {
if (this.browserView.webContents.navigationHistory.canGoToOffset(offset)) {
try {
this.browserView.webContents.goToOffset(offset);
this.browserView.webContents.navigationHistory.goToOffset(offset);
this.updateHistoryButton();
} catch (error) {
this.log.error(error);
Expand All @@ -162,15 +162,15 @@ export class MattermostBrowserView extends EventEmitter {

getBrowserHistoryStatus = () => {
if (this.currentURL?.toString() === this.view.url.toString()) {
this.browserView.webContents.clearHistory();
this.browserView.webContents.navigationHistory.clear();
this.atRoot = true;
} else {
this.atRoot = false;
}

return {
canGoBack: this.browserView.webContents.canGoBack(),
canGoForward: this.browserView.webContents.canGoForward(),
canGoBack: this.browserView.webContents.navigationHistory.canGoBack(),
canGoForward: this.browserView.webContents.navigationHistory.canGoForward(),
};
};

Expand Down
Loading