Skip to content

Commit 8bc0095

Browse files
authored
refactor(app-shell, app-shell-odd): update electron-devtools-installer (#20176)
* refactor(app-shell, app-shell-odd): update electron-devtools-installer
1 parent b5233bc commit 8bc0095

File tree

5 files changed

+70
-48
lines changed

5 files changed

+70
-48
lines changed

app-shell-odd/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
"@types/uuid": "^3.4.7",
4343
"ajv": "6.12.3",
4444
"dateformat": "3.0.3",
45-
"electron-devtools-installer": "3.2.0",
45+
"electron-devtools-installer": "4.0.0",
4646
"electron-store": "5.1.1",
4747
"electron-updater": "6.3.9",
4848
"execa": "4.0.0",

app-shell-odd/src/main.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ function installDevtools(): void {
193193
// eslint-disable-next-line @typescript-eslint/no-var-requires
194194
const devtools = require('electron-devtools-installer')
195195
const extensions = [devtools.REACT_DEVELOPER_TOOLS, devtools.REDUX_DEVTOOLS]
196-
const install = devtools.default
196+
const install = devtools.installExtensions
197197
const forceReinstall = config.reinstallDevtools
198198

199199
log.debug('Installing devtools')

app-shell/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
"electron-debug": "3.2.0",
5252
"electron-is-dev": "1.2.0",
5353
"electron-localshortcut": "3.2.1",
54-
"electron-devtools-installer": "3.2.0",
54+
"electron-devtools-installer": "4.0.0",
5555
"electron-store": "5.1.1",
5656
"electron-updater": "6.3.9",
5757
"execa": "4.0.0",

app-shell/src/main.ts

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@ import dns from 'dns'
33
import { app, BrowserWindow, ipcMain } from 'electron'
44
import contextMenu from 'electron-context-menu'
55
import electronDebug from 'electron-debug'
6-
import * as electronDevtoolsInstaller from 'electron-devtools-installer'
6+
import {
7+
installExtension,
8+
REACT_DEVELOPER_TOOLS,
9+
REDUX_DEVTOOLS,
10+
} from 'electron-devtools-installer'
711

812
import { getConfig, getOverrides, getStore, registerConfig } from './config'
913
import {
@@ -63,11 +67,20 @@ interface HandlerSet {
6367
// Handler caching using window ID as key
6468
const handlerSets = new Map<string, HandlerSet>()
6569

66-
// prepended listener is important here to work around Electron issue
67-
// https://github.com/electron/electron/issues/19468#issuecomment-623529556
68-
app.prependOnceListener('ready', startUp)
69-
// eslint-disable-next-line @typescript-eslint/no-misused-promises
70-
if (config.devtools) app.once('ready', installDevtools)
70+
app
71+
.whenReady()
72+
.then(async () => {
73+
startUp()
74+
75+
if (config.devtools) {
76+
await installDevtools()
77+
78+
if (mainWindow && !mainWindow.isDestroyed()) {
79+
mainWindow.webContents.openDevTools({ mode: 'detach' })
80+
}
81+
}
82+
})
83+
.catch(err => log.error('Startup failed', { err }))
7184

7285
app.once('window-all-closed', () => {
7386
log.debug('all windows closed, quitting the app')
@@ -203,36 +216,23 @@ function createRendererLogger(): Logger {
203216
return logger
204217
}
205218

206-
function installDevtools(): Promise<Logger> {
207-
const extensions = [
208-
electronDevtoolsInstaller.REACT_DEVELOPER_TOOLS,
209-
electronDevtoolsInstaller.REDUX_DEVTOOLS,
210-
]
211-
// @ts-expect-error the types for electron-devtools-installer are not correct
212-
// when importing the default export via commmon JS. the installer is actually nested in
213-
// another default object
214-
const install = electronDevtoolsInstaller.default?.default
215-
const forceReinstall = config.reinstallDevtools
216-
217-
log.debug('Installing devtools')
218-
219-
if (typeof install === 'function') {
220-
return install(extensions, {
219+
async function installDevtools(): Promise<void> {
220+
const extensions = [REACT_DEVELOPER_TOOLS, REDUX_DEVTOOLS]
221+
222+
log.debug('Installing devtools with v4 API')
223+
224+
try {
225+
await installExtension(extensions, {
221226
loadExtensionOptions: { allowFileAccess: true },
222-
forceDownload: forceReinstall,
227+
forceDownload: config.reinstallDevtools,
228+
})
229+
230+
log.debug('Devtools extensions installed')
231+
} catch (error) {
232+
log.warn('Failed to install devtools extensions', {
233+
forceReinstall: config.reinstallDevtools,
234+
error,
223235
})
224-
.then(() => log.debug('Devtools extensions installed'))
225-
.catch((error: unknown) => {
226-
log.warn('Failed to install devtools extensions', {
227-
forceReinstall,
228-
error,
229-
})
230-
})
231-
} else {
232-
log.warn('could not resolve electron dev tools installer')
233-
return Promise.reject(
234-
new Error('could not resolve electron dev tools installer')
235-
)
236236
}
237237
}
238238

yarn.lock

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10813,14 +10813,11 @@ [email protected]:
1081310813
electron-is-dev "^1.1.0"
1081410814
electron-localshortcut "^3.1.0"
1081510815

10816-
electron-devtools-installer@3.2.0:
10817-
version "3.2.0"
10818-
resolved "https://registry.yarnpkg.com/electron-devtools-installer/-/electron-devtools-installer-3.2.0.tgz#acc48d24eb7033fe5af284a19667e73b78d406d0"
10819-
integrity sha512-t3UczsYugm4OAbqvdImMCImIMVdFzJAHgbwHpkl5jmfu1izVgUcP/mnrPqJIpEeCK1uZGpt+yHgWEN+9EwoYhQ==
10816+
electron-devtools-installer@4.0.0:
10817+
version "4.0.0"
10818+
resolved "https://registry.yarnpkg.com/electron-devtools-installer/-/electron-devtools-installer-4.0.0.tgz#6556a6a326cddea18194cb6d97d85c8ae329dedf"
10819+
integrity sha512-9Tntu/jtfSn0n6N/ZI6IdvRqXpDyLQiDuuIbsBI+dL+1Ef7C8J2JwByw58P3TJiNeuqyV3ZkphpNWuZK5iSY2w==
1082010820
dependencies:
10821-
rimraf "^3.0.2"
10822-
semver "^7.2.1"
10823-
tslib "^2.1.0"
1082410821
unzip-crx-3 "^0.2.0"
1082510822

1082610823
electron-dl@^3.2.1:
@@ -20480,7 +20477,7 @@ semver@^6.0.0, semver@^6.2.0, semver@^6.3.0, semver@^6.3.1:
2048020477
resolved "https://registry.yarnpkg.com/semver/-/semver-6.3.1.tgz#556d2ef8689146e46dcea4bfdd095f3434dffcb4"
2048120478
integrity sha512-BR7VvDCVHO+q2xBEWskxS6DJE1qRnb7DxzUrogb71CWoSficBxYsiAGd+Kl0mmq/MprG9yArRkyrQxTO6XjMzA==
2048220479

20483-
semver@^7.0.0, semver@^7.2.1, semver@^7.3.2, semver@^7.3.4, semver@^7.3.5, semver@^7.3.7, semver@^7.3.8, semver@^7.5.3, semver@^7.5.4:
20480+
semver@^7.0.0, semver@^7.3.2, semver@^7.3.4, semver@^7.3.5, semver@^7.3.7, semver@^7.3.8, semver@^7.5.3, semver@^7.5.4:
2048420481
version "7.6.0"
2048520482
resolved "https://registry.yarnpkg.com/semver/-/semver-7.6.0.tgz#1a46a4db4bffcccd97b743b5005c8325f23d4e2d"
2048620483
integrity sha512-EnwXhrlwXMk9gKu5/flx5sv/an57AkRplG3hTK68W7FRDN+k+OWBj65M7719OkA82XLBxrcX0KSHj+X5COhOVg==
@@ -21209,7 +21206,7 @@ string-ts@^2.2.1:
2120921206
resolved "https://registry.yarnpkg.com/string-ts/-/string-ts-2.2.1.tgz#9cf9a93d210f778080a9db86ca37cba37f55e44c"
2121021207
integrity sha512-Q2u0gko67PLLhbte5HmPfdOjNvUKbKQM+mCNQae6jE91DmoFHY6HH9GcdqCeNx87DZ2KKjiFxmA0R/42OneGWw==
2121121208

21212-
"string-width-cjs@npm:string-width@^4.2.0", string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.3:
21209+
"string-width-cjs@npm:string-width@^4.2.0":
2121321210
version "4.2.3"
2121421211
resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010"
2121521212
integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==
@@ -21227,6 +21224,15 @@ string-width@^3.0.0, string-width@^3.1.0:
2122721224
is-fullwidth-code-point "^2.0.0"
2122821225
strip-ansi "^5.1.0"
2122921226

21227+
string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.3:
21228+
version "4.2.3"
21229+
resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010"
21230+
integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==
21231+
dependencies:
21232+
emoji-regex "^8.0.0"
21233+
is-fullwidth-code-point "^3.0.0"
21234+
strip-ansi "^6.0.1"
21235+
2123021236
string-width@^5.0.1, string-width@^5.1.2:
2123121237
version "5.1.2"
2123221238
resolved "https://registry.yarnpkg.com/string-width/-/string-width-5.1.2.tgz#14f8daec6d81e7221d2a357e668cab73bdbca794"
@@ -21339,7 +21345,7 @@ stringify-object@^3.2.1:
2133921345
is-obj "^1.0.1"
2134021346
is-regexp "^1.0.0"
2134121347

21342-
"strip-ansi-cjs@npm:strip-ansi@^6.0.1", strip-ansi@^6.0.0, strip-ansi@^6.0.1:
21348+
"strip-ansi-cjs@npm:strip-ansi@^6.0.1":
2134321349
version "6.0.1"
2134421350
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9"
2134521351
integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==
@@ -21360,6 +21366,13 @@ strip-ansi@^5.0.0, strip-ansi@^5.1.0, strip-ansi@^5.2.0:
2136021366
dependencies:
2136121367
ansi-regex "^4.1.0"
2136221368

21369+
strip-ansi@^6.0.0, strip-ansi@^6.0.1:
21370+
version "6.0.1"
21371+
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9"
21372+
integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==
21373+
dependencies:
21374+
ansi-regex "^5.0.1"
21375+
2136321376
strip-ansi@^7.0.1:
2136421377
version "7.1.0"
2136521378
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-7.1.0.tgz#d5b6568ca689d8561370b0707685d22434faff45"
@@ -23656,7 +23669,7 @@ worker-plugin@^5.0.0:
2365623669
dependencies:
2365723670
loader-utils "^1.1.0"
2365823671

23659-
"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0", wrap-ansi@^7.0.0:
23672+
"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0":
2366023673
version "7.0.0"
2366123674
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43"
2366223675
integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==
@@ -23683,6 +23696,15 @@ wrap-ansi@^6.2.0:
2368323696
string-width "^4.1.0"
2368423697
strip-ansi "^6.0.0"
2368523698

23699+
wrap-ansi@^7.0.0:
23700+
version "7.0.0"
23701+
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43"
23702+
integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==
23703+
dependencies:
23704+
ansi-styles "^4.0.0"
23705+
string-width "^4.1.0"
23706+
strip-ansi "^6.0.0"
23707+
2368623708
wrap-ansi@^8.1.0:
2368723709
version "8.1.0"
2368823710
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-8.1.0.tgz#56dc22368ee570face1b49819975d9b9a5ead214"

0 commit comments

Comments
 (0)