From 5f527a00cf225d3e74b3f6577d6e2456e919de24 Mon Sep 17 00:00:00 2001 From: undergroundwires Date: Sun, 14 Mar 2021 14:56:30 +0100 Subject: [PATCH] fix fs module hanging not allowing code to run Run button on Windows stopped working as CodeRunner was hanging when executing fs.promises.mkdir as described in electron/electron#20951 It started happening after electron update to v12 in 1f515e7. This commit adds the workaround suggested in electron/electron#19554 that fixes the issue. --- src/presentation/background.ts | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/presentation/background.ts b/src/presentation/background.ts index 4e3b5b91..1acd81f7 100644 --- a/src/presentation/background.ts +++ b/src/presentation/background.ts @@ -115,14 +115,14 @@ if (isDevelopment) { function loadApplication(window: BrowserWindow) { if (process.env.WEBPACK_DEV_SERVER_URL) { // Load the url of the dev server if in development mode - win.loadURL(process.env.WEBPACK_DEV_SERVER_URL as string); + loadUrlWithNodeWorkaround(win, process.env.WEBPACK_DEV_SERVER_URL as string); if (!process.env.IS_TEST) { win.webContents.openDevTools(); } } else { createProtocol('app'); // Load the index.html when not in development - win.loadURL('app://./index.html'); + loadUrlWithNodeWorkaround(win, 'app://./index.html'); // tslint:disable-next-line:max-line-length autoUpdater.checkForUpdatesAndNotify(); // https://nklayman.github.io/vue-cli-plugin-electron-builder/guide/recipes.html#check-for-updates-in-background-js-ts } @@ -136,3 +136,10 @@ function configureExternalsUrlsOpenBrowser(window: BrowserWindow) { } }); } + +// Workaround for https://github.com/electron/electron/issues/19554 otherwise fs does not work +function loadUrlWithNodeWorkaround(window: BrowserWindow, url: string) { + setTimeout(() => { + window.loadURL(url); + }, 10); +}