diff options
author | Kristóf Marussy <kristof@marussy.com> | 2022-04-14 15:49:52 +0200 |
---|---|---|
committer | Kristóf Marussy <kristof@marussy.com> | 2022-05-16 00:55:00 +0200 |
commit | 7e34607793a044bcf5ca3ce471f99859bc6cf636 (patch) | |
tree | 777147cb562b15ceac4e15a5182110a4df6f27e5 /packages | |
parent | chore(deps): Bump dependencies (diff) | |
download | sophie-7e34607793a044bcf5ca3ce471f99859bc6cf636.tar.gz sophie-7e34607793a044bcf5ca3ce471f99859bc6cf636.tar.zst sophie-7e34607793a044bcf5ca3ce471f99859bc6cf636.zip |
chore(deps): Bump electron to 19 for setBackgroundColor fix
Since https://github.com/electron/electron/pull/33435 has landed in
electron 19 alpha, but not in 18, moving to 19 lets us remove the
workarounds for setBackgroundColor.
Signed-off-by: Kristóf Marussy <kristof@marussy.com>
Diffstat (limited to 'packages')
-rw-r--r-- | packages/main/package.json | 2 | ||||
-rw-r--r-- | packages/main/src/infrastructure/electron/impl/ElectronMainWindow.ts | 1 | ||||
-rw-r--r-- | packages/main/src/infrastructure/electron/impl/ElectronServiceView.ts | 2 | ||||
-rw-r--r-- | packages/preload/package.json | 2 | ||||
-rw-r--r-- | packages/service-preload/package.json | 3 | ||||
-rw-r--r-- | packages/service-preload/src/index.ts | 57 |
6 files changed, 5 insertions, 62 deletions
diff --git a/packages/main/package.json b/packages/main/package.json index 4ebc994..b8e00c8 100644 --- a/packages/main/package.json +++ b/packages/main/package.json | |||
@@ -12,7 +12,7 @@ | |||
12 | "@sophie/shared": "workspace:*", | 12 | "@sophie/shared": "workspace:*", |
13 | "chalk": "^5.0.1", | 13 | "chalk": "^5.0.1", |
14 | "deep-equal": "^2.0.5", | 14 | "deep-equal": "^2.0.5", |
15 | "electron": "18.0.3", | 15 | "electron": "^19.0.0-alpha.1", |
16 | "fs-extra": "^10.0.1", | 16 | "fs-extra": "^10.0.1", |
17 | "i18next": "^21.6.16", | 17 | "i18next": "^21.6.16", |
18 | "json5": "^2.2.1", | 18 | "json5": "^2.2.1", |
diff --git a/packages/main/src/infrastructure/electron/impl/ElectronMainWindow.ts b/packages/main/src/infrastructure/electron/impl/ElectronMainWindow.ts index 6144d89..edc6592 100644 --- a/packages/main/src/infrastructure/electron/impl/ElectronMainWindow.ts +++ b/packages/main/src/infrastructure/electron/impl/ElectronMainWindow.ts | |||
@@ -153,7 +153,6 @@ export default class ElectronMainWindow implements MainWindow { | |||
153 | } | 153 | } |
154 | if (serviceView instanceof ElectronServiceView) { | 154 | if (serviceView instanceof ElectronServiceView) { |
155 | this.browserWindow.setBrowserView(serviceView.browserView); | 155 | this.browserWindow.setBrowserView(serviceView.browserView); |
156 | serviceView.browserView.setBackgroundColor('#fff'); | ||
157 | return; | 156 | return; |
158 | } | 157 | } |
159 | throw new TypeError( | 158 | throw new TypeError( |
diff --git a/packages/main/src/infrastructure/electron/impl/ElectronServiceView.ts b/packages/main/src/infrastructure/electron/impl/ElectronServiceView.ts index 340c523..2e64269 100644 --- a/packages/main/src/infrastructure/electron/impl/ElectronServiceView.ts +++ b/packages/main/src/infrastructure/electron/impl/ElectronServiceView.ts | |||
@@ -55,6 +55,8 @@ export default class ElectronServiceView implements ServiceView { | |||
55 | }, | 55 | }, |
56 | }); | 56 | }); |
57 | 57 | ||
58 | this.browserView.setBackgroundColor('#fff'); | ||
59 | |||
58 | const { webContents } = this.browserView; | 60 | const { webContents } = this.browserView; |
59 | 61 | ||
60 | function setLocation(url: string) { | 62 | function setLocation(url: string) { |
diff --git a/packages/preload/package.json b/packages/preload/package.json index ce6d433..5e5f0bf 100644 --- a/packages/preload/package.json +++ b/packages/preload/package.json | |||
@@ -10,7 +10,7 @@ | |||
10 | }, | 10 | }, |
11 | "dependencies": { | 11 | "dependencies": { |
12 | "@sophie/shared": "workspace:*", | 12 | "@sophie/shared": "workspace:*", |
13 | "electron": "18.0.3", | 13 | "electron": "^19.0.0-alpha.1", |
14 | "i18next": "^21.6.16", | 14 | "i18next": "^21.6.16", |
15 | "loglevel": "^1.8.0", | 15 | "loglevel": "^1.8.0", |
16 | "mobx": "^6.5.0", | 16 | "mobx": "^6.5.0", |
diff --git a/packages/service-preload/package.json b/packages/service-preload/package.json index 4650f10..28d1129 100644 --- a/packages/service-preload/package.json +++ b/packages/service-preload/package.json | |||
@@ -10,8 +10,7 @@ | |||
10 | "dependencies": { | 10 | "dependencies": { |
11 | "@sophie/service-inject": "workspace:*", | 11 | "@sophie/service-inject": "workspace:*", |
12 | "@sophie/service-shared": "workspace:*", | 12 | "@sophie/service-shared": "workspace:*", |
13 | "color-string": "^1.9.0", | 13 | "electron": "^19.0.0-alpha.1" |
14 | "electron": "18.0.3" | ||
15 | }, | 14 | }, |
16 | "devDependencies": { | 15 | "devDependencies": { |
17 | "@types/color-string": "^1.5.2" | 16 | "@types/color-string": "^1.5.2" |
diff --git a/packages/service-preload/src/index.ts b/packages/service-preload/src/index.ts index 99d02ec..eee8551 100644 --- a/packages/service-preload/src/index.ts +++ b/packages/service-preload/src/index.ts | |||
@@ -18,67 +18,10 @@ | |||
18 | * SPDX-License-Identifier: AGPL-3.0-only | 18 | * SPDX-License-Identifier: AGPL-3.0-only |
19 | */ | 19 | */ |
20 | 20 | ||
21 | import colorString from 'color-string'; | ||
22 | import { webFrame } from 'electron'; | 21 | import { webFrame } from 'electron'; |
23 | // eslint-disable-next-line import/no-unresolved -- Synthetic import provided by an eslint plugin. | 22 | // eslint-disable-next-line import/no-unresolved -- Synthetic import provided by an eslint plugin. |
24 | import injectSource from 'sophie-src:@sophie/service-inject'; | 23 | import injectSource from 'sophie-src:@sophie/service-inject'; |
25 | 24 | ||
26 | const DEFAULT_BG_COLOR = '#fff'; | ||
27 | |||
28 | /** | ||
29 | * Styles a HTML element such that its background is opaque. | ||
30 | * | ||
31 | * If there is an existing background color, it will be made maximally opaque. | ||
32 | * | ||
33 | * If there is a background image, transparent areas will be colored `DEFAULT_BG_COLOR`. | ||
34 | * | ||
35 | * If the element was completely transparent, the function returns `false` instead. | ||
36 | * This allows leaving a `html` element transparent to let the background of the `body` | ||
37 | * element render in its palce. | ||
38 | * | ||
39 | * @param element The HTML element to style. | ||
40 | * @returns `true` if the background was made opaque. | ||
41 | * @see https://www.w3.org/TR/css-backgrounds-3/#body-background | ||
42 | */ | ||
43 | function tryMakeOpaque(element: HTMLElement): boolean { | ||
44 | const style = getComputedStyle(element); | ||
45 | const bgColor = colorString.get.rgb(style.backgroundColor); | ||
46 | if (bgColor[3] > 0) { | ||
47 | if (bgColor[3] < 1) { | ||
48 | bgColor[3] = 1; | ||
49 | // eslint-disable-next-line no-param-reassign -- Deliberately add element style. | ||
50 | element.style.backgroundColor = colorString.to.rgb(bgColor); | ||
51 | } | ||
52 | return true; | ||
53 | } | ||
54 | if (style.backgroundImage !== 'none') { | ||
55 | // eslint-disable-next-line no-param-reassign -- Deliberately add element style. | ||
56 | element.style.backgroundColor = DEFAULT_BG_COLOR; | ||
57 | return true; | ||
58 | } | ||
59 | return false; | ||
60 | } | ||
61 | |||
62 | if (webFrame.parent === null) { | ||
63 | // Inject CSS to simulate `browserView.setBackgroundColor`. | ||
64 | // This is injected before the page loads, so the styles from the website will overwrite it. | ||
65 | document.addEventListener('DOMContentLoaded', () => { | ||
66 | if ( | ||
67 | document.documentElement.style.contain === '' && | ||
68 | document.body.style.contain === '' | ||
69 | ) { | ||
70 | if ( | ||
71 | !tryMakeOpaque(document.documentElement) && | ||
72 | !tryMakeOpaque(document.body) | ||
73 | ) { | ||
74 | document.body.style.backgroundColor = DEFAULT_BG_COLOR; | ||
75 | } | ||
76 | } else if (!tryMakeOpaque(document.documentElement)) { | ||
77 | document.documentElement.style.backgroundColor = DEFAULT_BG_COLOR; | ||
78 | } | ||
79 | }); | ||
80 | } | ||
81 | |||
82 | /** | 25 | /** |
83 | * Executes the service inject script in the isolated world. | 26 | * Executes the service inject script in the isolated world. |
84 | * | 27 | * |