Skip to content

Commit

Permalink
⬆ Bump electron to 30.0.6 (#414)
Browse files Browse the repository at this point in the history
Signed-off-by: Marc Nuri <marc@marcnuri.com>
  • Loading branch information
manusa committed May 19, 2024
1 parent b36da2a commit 93b6d3e
Show file tree
Hide file tree
Showing 35 changed files with 414 additions and 397 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ electronim
## Features

- ⚛ Multi-platform: ElectronIM is available for Linux 🐧, Mac 🍏 and Windows.
- 🌍 Based on Chromium 122
- 🌍 Based on Chromium 124
- 🔔 Desktop notifications: ElectronIM will notify you using your native system notifications.
- 🧐 Spellchecker: ElectronIM contains spellchecker dictionaries for many languages,
if your language is not supported, just [file an issue](https://github.com/manusa/electronim/issues/new).
Expand Down
2 changes: 1 addition & 1 deletion build-config/electronim.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Improve your productivity by combining all your instant messaging applications (
### Features

- ⚛ Multi-platform: ElectronIM is available for Linux 🐧, Mac 🍏 and Windows.
- 🌍 Based on Chromium 122
- 🌍 Based on Chromium 124
- 🔔 Desktop notifications: ElectronIM will notify you using your native system notifications.
- 🧐 Spellchecker: ElectronIM contains spellchecker dictionaries for many languages,
if your language is not supported, just [file an issue](https://github.com/manusa/electronim/issues/new).
Expand Down
14 changes: 7 additions & 7 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 @@ -222,7 +222,7 @@
"dictionary-sv": "^3.0.1",
"dictionary-tr": "^1.3.3",
"dictionary-uk": "^2.1.1",
"electron": "29.3.3",
"electron": "30.0.6",
"htm": "3.1.1",
"markdown-it": "14.1.0",
"nodehun": "3.0.2",
Expand Down
58 changes: 35 additions & 23 deletions src/__tests__/electron.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,29 +14,15 @@
limitations under the License.
*/

const mockBrowserWindowInstance = () => {
const mockWebContentsViewInstance = () => {
const instance = {
listeners: {},
addBrowserView: jest.fn(),
destroy: jest.fn(),
getContentBounds: jest.fn(() => ({})),
isFullScreen: jest.fn(),
loadURL: jest.fn(),
minimize: jest.fn(),
on: jest.fn((eventName, func) => {
instance.listeners[eventName] = func;
}),
removeBrowserView: jest.fn(),
removeMenu: jest.fn(),
setAutoResize: jest.fn(),
setBounds: jest.fn(),
setBrowserView: jest.fn(),
setFullScreen: jest.fn(),
show: jest.fn(),
showInactive: jest.fn(),
webContents: {
loadedUrl: '',
browserWindowInstance: () => instance,
copy: jest.fn(),
copyImageAt: jest.fn(),
cut: jest.fn(),
Expand All @@ -61,9 +47,36 @@ const mockBrowserWindowInstance = () => {
return instance;
};

const mockBaseWindowInstance = () => {
const instance = {
listeners: {},
destroy: jest.fn(),
getContentBounds: jest.fn(() => ({})),
isFullScreen: jest.fn(),
loadURL: jest.fn(),
minimize: jest.fn(),
on: jest.fn((eventName, func) => {
instance.listeners[eventName] = func;
}),
removeMenu: jest.fn(),
setBounds: jest.fn(),
setFullScreen: jest.fn(),
show: jest.fn(),
showInactive: jest.fn(),
contentView: {
addChildView: jest.fn(view => instance.contentView.children.push(view)),
removeChildView: jest.fn(view => {
instance.contentView.children = instance.contentView.children.filter(child => child !== view);
}),
children: []
}
};
return instance;
};

const mockElectronInstance = ({...overriddenProps} = {}) => {
const browserViewInstance = mockBrowserWindowInstance();
const browserWindowInstance = mockBrowserWindowInstance();
const webContentsViewInstance = mockWebContentsViewInstance();
const baseWindowInstance = mockBaseWindowInstance();
const sessionInstance = {
clearCache: jest.fn(),
clearCodeCaches: jest.fn(),
Expand All @@ -76,10 +89,10 @@ const mockElectronInstance = ({...overriddenProps} = {}) => {
on: jest.fn()
};
const instance = {
BrowserView: jest.fn(() => browserViewInstance),
browserViewInstance,
BrowserWindow: jest.fn(() => browserWindowInstance),
browserWindowInstance,
WebContentsView: jest.fn(() => webContentsViewInstance),
webContentsViewInstance,
BaseWindow: jest.fn(() => baseWindowInstance),
baseWindowInstance,
Menu: jest.fn(),
MenuItem: jest.fn(),
Notification: jest.fn(),
Expand Down Expand Up @@ -139,8 +152,7 @@ const mockElectronInstance = ({...overriddenProps} = {}) => {
},
...overriddenProps
};
instance.BrowserWindow.fromWebContents = jest.fn(webContents => webContents.browserWindowInstance());
return instance;
};

module.exports = {mockBrowserWindowInstance, mockElectronInstance};
module.exports = {mockBaseWindowInstance, mockWebContentsViewInstance, mockElectronInstance};
3 changes: 2 additions & 1 deletion src/__tests__/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/

module.exports = {
mockBrowserWindowInstance: require('./electron.js').mockBrowserWindowInstance,
mockBaseWindowInstance: require('./electron.js').mockBaseWindowInstance,
mockWebContentsViewInstance: require('./electron.js').mockWebContentsViewInstance,
mockElectronInstance: require('./electron.js').mockElectronInstance
};
2 changes: 1 addition & 1 deletion src/__tests__/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ describe('Entrypoint test suite', () => {
test('Adds quit event listener', () => expect(app.on).toHaveBeenCalledWith('quit', main.quit));
test('Registers app keyboard shortcuts on every webContents created (web-contents-created)', () => {
expect(app.on)
.toHaveBeenCalledWith('web-contents-created', require('../browser-window').registerAppShortcuts);
.toHaveBeenCalledWith('web-contents-created', require('../base-window').registerAppShortcuts);
});
});
});
36 changes: 19 additions & 17 deletions src/about/__tests__/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,61 +15,63 @@
*/
describe('About module test suite', () => {
let electron;
let sender;
let about;
beforeEach(() => {
jest.resetModules();
jest.mock('electron', () => require('../../__tests__').mockElectronInstance());
electron = require('electron');
sender = electron.browserWindowInstance.webContents;
about = require('../');
});
describe('openAboutDialog', () => {
let openAbout;
beforeEach(() => {
openAbout = about.openAboutDialog(electron.baseWindowInstance);
});
describe('webPreferences', () => {
test('is sandboxed', () => {
// When
about.openAboutDialog({sender});
openAbout();
// Then
const BrowserView = electron.BrowserView;
expect(BrowserView).toHaveBeenCalledTimes(1);
expect(BrowserView).toHaveBeenCalledWith({
const WebContentsView = electron.WebContentsView;
expect(WebContentsView).toHaveBeenCalledTimes(1);
expect(WebContentsView).toHaveBeenCalledWith({
webPreferences: expect.objectContaining({sandbox: true, nodeIntegration: false})
});
});
test('has no node integration', () => {
// When
about.openAboutDialog({sender});
openAbout();
// Then
expect(electron.BrowserView).toHaveBeenCalledWith({
expect(electron.WebContentsView).toHaveBeenCalledWith({
webPreferences: expect.objectContaining({nodeIntegration: false})
});
});
test('has context isolation', () => {
// When
about.openAboutDialog({sender});
openAbout();
// Then
expect(electron.BrowserView).toHaveBeenCalledWith({
expect(electron.WebContentsView).toHaveBeenCalledWith({
webPreferences: expect.objectContaining({contextIsolation: true})
});
});
});
test('hasWindowOpenHandler', () => {
// Given
electron.browserViewInstance.webContents.getURL.mockReturnValue('file://about/index.html');
about.openAboutDialog({sender});
electron.webContentsViewInstance.webContents.getURL.mockReturnValue('file://about/index.html');
openAbout();
// When
electron.browserViewInstance.webContents.setWindowOpenHandler.mock.calls[0][0]({url: 'https://example.com'});
electron.webContentsViewInstance.webContents.setWindowOpenHandler.mock.calls[0][0]({url: 'https://example.com'});
// Then
expect(electron.shell.openExternal).toHaveBeenCalledWith('https://example.com');
});
test('should open dialog and add event listeners', () => {
// When
about.openAboutDialog({sender: electron.browserWindowInstance.webContents});
openAbout();
// Then
expect(electron.browserViewInstance.webContents.loadURL).toHaveBeenCalledTimes(1);
expect(electron.browserViewInstance.webContents.loadURL)
expect(electron.webContentsViewInstance.webContents.loadURL).toHaveBeenCalledTimes(1);
expect(electron.webContentsViewInstance.webContents.loadURL)
.toHaveBeenCalledWith(expect.stringMatching(/.+?\/index.html$/)); // NOSONAR
expect(electron.browserViewInstance.webContents.on).toHaveBeenCalledWith('will-navigate', expect.any(Function));
expect(electron.webContentsViewInstance.webContents.on).toHaveBeenCalledWith('will-navigate', expect.any(Function));
});
});
});
Expand Down
10 changes: 5 additions & 5 deletions src/about/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
See the License for the specific language governing permissions and
limitations under the License.
*/
const {BrowserView, BrowserWindow} = require('electron');
const {WebContentsView} = require('electron');
const path = require('path');
const {showDialog} = require('../browser-window');
const {showDialog} = require('../base-window');
const {handleRedirect, windowOpenHandler} = require('../tab-manager/redirect');

const webPreferences = {
Expand All @@ -25,12 +25,12 @@ const webPreferences = {
preload: path.resolve(__dirname, '..', '..', 'bundles', 'about.preload.js')
};

const openAboutDialog = event => {
const aboutView = new BrowserView({webPreferences});
const openAboutDialog = baseWindow => () => {
const aboutView = new WebContentsView({webPreferences});
aboutView.webContents.loadURL(`file://${__dirname}/index.html`);
aboutView.webContents.on('will-navigate', handleRedirect(aboutView));
aboutView.webContents.setWindowOpenHandler(windowOpenHandler(aboutView));
showDialog(BrowserWindow.fromWebContents(event.sender), aboutView);
showDialog(baseWindow, aboutView);
};

module.exports = {openAboutDialog};
2 changes: 1 addition & 1 deletion src/app-menu/__tests__/app-menu.browser.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ describe('App Menu in Browser test suite', () => {
};
await loadDOM({meta: import.meta, path: ['..', 'index.html']});
});
test('wrapper, click should close menu (BrowserView)', () => {
test('wrapper, click should close menu (WebContentsView)', () => {
// When
fireEvent.click(document.querySelector('.app-menu .wrapper'));
// Then
Expand Down
9 changes: 4 additions & 5 deletions src/app-menu/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
limitations under the License.
*/
const path = require('path');
const {BrowserView} = require('electron');
const {WebContentsView} = require('electron');

const webPreferences = {
transparent: true,
Expand All @@ -25,13 +25,12 @@ const webPreferences = {
};

/**
* Creates a new BrowserView instance with the App Menu
* @returns {Electron.CrossProcessExports.BrowserView}
* Creates a new WebContentsView instance with the App Menu
* @returns {Electron.CrossProcessExports.WebContentsView}
*/
const newAppMenu = () => {
const appMenu = new BrowserView({webPreferences});
const appMenu = new WebContentsView({webPreferences});
appMenu.isAppMenu = true;
appMenu.setAutoResize({width: false, horizontal: false, height: false, vertical: false});
appMenu.webContents.loadURL(`file://${__dirname}/index.html`);
return appMenu;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,23 @@
See the License for the specific language governing permissions and
limitations under the License.
*/
describe('browser-window util module test suite', () => {
let browserWindow;
describe('base-window util module test suite', () => {
let baseWindow;
beforeEach(() => {
browserWindow = require('../');
baseWindow = require('../');
});
test('showDialog, should fill provided window with provided BrowserView', () => {
// Given
const window = require('../../__tests__/electron').mockBrowserWindowInstance();
const window = require('../../__tests__/electron').mockBaseWindowInstance();
window.getContentBounds = jest.fn(() => ({width: 13, height: 37}));
const dialog = require('../../__tests__/electron').mockBrowserWindowInstance();
const dialog = require('../../__tests__/electron').mockWebContentsViewInstance();
// When
browserWindow.showDialog(window, dialog);
baseWindow.showDialog(window, dialog);
// Then
expect(window.setBrowserView).toHaveBeenCalledWith(dialog);
expect(window.setBrowserView).toHaveBeenCalledBefore(dialog.setBounds);
expect(window.contentView.addChildView).toHaveBeenCalledWith(dialog);
expect(window.contentView.addChildView).toHaveBeenCalledBefore(dialog.setBounds);
expect(dialog.setBounds).toHaveBeenCalledTimes(1);
expect(dialog.setBounds).toHaveBeenCalledWith({x: 0, y: 0, width: 13, height: 37});
expect(dialog.setAutoResize).toHaveBeenCalledTimes(1);
expect(dialog.setAutoResize)
.toHaveBeenCalledWith({width: false, horizontal: false, height: false, vertical: false});
expect(dialog.webContents.focus).toHaveBeenCalledTimes(1);
});
});
Loading

0 comments on commit 93b6d3e

Please sign in to comment.