|
1 | 1 | import {BrowserWindow, Menu, app, dialog, ipcMain} from 'electron';
|
2 |
| -import * as path from 'path'; |
| 2 | +import fs from 'fs'; |
| 3 | +import path from 'path'; |
3 | 4 | import {format as formatUrl} from 'url';
|
| 5 | + |
4 | 6 | import {getFilterForExtension} from './FileFilters';
|
5 | 7 | import telemetry from './ScratchDesktopTelemetry';
|
6 | 8 | import MacOSMenu from './MacOSMenu';
|
@@ -28,23 +30,9 @@ const createWindow = ({search = null, url = 'index.html', ...browserWindowOption
|
28 | 30 | const webContents = window.webContents;
|
29 | 31 |
|
30 | 32 | if (isDevelopment) {
|
31 |
| - webContents.openDevTools(); |
32 |
| - import('electron-devtools-installer').then(importedModule => { |
33 |
| - const {default: installExtension, REACT_DEVELOPER_TOOLS} = importedModule; |
34 |
| - installExtension(REACT_DEVELOPER_TOOLS); |
35 |
| - // TODO: add logging package and bring back the lines below |
36 |
| - // .then(name => console.log(`Added browser extension: ${name}`)) |
37 |
| - // .catch(err => console.log('An error occurred: ', err)); |
38 |
| - }); |
| 33 | + webContents.openDevTools({mode: 'detach', activate: true}); |
39 | 34 | }
|
40 | 35 |
|
41 |
| - webContents.on('devtools-opened', () => { |
42 |
| - window.focus(); |
43 |
| - setImmediate(() => { |
44 |
| - window.focus(); |
45 |
| - }); |
46 |
| - }); |
47 |
| - |
48 | 36 | const fullUrl = formatUrl(isDevelopment ?
|
49 | 37 | { // Webpack Dev Server
|
50 | 38 | hostname: 'localhost',
|
@@ -166,8 +154,41 @@ app.on('will-quit', () => {
|
166 | 154 | telemetry.appWillClose();
|
167 | 155 | });
|
168 | 156 |
|
| 157 | +// work around https://github.com/MarshallOfSound/electron-devtools-installer/issues/122 |
| 158 | +// which seems to be a result of https://github.com/electron/electron/issues/19468 |
| 159 | +if (process.platform === 'win32') { |
| 160 | + const appUserDataPath = app.getPath('userData'); |
| 161 | + const devToolsExtensionsPath = path.join(appUserDataPath, 'DevTools Extensions'); |
| 162 | + try { |
| 163 | + fs.unlinkSync(devToolsExtensionsPath); |
| 164 | + } catch (_) { |
| 165 | + // don't complain if the file doesn't exist |
| 166 | + } |
| 167 | +} |
| 168 | + |
169 | 169 | // create main BrowserWindow when electron is ready
|
170 | 170 | app.on('ready', () => {
|
| 171 | + if (isDevelopment) { |
| 172 | + import('electron-devtools-installer').then(importedModule => { |
| 173 | + const {default: installExtension, ...devToolsExtensions} = importedModule; |
| 174 | + const extensionsToInstall = [ |
| 175 | + devToolsExtensions.REACT_DEVELOPER_TOOLS, |
| 176 | + devToolsExtensions.REACT_PERF, |
| 177 | + devToolsExtensions.REDUX_DEVTOOLS |
| 178 | + ]; |
| 179 | + for (const extension of extensionsToInstall) { |
| 180 | + // WARNING: depending on a lot of things including the version of Electron `installExtension` might |
| 181 | + // return a promise that never resolves, especially if the extension is already installed. |
| 182 | + installExtension(extension).then( |
| 183 | + // eslint-disable-next-line no-console |
| 184 | + extensionName => console.log(`Installed dev extension: ${extensionName}`), |
| 185 | + // eslint-disable-next-line no-console |
| 186 | + errorMessage => console.error(`Error installing dev extension: ${errorMessage}`) |
| 187 | + ); |
| 188 | + } |
| 189 | + }); |
| 190 | + } |
| 191 | + |
171 | 192 | _windows.main = createMainWindow();
|
172 | 193 | _windows.main.on('closed', () => {
|
173 | 194 | delete _windows.main;
|
|
0 commit comments