diff options
author | Kristóf Marussy <kristof@marussy.com> | 2022-01-02 11:32:59 +0100 |
---|---|---|
committer | Kristóf Marussy <kristof@marussy.com> | 2022-01-02 11:46:08 +0100 |
commit | 3127fc53390bce67f816e4cc9112135785b067d5 (patch) | |
tree | cc9508224119a4c231acede12c72a502e1082537 /packages/main/src/index.ts | |
parent | fix: Ensure dev user directory exists (diff) | |
download | sophie-3127fc53390bce67f816e4cc9112135785b067d5.tar.gz sophie-3127fc53390bce67f816e4cc9112135785b067d5.tar.zst sophie-3127fc53390bce67f816e4cc9112135785b067d5.zip |
fix: Allow devtools extensions to be installed
On the first startup in dev mode, Electron must be able to download the
devtools extensions and wait for them to be installed.
Loosens the UI process request filter a bit, but the behavior should
match production mode in all cases except chrome webstore URLs.
Nevertheless, only production mode should be considered secure.
Fixes #6
Signed-off-by: Kristóf Marussy <kristof@marussy.com>
Diffstat (limited to 'packages/main/src/index.ts')
-rw-r--r-- | packages/main/src/index.ts | 23 |
1 files changed, 13 insertions, 10 deletions
diff --git a/packages/main/src/index.ts b/packages/main/src/index.ts index ff14332..7c6bfd5 100644 --- a/packages/main/src/index.ts +++ b/packages/main/src/index.ts | |||
@@ -42,6 +42,7 @@ import { URL } from 'url'; | |||
42 | 42 | ||
43 | import { init } from './compositionRoot.js'; | 43 | import { init } from './compositionRoot.js'; |
44 | import { | 44 | import { |
45 | DEVMODE_ALLOWED_URL_PREFIXES, | ||
45 | installDevToolsExtensions, | 46 | installDevToolsExtensions, |
46 | openDevToolsWhenReady, | 47 | openDevToolsWhenReady, |
47 | } from './devTools.js'; | 48 | } from './devTools.js'; |
@@ -73,14 +74,6 @@ app.commandLine.appendSwitch( | |||
73 | 'HardwareMediaKeyHandling,MediaSessionService', | 74 | 'HardwareMediaKeyHandling,MediaSessionService', |
74 | ); | 75 | ); |
75 | 76 | ||
76 | // It doesn't seem to cause a race condition to start installing the extensions this early. | ||
77 | if (isDevelopment) { | ||
78 | app.whenReady().then(installDevToolsExtensions).catch((err) => { | ||
79 | console.error('Failed to install devtools extensions', err); | ||
80 | process.exit(1); | ||
81 | }); | ||
82 | } | ||
83 | |||
84 | // Remove sophie and electron from the user-agent string to avoid detection. | 77 | // Remove sophie and electron from the user-agent string to avoid detection. |
85 | const originalUserAgent = app.userAgentFallback; | 78 | const originalUserAgent = app.userAgentFallback; |
86 | const userAgent = originalUserAgent.replaceAll(/\s(sophie|Electron)\/\S+/g, ''); | 79 | const userAgent = originalUserAgent.replaceAll(/\s(sophie|Electron)\/\S+/g, ''); |
@@ -127,7 +120,7 @@ function shouldCancelMainWindowRequest(url: string, method: string): boolean { | |||
127 | return true; | 120 | return true; |
128 | } | 121 | } |
129 | if (isDevelopment) { | 122 | if (isDevelopment) { |
130 | if (normalizedUrl.startsWith('devtools:') || normalizedUrl.startsWith('chrome-extension:')) { | 123 | if (DEVMODE_ALLOWED_URL_PREFIXES.some((prefix) => normalizedUrl.startsWith(prefix))) { |
131 | return false; | 124 | return false; |
132 | } | 125 | } |
133 | if (import.meta.env.VITE_DEV_SERVER_URL !== undefined) { | 126 | if (import.meta.env.VITE_DEV_SERVER_URL !== undefined) { |
@@ -315,7 +308,17 @@ app.on('window-all-closed', () => { | |||
315 | } | 308 | } |
316 | }); | 309 | }); |
317 | 310 | ||
318 | app.whenReady().then(createWindow).catch((err) => { | 311 | app.whenReady().then(async () => { |
312 | if (isDevelopment) { | ||
313 | try { | ||
314 | await installDevToolsExtensions(); | ||
315 | } catch (err) { | ||
316 | console.error('Failed to install devtools extensions', err); | ||
317 | } | ||
318 | } | ||
319 | |||
320 | return createWindow(); | ||
321 | }).catch((err) => { | ||
319 | console.error('Failed to create window', err); | 322 | console.error('Failed to create window', err); |
320 | process.exit(1); | 323 | process.exit(1); |
321 | }); | 324 | }); |