Skip to content

Commit

Permalink
⬆ Bump electron to 25.0.1
Browse files Browse the repository at this point in the history
Signed-off-by: Marc Nuri <[email protected]>
  • Loading branch information
manusa committed Jun 3, 2023
1 parent e8ad237 commit faa7c3f
Show file tree
Hide file tree
Showing 13 changed files with 53 additions and 50 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 112
- 🌍 Based on Chromium 114
- 🔔 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 112
- 🌍 Based on Chromium 114
- 🔔 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": "24.4.1",
"electron": "25.0.1",
"htm": "3.1.1",
"markdown-it": "13.0.1",
"nodehun": "3.0.2",
Expand Down
6 changes: 3 additions & 3 deletions src/browser-window/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
*/
const {registerAppShortcuts} = require('./keyboard-shortcuts');

const showDialog = (window, browserView) => {
window.setBrowserView(browserView);
const {width, height} = window.getContentBounds();
const showDialog = (browserWindow, browserView) => {
browserWindow.setBrowserView(browserView);
const {width, height} = browserWindow.getContentBounds();
browserView.setBounds({x: 0, y: 0, width, height});
browserView.setAutoResize({width: false, horizontal: false, height: false, vertical: false});
browserView.webContents.focus();
Expand Down
7 changes: 3 additions & 4 deletions src/chrome-tabs/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ const checkForUpdates = webContents => {
.catch(e => console.debug('Error checking for updates', e));
};

const handleContextMenu = (event, params) => {
const webContents = event.sender;
const handleContextMenu = viewOrWindow => (event, params) => {
const menu = new Menu();
menu.append(new MenuItem({
label: 'Settings',
Expand All @@ -50,7 +49,7 @@ const handleContextMenu = (event, params) => {
}));
menu.append(new MenuItem({
label: 'DevTools',
click: () => webContents.openDevTools({mode: 'detach', activate: true})
click: () => viewOrWindow.webContents.openDevTools({mode: 'detach', activate: true})
}));
const {x, y} = params;
menu.popup({x, y});
Expand All @@ -66,7 +65,7 @@ const newTabContainer = () => {
tabContainer.setAutoResize({width: false, horizontal: false, height: false, vertical: false});
tabContainer.webContents.loadURL(`file://${__dirname}/index.html`,
{extraHeaders: 'pragma: no-cache\nCache-control: no-cache'});
tabContainer.webContents.on('context-menu', handleContextMenu);
tabContainer.webContents.on('context-menu', handleContextMenu(tabContainer));
eventBus.once(APP_EVENTS.tabsReady, () => checkForUpdates(tabContainer.webContents));
setInterval(() => checkForUpdates(tabContainer.webContents), 1000 * 60 * 30).unref();
return tabContainer;
Expand Down
16 changes: 9 additions & 7 deletions src/help/__tests__/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,22 @@
*/
describe('Help module test suite', () => {
let electron;
let sender;
let help;
beforeEach(() => {
jest.resetModules();
jest.mock('electron', () => require('../../__tests__').mockElectronInstance());
electron = require('electron');
sender = electron.browserWindowInstance.webContents;
help = require('../');
});
describe('openHelpDialog', () => {
let openHelp;
beforeEach(() => {
openHelp = help.openHelpDialog(electron.browserWindowInstance);
});
describe('webPreferences', () => {
test('is sandboxed', () => {
// When
help.openHelpDialog({sender});
openHelp();
// Then
const BrowserView = electron.BrowserView;
expect(BrowserView).toHaveBeenCalledTimes(1);
Expand All @@ -38,15 +40,15 @@ describe('Help module test suite', () => {
});
test('has no node integration', () => {
// When
help.openHelpDialog({sender});
openHelp();
// Then
expect(electron.BrowserView).toHaveBeenCalledWith({
webPreferences: expect.objectContaining({nodeIntegration: false})
});
});
test('has context isolation', () => {
// When
help.openHelpDialog({sender});
openHelp();
// Then
expect(electron.BrowserView).toHaveBeenCalledWith({
webPreferences: expect.objectContaining({contextIsolation: true})
Expand All @@ -56,15 +58,15 @@ describe('Help module test suite', () => {
test('hasWindowOpenHandler', () => {
// Given
electron.browserViewInstance.webContents.getURL.mockReturnValue('file://help/index.html');
help.openHelpDialog({sender});
openHelp();
// When
electron.browserViewInstance.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
help.openHelpDialog({sender: electron.browserWindowInstance.webContents});
openHelp();
// Then
expect(electron.browserViewInstance.webContents.loadURL).toHaveBeenCalledTimes(1);
expect(electron.browserViewInstance.webContents.loadURL)
Expand Down
6 changes: 3 additions & 3 deletions src/help/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
See the License for the specific language governing permissions and
limitations under the License.
*/
const {BrowserView, BrowserWindow} = require('electron');
const {BrowserView} = require('electron');
const path = require('path');
const {showDialog} = require('../browser-window');
const {handleRedirect, windowOpenHandler} = require('../tab-manager/redirect');
Expand All @@ -25,12 +25,12 @@ const webPreferences = {
preload: path.resolve(__dirname, '..', '..', 'bundles', 'help.preload.js')
};

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

module.exports = {openHelpDialog};
11 changes: 5 additions & 6 deletions src/main/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,19 +68,18 @@ const activateTab = tabId => {
}
};

const handleMainWindowResize = event => {
const window = event.sender;
const [windowWidth, windowHeight] = window.getSize();
const handleMainWindowResize = () => {
const [windowWidth, windowHeight] = mainWindow.getSize();
updateSettings({width: windowWidth, height: windowHeight});

setTimeout(() => {
const {width: contentWidth, height: contentHeight} = window.getContentBounds();
const {width: contentWidth, height: contentHeight} = mainWindow.getContentBounds();
if (appMenu && appMenu.setBounds) {
appMenu.setBounds({x: 0, y: 0, width: contentWidth, height: contentHeight});
}
let totalHeight = 0;
const isLast = (idx, array) => idx === array.length - 1;
window.getBrowserViews().filter(isNotAppMenu).forEach((bv, idx, array) => {
mainWindow.getBrowserViews().filter(isNotAppMenu).forEach((bv, idx, array) => {
const {x: currentX, y: currentY, height: currentHeight} = bv.getBounds();
let newHeight = currentHeight;
if (isLast(idx, array)) {
Expand Down Expand Up @@ -228,7 +227,7 @@ const initGlobalListeners = () => {
eventBus.handle(APP_EVENTS.dictionaryGetAvailableNative, getAvailableNativeDictionaries);
eventBus.handle(APP_EVENTS.dictionaryGetEnabled, getEnabledDictionaries);
eventBus.on(APP_EVENTS.fullscreenToggle, fullscreenToggle);
eventBus.on(APP_EVENTS.helpOpenDialog, openHelpDialog);
eventBus.on(APP_EVENTS.helpOpenDialog, openHelpDialog(mainWindow));
eventBus.on(APP_EVENTS.quit, app.exit);
eventBus.on(APP_EVENTS.restore, () => {
mainWindow.restore();
Expand Down
8 changes: 4 additions & 4 deletions src/spell-check/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,21 +117,21 @@ const menuItem = ({webContents, suggestion}) => new MenuItem({
}
});

const contextMenuHandler = async (event, {misspelledWord}) => {
const contextMenuHandler = async (webContents, {misspelledWord}) => {
const ret = [];
if (misspelledWord && misspelledWord.length > 0) {
const suggestions = await fakeRendererWorker.webContents.executeJavaScript(`getSuggestions('${misspelledWord}')`);
suggestions.forEach(suggestion =>
ret.push(menuItem({webContents: event.sender, suggestion})));
ret.push(menuItem({webContents, suggestion})));
}
return ret;
};

const contextMenuNativeHandler = (event, {misspelledWord, dictionarySuggestions = []}) => {
const contextMenuNativeHandler = (webContents, {misspelledWord, dictionarySuggestions = []}) => {
const ret = [];
if (misspelledWord && misspelledWord.length > 0) {
dictionarySuggestions.forEach(suggestion =>
ret.push(menuItem({webContents: event.sender, suggestion})));
ret.push(menuItem({webContents, suggestion})));
}
return ret;
};
Expand Down
1 change: 0 additions & 1 deletion src/tab-manager/__tests__/context-menu.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ describe('Tab Manager context-menu test suite', () => {
electron.browserViewInstance.webContents.canGoBack = jest.fn(() => false);
listeners = electron.browserViewInstance.listeners;
event = new Event('');
event.sender = electron.browserViewInstance.webContents;
params = {x: 13, y: 37};
tabManager = require('../');
tabManager.addTabs({send: jest.fn()})([{id: '1337', url: 'https://localhost'}]);
Expand Down
26 changes: 15 additions & 11 deletions src/tab-manager/context-menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
const {Menu, MenuItem} = require('electron');
const {contextMenuHandler, contextMenuNativeHandler} = require('../spell-check');

const entries = (event, params) => {
const webContents = event.sender;
const entries = ({webContents, params}) => {
return [
[{
label: 'Back',
Expand Down Expand Up @@ -49,24 +48,24 @@ const entries = (event, params) => {
];
};

const spellCheckContextMenu = async (event, params) => {
const spellCheckContextMenu = async ({webContents, params}) => {
const menu = new Menu();
let spellingSuggestions;
if (event.sender.session.spellcheck) {
spellingSuggestions = contextMenuNativeHandler(event, params);
if (webContents.session.spellcheck) {
spellingSuggestions = contextMenuNativeHandler(webContents, params);
} else {
spellingSuggestions = await contextMenuHandler(event, params);
spellingSuggestions = await contextMenuHandler(webContents, params);
}
if (spellingSuggestions && spellingSuggestions.length > 0) {
spellingSuggestions.forEach(mi => menu.append(mi));
}
return menu;
};

const regularContextMenu = (event, params) => {
const regularContextMenu = ({webContents, params}) => {
const menu = new Menu();
const isVisible = me => !Object.keys(me).includes('visible') || me.visible === true;
entries(event, params).forEach((group, idx, arr) => {
entries({webContents, params}).forEach((group, idx, arr) => {
for (const entry of group) {
menu.append(new MenuItem({...entry}));
}
Expand All @@ -77,12 +76,17 @@ const regularContextMenu = (event, params) => {
return menu;
};

const handleContextMenu = async (event, params) => {
/**
* @param {BrowserView|BrowserWindow} viewOrWindow
* @returns {(function(*, *): Promise<void>)|*}
*/
const handleContextMenu = viewOrWindow => async (_event, params) => {
const {webContents} = viewOrWindow;
let menu;
if (params.misspelledWord) {
menu = await spellCheckContextMenu(event, params);
menu = await spellCheckContextMenu({webContents, params});
} else {
menu = regularContextMenu(event, params);
menu = regularContextMenu({webContents, params});
}
const {x, y} = params;
menu.popup({x, y});
Expand Down
2 changes: 1 addition & 1 deletion src/tab-manager/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ const addTabs = ipcSender => tabsMetadata => {
const handlePageFaviconUpdatedForCurrentTab = handlePageFaviconUpdated(tab, ipcSender, id);
tab.webContents.on('page-favicon-updated', handlePageFaviconUpdatedForCurrentTab);

tab.webContents.on('context-menu', handleContextMenu);
tab.webContents.on('context-menu', handleContextMenu(tab));

const registerIdInTab = () => tab.webContents.executeJavaScript(`window.tabId = '${id}';`);
tab.webContents.on('dom-ready', registerIdInTab);
Expand Down

0 comments on commit faa7c3f

Please sign in to comment.