From 2d933e0ba93cbc318b36d54fe5d5ab20767bc27e Mon Sep 17 00:00:00 2001 From: bastimeyer Date: Fri, 14 Oct 2022 01:57:05 +0200 Subject: [PATCH] init/instance: fix NW.js window initialization Resolves #911 Don't call `requestAnimationFrame` while the application window is still hidden during initialization. NW.js sometimes doesn't execute the animation frame callback during the initial window visibility state. This became clear after the NW.js 0.68.1 upgrade recently, which lead to the initialization never completing in certain cases on some systems. Remove the two `requestAnimationFrame` calls and schedule the `afterRender` Ember run-loop callback in the next run-loop, which ensures that the DOM is actually fully loaded and rendered by NW.js, so that no white screen appears for a few frames, which needs to be avoided when using the dark theme. --- .../nwjs/instance-initializer.js | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/app/init/instance-initializers/nwjs/instance-initializer.js b/src/app/init/instance-initializers/nwjs/instance-initializer.js index 132885065d..aeb9ad2a7e 100644 --- a/src/app/init/instance-initializers/nwjs/instance-initializer.js +++ b/src/app/init/instance-initializers/nwjs/instance-initializer.js @@ -1,6 +1,6 @@ import { get } from "@ember/object"; import { addObserver } from "@ember/object/observers"; -import { scheduleOnce } from "@ember/runloop"; +import { later, scheduleOnce } from "@ember/runloop"; import { default as nwApp, quit } from "nwjs/App"; import { default as nwWindow, setVisibility, setFocused } from "nwjs/Window"; import { argv, parseCommand } from "nwjs/argv"; @@ -52,12 +52,11 @@ export default { // restore window position first (while being hidden) await windowInitializer( application ); - // wait until Ember has rendered the app for the first time (window is still hidden) - await new Promise( resolve => scheduleOnce( "afterRender", resolve ) ); - // assume that NW.js doesn't render a white page anymore after the next two frames - for ( let i = 0; i < 2; i++ ) { - await new Promise( resolve => requestAnimationFrame( resolve ) ); - } + // Wait until Ember has rendered the app for the first time (window is still hidden). + // Wrap scheduled "afterRender" run-loop queue callback in a new run-loop to ensure + // that the DOM is fully rendered and no white screen will appear for a few frames. + // We can't use requestAnimationFrame here due to issue #911. + await new Promise( resolve => later( () => scheduleOnce( "afterRender", resolve ) ) ); // wait until the target route is loaded const routeName = await routingPromise;