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

Upgrade to Electron 21 #1463

Closed
wants to merge 32 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
6033dbd
[WIP] Electron 21
gre Oct 4, 2022
d22caef
pnpm lock
gre Oct 14, 2022
fc8f70f
update electron-builder
gre Oct 14, 2022
971769c
update screenshots (macos-latest)
ledgerlive Oct 14, 2022
7b6f5d5
update screenshots (ubuntu-latest)
ledgerlive Oct 14, 2022
779a819
ci
gre Oct 14, 2022
fd5f6cf
playwright update
gre Oct 14, 2022
3673c6b
update sentry
gre Oct 17, 2022
cb7d657
update deps
gre Oct 17, 2022
78ad13b
Merge branch 'develop' into feat/electron-21
gre Oct 18, 2022
05b1a51
Merge branch 'develop' into feat/electron-21
gre Oct 18, 2022
260aa5a
Merge branch 'develop' into feat/electron-21
gre Oct 18, 2022
b1d6636
add debug to test-desktop
valpinkman Oct 26, 2022
fbf5139
test without nyc
valpinkman Oct 26, 2022
42d1f57
Revert "add debug to test-desktop"
valpinkman Oct 26, 2022
346be1f
Merge branch 'develop' into feat/electron-21
gre Nov 3, 2022
c6b0df9
update screenshots (ubuntu-latest)
ledgerlive Nov 3, 2022
bc7f314
update screenshots (macos-latest)
ledgerlive Nov 3, 2022
6d144ff
Merge branch 'develop' into feat/electron-21
gre Nov 3, 2022
bec020a
Merge branch 'develop' into feat/electron-21
gre Nov 3, 2022
81060ec
Merge branch 'develop' into feat/electron-21
gre Nov 4, 2022
ff2d747
update node-hid
gre Nov 4, 2022
926f5b8
Merge branch 'develop' into feat/electron-21
gre Nov 7, 2022
273d01c
Fix webview usage with electron 21 (#1777)
chabroA Nov 14, 2022
ced8aad
Merge branch 'develop' into feat/electron-21
gre Nov 14, 2022
97c4787
Merge branch 'develop' into feat/electron-21
gre Nov 14, 2022
c649ada
Merge branch 'develop' into feat/electron-21
gre Nov 14, 2022
caff4f1
Merge branch 'develop' into feat/electron-21
gre Nov 29, 2022
fc00e89
Merge branch 'develop' into feat/electron-21
gre Nov 29, 2022
a79639a
update screenshots (macos-latest)
ledgerlive Nov 29, 2022
a540680
add changeset for LLD update
chabroA Dec 1, 2022
2677226
Merge branch 'develop' into feat/electron-21
gre Dec 1, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 21 additions & 0 deletions .changeset/famous-yaks-deliver.md
@@ -0,0 +1,21 @@
---
"ledger-live-desktop": major
---

Electron was upgraded from 15 to 21 as well as "electron-builder"

- that means we have a new bump of the nodejs version for native module too. So all native library impacted (coins, usb,..)
- that means we have a new Chromium version. So the UI is impacted. Screenshots have changed due to this.

In a breaking change in Electron 18 the nativeWindowOpen web preference (used [here](https://github.com/LedgerHQ/ledger-live/blob/ff2d747c1a3aa6bc779d1987c0f2a5e0369c2d72/apps/ledger-live-desktop/src/renderer/components/WebPlatformPlayer/index.tsx#L416)) have [been removed](https://www.electronjs.org/blog/electron-18-0#removed-nativewindowopen) (cf. [this PR](https://github.com/electron/electron/pull/29405))

Now, Ledger live does not seem to receive (and handle) new-window events when a live-apps wants to open a new window (regularly used throughout Live Apps to open external contextual info like redirect to Twitter account, open ToS page, etc…)

`webview` are deprecated and not formerly integrated / maintained in electron.
updating electron broke previous handleding of new window opened from a `webview`

use `setWindowOpenHandler` on the `webview` webContents to handle opening new window.
cf. https://github.com/electron/electron/issues/31117#issuecomment-958733861

also, there seem to be issues between `webview` and React
cf. https://github.com/electron/electron/issues/6046
16 changes: 8 additions & 8 deletions apps/ledger-live-desktop/package.json
Expand Up @@ -41,7 +41,7 @@
"test": "pnpm test:jest && pnpm test:playwright",
"test:codecheck": "node ./tools/ci.js",
"test:jest": "jest src --silent --ci --coverage --json --testLocationInResults --outputFile=report.json",
"test:playwright": "nyc playwright test --config=tests/playwright.config.ts",
"test:playwright": "playwright test --config=tests/playwright.config.ts",
"test:playwright:update-snapshots": "pnpm test:playwright --update-snapshots",
"test:playwright:recorder": "playwright test tests/specs/recorder.spec.ts",
"test:playwright:clean": "git clean -fdX tests/artifacts",
Expand All @@ -62,9 +62,9 @@
"@ledgerhq/types-devices": "workspace:^",
"@ledgerhq/types-live": "workspace:^",
"@polkadot/react-identicon": "2.9.13",
"@sentry/electron": "^4.0.0",
"@sentry/node": "7.8.1",
"@sentry/tracing": "7.8.1",
"@sentry/electron": "^4.1.2",
"@sentry/node": "7.16.0",
"@sentry/tracing": "7.16.0",
"@tippyjs/react": "^4.2.6",
"@trust/keyto": "^1.0.1",
"@types/semver": "^7.3.9",
Expand All @@ -79,7 +79,7 @@
"color": "^3.1.3",
"debug": "^4.3.3",
"dotenv": "^8.2.0",
"electron-context-menu": "^2.5.2",
"electron-context-menu": "^3.6.0",
"ethereumjs-tx": "^2.1.2",
"firebase": "^9.6.6",
"focus-trap": "^6.6.1",
Expand Down Expand Up @@ -166,7 +166,7 @@
"@mapbox/node-pre-gyp": "^1.0.8",
"@octokit/rest": "^18.12.0",
"@playwright/test": "1.27.1",
"@sentry/cli": "^2.5.2",
"@sentry/cli": "^2.9.0",
"@storybook/addon-actions": "^6.3.12",
"@storybook/addon-essentials": "^6.3.12",
"@storybook/addon-links": "^6.3.12",
Expand All @@ -192,10 +192,10 @@
"codecov": "^3.8.3",
"cross-env": "^7.0.3",
"css-loader": "^3.5.3",
"electron": "^15",
"electron": "^21.3.1",
"electron-builder": "^23.6.0",
"electron-devtools-installer": "^3.2.0",
"electron-notarize": "^1.1.0",
"electron-notarize": "^1.2.2",
"esbuild-loader": "^2.19.0",
"esbuild-utils": "workspace:*",
"eslint": "^7.32.0",
Expand Down
15 changes: 14 additions & 1 deletion apps/ledger-live-desktop/src/main/index.js
Expand Up @@ -4,7 +4,7 @@ require("@electron/remote/main").initialize();

/* eslint-disable import/first */
import "./setup";
import { app, Menu, ipcMain, session } from "electron";
import { app, Menu, ipcMain, session, webContents, shell } from "electron";
import menu from "./menu";
import {
createMainWindow,
Expand Down Expand Up @@ -158,6 +158,19 @@ app.on("ready", async () => {

ipcMain.on("log", (event, { log }) => logger.log(log));

// To handle openning new windows from webview
// cf. https://gist.github.com/codebytere/409738fcb7b774387b5287db2ead2ccb
ipcMain.on("webview-dom-ready", (_, id) => {
const wc = webContents.fromId(id);
wc.setWindowOpenHandler(({ url }) => {
const protocol = new URL(url).protocol;
if (["https:", "http:"].includes(protocol)) {
shell.openExternal(url);
}
return { action: "deny" };
});
});

Menu.setApplicationMenu(menu);

const windowParams = await db.getKey("windowParams", "MainWindow", {});
Expand Down
4 changes: 4 additions & 0 deletions apps/ledger-live-desktop/src/preloader/index.js
Expand Up @@ -32,9 +32,13 @@ const appLoaded = () => {

const reloadRenderer = () => ipcRenderer.invoke("reloadRenderer");

// cf. https://gist.github.com/codebytere/409738fcb7b774387b5287db2ead2ccb
const openWindow = id => ipcRenderer.send("webview-dom-ready", id);

window.api = {
appLoaded,
reloadRenderer,
openWindow,
};

/**
Expand Down
@@ -1,4 +1,4 @@
import { shell, WebviewTag } from "electron";
import { WebviewTag } from "electron";
import * as remote from "@electron/remote";
import { JSONRPCRequest } from "json-rpc-2.0";
import React, { useCallback, useEffect, useMemo, useRef, useState } from "react";
Expand Down Expand Up @@ -400,31 +400,35 @@ export default function WebPlatformPlayer({ manifest, onClose, inputs = {}, conf
}
}, [manifest]);

const handleNewWindow = useCallback(async e => {
const protocol = new URL(e.url).protocol;
if (protocol === "http:" || protocol === "https:") {
await shell.openExternal(e.url);
const handleDomReady = useCallback(() => {
const webview = targetRef.current;
if (!webview) {
return;
}

const id = webview.getWebContentsId();

// cf. https://gist.github.com/codebytere/409738fcb7b774387b5287db2ead2ccb
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
window.api.openWindow(id);
}, []);

useEffect(() => {
const webview = targetRef.current;

if (webview) {
// For mysterious reasons, the webpreferences attribute does not
// pass through the styled component when added in the JSX.
webview.webpreferences = "nativeWindowOpen=no";
webview.addEventListener("new-window", handleNewWindow);
webview.addEventListener("did-finish-load", handleLoad);
webview.addEventListener("dom-ready", handleDomReady);
}

return () => {
if (webview) {
webview.removeEventListener("new-window", handleNewWindow);
webview.removeEventListener("did-finish-load", handleLoad);
webview.removeEventListener("dom-ready", handleDomReady);
}
};
}, [handleLoad, handleNewWindow]);
}, [handleLoad, handleDomReady]);

return (
<Container>
Expand All @@ -438,11 +442,32 @@ export default function WebPlatformPlayer({ manifest, onClose, inputs = {}, conf
/>

<Wrapper>
<CustomWebview
<webview
src={url.toString()}
ref={targetRef}
style={{ opacity: widgetLoaded ? 1 : 0 }}
/**
* There seem to be an issue between Electron webview and styled-components
* (and React more broadly, cf. comment bellow).
* When using a styled webview componennt, the `allowpopups` prop does not
* seem to be set
*/
style={{
opacity: widgetLoaded ? 1 : 0,
border: "none",
width: "100%",
flex: 1,
transition: "opacity 200ms ease-out",
}}
preload={`file://${remote.app.dirname}/webviewPreloader.bundle.js`}
/**
* There seems to be an issue between Electron webview and react
* Hense, the normal `allowpopups` prop does not work and we need to
* explicitly set it's value to "true" as a string
* cf. https://github.com/electron/electron/issues/6046
*/
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
allowpopups="true"
/>
{!widgetLoaded ? (
<Loader>
Expand Down
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Expand Up @@ -31,7 +31,7 @@
"@ledgerhq/errors": "workspace:^",
"@ledgerhq/hw-transport": "workspace:^",
"@ledgerhq/logs": "workspace:^",
"node-hid": "2.1.1"
"node-hid": "^2.1.2"
},
"devDependencies": {
"@types/node-hid": "^1.3.1"
Expand Down
Expand Up @@ -33,7 +33,7 @@
"@ledgerhq/hw-transport-node-hid-noevents": "workspace:^",
"@ledgerhq/logs": "workspace:^",
"lodash": "^4.17.21",
"node-hid": "2.1.1",
"node-hid": "^2.1.2",
"usb": "2.5.1"
},
"scripts": {
Expand Down