From f60d6e0748a4c31817f85f361332c8142d796f4b Mon Sep 17 00:00:00 2001 From: Laurent Cozic Date: Tue, 17 Dec 2019 12:09:57 +0000 Subject: [PATCH] Desktop: Make it easier to view early errors when the app starts --- ElectronClient/app/ElectronAppWrapper.js | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/ElectronClient/app/ElectronAppWrapper.js b/ElectronClient/app/ElectronAppWrapper.js index 4ebb6d0f5..6b242f847 100644 --- a/ElectronClient/app/ElectronAppWrapper.js +++ b/ElectronClient/app/ElectronAppWrapper.js @@ -34,6 +34,9 @@ class ElectronAppWrapper { } createWindow() { + // Set to true to view errors if the application does not start + const debugEarlyBugs = this.env_ === 'dev' && false; + const windowStateKeeper = require('electron-window-state'); const stateOptions = { @@ -56,9 +59,10 @@ class ElectronAppWrapper { webPreferences: { nodeIntegration: true, }, + webviewTag: true, // We start with a hidden window, which is then made visible depending on the showTrayIcon setting // https://github.com/laurent22/joplin/issues/2031 - show: false, + show: debugEarlyBugs, }; // Linux icon workaround for bug https://github.com/electron-userland/electron-builder/issues/2098 @@ -81,8 +85,11 @@ class ElectronAppWrapper { slashes: true, })); - // Uncomment this to view errors if the application does not start - // if (this.env_ === 'dev') this.win_.webContents.openDevTools(); + // Note that on Windows, calling openDevTools() too early results in a white window with no error message. + // Waiting for one of the ready events might work but they might not be triggered if there's an error, so + // the easiest is to use a timeout. Keep in mind that if you get a white window on Windows it might be due + // to this line though. + if (debugEarlyBugs) setTimeout(() => this.win_.webContents.openDevTools(), 3000); this.win_.on('close', (event) => { // If it's on macOS, the app is completely closed only if the user chooses to close the app (willQuitApp_ will be true)