Skip to content

Commit

Permalink
init/instance: fix NW.js window initialization
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
bastimeyer committed Oct 13, 2022
1 parent a285b9d commit 2d933e0
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions src/app/init/instance-initializers/nwjs/instance-initializer.js
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 2d933e0

Please sign in to comment.