mirror of
https://github.com/scratchfoundation/scratch-desktop.git
synced 2024-12-23 06:02:30 -05:00
Merge pull request #98 from cwillisf/dark-dev-dont-hang
work around startup hang in dev on Win10 dark mode
This commit is contained in:
commit
85ce509434
1 changed files with 37 additions and 16 deletions
|
@ -1,6 +1,8 @@
|
||||||
import {BrowserWindow, Menu, app, dialog, ipcMain} from 'electron';
|
import {BrowserWindow, Menu, app, dialog, ipcMain} from 'electron';
|
||||||
import * as path from 'path';
|
import fs from 'fs';
|
||||||
|
import path from 'path';
|
||||||
import {format as formatUrl} from 'url';
|
import {format as formatUrl} from 'url';
|
||||||
|
|
||||||
import {getFilterForExtension} from './FileFilters';
|
import {getFilterForExtension} from './FileFilters';
|
||||||
import telemetry from './ScratchDesktopTelemetry';
|
import telemetry from './ScratchDesktopTelemetry';
|
||||||
import MacOSMenu from './MacOSMenu';
|
import MacOSMenu from './MacOSMenu';
|
||||||
|
@ -28,23 +30,9 @@ const createWindow = ({search = null, url = 'index.html', ...browserWindowOption
|
||||||
const webContents = window.webContents;
|
const webContents = window.webContents;
|
||||||
|
|
||||||
if (isDevelopment) {
|
if (isDevelopment) {
|
||||||
webContents.openDevTools();
|
webContents.openDevTools({mode: 'detach', activate: true});
|
||||||
import('electron-devtools-installer').then(importedModule => {
|
|
||||||
const {default: installExtension, REACT_DEVELOPER_TOOLS} = importedModule;
|
|
||||||
installExtension(REACT_DEVELOPER_TOOLS);
|
|
||||||
// TODO: add logging package and bring back the lines below
|
|
||||||
// .then(name => console.log(`Added browser extension: ${name}`))
|
|
||||||
// .catch(err => console.log('An error occurred: ', err));
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
webContents.on('devtools-opened', () => {
|
|
||||||
window.focus();
|
|
||||||
setImmediate(() => {
|
|
||||||
window.focus();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
const fullUrl = formatUrl(isDevelopment ?
|
const fullUrl = formatUrl(isDevelopment ?
|
||||||
{ // Webpack Dev Server
|
{ // Webpack Dev Server
|
||||||
hostname: 'localhost',
|
hostname: 'localhost',
|
||||||
|
@ -166,8 +154,41 @@ app.on('will-quit', () => {
|
||||||
telemetry.appWillClose();
|
telemetry.appWillClose();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// work around https://github.com/MarshallOfSound/electron-devtools-installer/issues/122
|
||||||
|
// which seems to be a result of https://github.com/electron/electron/issues/19468
|
||||||
|
if (process.platform === 'win32') {
|
||||||
|
const appUserDataPath = app.getPath('userData');
|
||||||
|
const devToolsExtensionsPath = path.join(appUserDataPath, 'DevTools Extensions');
|
||||||
|
try {
|
||||||
|
fs.unlinkSync(devToolsExtensionsPath);
|
||||||
|
} catch (_) {
|
||||||
|
// don't complain if the file doesn't exist
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// create main BrowserWindow when electron is ready
|
// create main BrowserWindow when electron is ready
|
||||||
app.on('ready', () => {
|
app.on('ready', () => {
|
||||||
|
if (isDevelopment) {
|
||||||
|
import('electron-devtools-installer').then(importedModule => {
|
||||||
|
const {default: installExtension, ...devToolsExtensions} = importedModule;
|
||||||
|
const extensionsToInstall = [
|
||||||
|
devToolsExtensions.REACT_DEVELOPER_TOOLS,
|
||||||
|
devToolsExtensions.REACT_PERF,
|
||||||
|
devToolsExtensions.REDUX_DEVTOOLS
|
||||||
|
];
|
||||||
|
for (const extension of extensionsToInstall) {
|
||||||
|
// WARNING: depending on a lot of things including the version of Electron `installExtension` might
|
||||||
|
// return a promise that never resolves, especially if the extension is already installed.
|
||||||
|
installExtension(extension).then(
|
||||||
|
// eslint-disable-next-line no-console
|
||||||
|
extensionName => console.log(`Installed dev extension: ${extensionName}`),
|
||||||
|
// eslint-disable-next-line no-console
|
||||||
|
errorMessage => console.error(`Error installing dev extension: ${errorMessage}`)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
_windows.main = createMainWindow();
|
_windows.main = createMainWindow();
|
||||||
_windows.main.on('closed', () => {
|
_windows.main.on('closed', () => {
|
||||||
delete _windows.main;
|
delete _windows.main;
|
||||||
|
|
Loading…
Reference in a new issue