Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

App starts, but GUI window does not show up #911

Closed
4 tasks done
mik-at opened this issue Oct 10, 2022 · 22 comments
Closed
4 tasks done

App starts, but GUI window does not show up #911

mik-at opened this issue Oct 10, 2022 · 22 comments

Comments

@mik-at
Copy link

mik-at commented Oct 10, 2022

Checklist

Streamlink Twitch GUI version

2.2.0

Streamlink version

5.0.1

Operating system, environment and configuration details

System Version: macOS 12.6 (21G115)
Model Name: MacBook Air
Model Identifier: Mac14,2
Chip: Apple M2

Description

In 2.2.0 Streamlink Twich GUI does launch, but no windows appear.
In 2.1.0 it works, so it seems to be something introduced in this release.

Hope I used the right commands for the debug log, if not, please tell me.

Debug log

MacOS % ./nwjs --enable-logging=stderr --log-level=1
[69439:259:1010/102708.682431:WARNING:account_consistency_mode_manager.cc(70)] Desktop Identity Consistency cannot be enabled as no OAuth client ID and client secret have been configured.
[69439:259:1010/102708.744858:WARNING:push_messaging_service_factory.cc(37)] PushMessagingService could not be built because InstanceID is unexpectedly disabled
objc[69449]: Class WebSwapCGLLayer is implemented in both /System/Library/Frameworks/WebKit.framework/Versions/A/Frameworks/WebCore.framework/Versions/A/Frameworks/libANGLE-shared.dylib (0x7ffb41694ec8) and /Users/<removed>/Downloads/Streamlink Twitch GUI.app/Contents/Frameworks/nwjs Framework.framework/Versions/105.0.5195.102/Libraries/libGLESv2.dylib (0x10df2a9e8). One of the two will be used. Which one is undefined.
@bastimeyer
Copy link
Member

Streamlink Twitch GUI is based on NW.js, and similar to Electron and other frameworks based on Chromium, there's almost nothing that can be done here on the application level if users are having issues with running NW.js itself. The only thing that can be done here is bumping the used NW.js release to the latest version or settings certain Chromium launch parameters.

Streamlink Twitch GUI v2.2.0 has bumped NW.js to 0.68.1, which is based on Chromium 105.0.5195.102 and is one Chromium release behind now:

The log output you've provided doesn't say anything useful. And since you're running macOS using an Apple M2 processor, there won't be any official support anyway, since it's ARMv8.X and not x86_64, and thus needs to be emulated. The application is running perfectly fine in my macOS Monterey x86_64 virtual machine.

Please try running NW.js on its own and check if that works:
https://nwjs.io/downloads/

Otherwise, try to disable GPU acceleration via Chromium's --disable-gpu launch parameter.

@mik-at
Copy link
Author

mik-at commented Oct 10, 2022

Thanks for your fast reply!

Is there anything else I can try to give you some more useful logs for debugging the issue?

I tried nwjs 0.68.1 and 0.69.1 and both opened a window.

nwjs-v0 68 1-osx-x64

nwjs-v0 69 1-osx-x64

I also tried to start it with "--disable-gpu" but the behaviour did not change and I got the same Error Message:

MacOS % ./nwjs --disable-gpu
objc[72200]: Class WebSwapCGLLayer is implemented in both /System/Library/Frameworks/WebKit.framework/Versions/A/Frameworks/WebCore.framework/Versions/A/Frameworks/libANGLE-shared.dylib (0x7ffb41694ec8) and /Users//Downloads/Streamlink Twitch GUI.app/Contents/Frameworks/nwjs Framework.framework/Versions/105.0.5195.102/Libraries/libGLESv2.dylib (0x11029c9e8). One of the two will be used. Which one is undefined.

@mik-at mik-at closed this as not planned Won't fix, can't repro, duplicate, stale Oct 10, 2022
@mik-at mik-at reopened this Oct 10, 2022
@bastimeyer
Copy link
Member

Is Streamlink Twitch GUI maybe already running on your system? Remember that this is a so called singleton application and can only be run once at the same time, so any additional launch attempts won't work. Check the running processes on your system and check for any left-over hanging/zombie processes in the background that may prevent you from starting it.

Also try deleting the application's user data dir or set a temporary custom one using the --user-data-dir=... launch parameter:
https://github.com/streamlink/streamlink-twitch-gui/wiki/Parameters#user-data-directory

As you can see in the changelog of v2.1.0...v2.2.0, nothing application-code-wise has changed in regards to the application setup or launch behavior:
v2.1.0...v2.2.0

As a last attempt, you could try building the application on your own with NW.js bumped to the latest version in src/config/main.json. Instructions can be found here:
https://github.com/streamlink/streamlink-twitch-gui/blob/master/CONTRIBUTING.md#developing-and-building

Other than that, I have no idea and can't further help. I don't use macOS and I don't own anything made by that company. Without any clear details, this is impossible for anyone else to debug. Since you've been the only one so far after 24+ days since the v2.2.0 release who's having issues launching the app, this sounds more like an issue on your system and its configuration.

@mik-at
Copy link
Author

mik-at commented Oct 11, 2022

Did a bisect today:

3d641ad is the first bad commit
commit 3d641ad
Author: bastimeyer mail@bastimeyer.de
Date: Thu Sep 15 23:06:34 2022 +0200

vendor: upgrade NW.js to 0.68.1

src/config/main.json | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

So yes, it really seems to be the nwjs update to 0.68.1.

Also tried 0.69.1, but did not run.
0.68.0 crashed with SIGSEGV
But 0.67.1 worked.
So it seems something between 0.67.1 and 0.68.1 in nwjs got bad.

Can you help me and tell me how to stop it from downloading nwjs and use a folder where i can checkout nwjs and do another bisect on that?

@bastimeyer
Copy link
Member

Did a bisect today

I've already told you that this was the only relevant change between the last two releases. Bisecting was not necessary.

So it seems something between 0.67.1 and 0.68.1 in nwjs got bad.

You'll have to find a reproduction on a bare NW.js project and report the issue on the NW.js issue tracker.
https://github.com/nwjs/nw.js/issues

Since you're able to run NW.js 0.69.1 without any application content, maybe check if these Chromium parameters are in any way related to the crash:
https://github.com/streamlink/streamlink-twitch-gui/blob/v2.2.0/src/app/package.json#L22

Checking which part of the application code is crashing NW.js on your system will be much, much more challenging. This could be either a bug in the NodeJS APIs or Chromium.

tell me how to stop it from downloading nwjs and use a folder where i can checkout nwjs and do another bisect on that?

The NW.js setup is handled by the nw-builder dependency. You'll have to place the NW.js binaries into the build/cache directory whose subdirectories depend on the version and build flavor set by the build config.

The easiest way will be replacing the NW.js binaries of the currently set version with ones from the available live builds here, so you don't have to fiddle with the build config:
https://dl.nwjs.io/live-build/

If you feel like digging through the NW.js code, go here:
https://github.com/nwjs

Good luck.

@mik-at
Copy link
Author

mik-at commented Oct 11, 2022

Since you're able to run NW.js 0.69.1 without any application content, maybe check if these Chromium parameters are in any way related to the crash: https://github.com/streamlink/streamlink-twitch-gui/blob/v2.2.0/src/app/package.json#L22

Changing the Chromium args did not help in any way, in some cases it made it even worse.
Anyway, you seem to have directed me at least in the right direction, I guess I found the problem.

If I change "show" to "true" it works and the window shows up:

I made a pull request for you to test it #912

@bastimeyer
Copy link
Member

From what it looks like, the dev tools aren't available anymore on http://localhost:8888 when running a dev build via yarn run grunt. Looks like this has been removed in a recent NW.js release, even though the webserver is alive on port 8888. The access of the remote dev tools is the reason why an automatically opened dev tools window hasn't been added to dev builds.

If you apply this patch and run a development build, it'll at least open the dev tools window, so maybe this will help. It may be required though to reload the dev tools once with ctrl+r (or cmd+r on macOS) in order to see any initialization errors.

diff --git a/src/app/main.js b/src/app/main.js
index 8628e125..9c633d99 100644
--- a/src/app/main.js
+++ b/src/app/main.js
@@ -29,6 +29,14 @@ global.process.on( "uncaughtException", function( err ) {
 });
 
 
+/* istanbul ignore next */
+if ( DEVELOPMENT ) {
+	try {
+		require( "nw.gui" ).Window.get().showDevTools();
+	} catch ( e ) {}
+}
+
+
 // "pre-load" certain native node modules
 // prevents a bug on Windows which causes all methods of stream.Writable.prototype to be missing
 // on stream.Duplex.prototype, more specifically stream.Duplex.prototype.cork. Also related to

@mik-at
Copy link
Author

mik-at commented Oct 12, 2022

Sadly, I can't do development builds (I guess because the arch is not supported, don't really want to debug that), so I have to make release builds.
So I tried it like this, but it crashes with SIGTRAP when I start it:

streamlink-twitch-gui % git diff
diff --git a/src/app/main.js b/src/app/main.js
index 8628e125..495878c8 100644
--- a/src/app/main.js
+++ b/src/app/main.js
@@ -29,6 +29,13 @@ global.process.on( "uncaughtException", function( err ) {
 });


+/* istanbul ignore next */
+if ( DEVELOPMENT ) {}
+try {
+       require( "nw.gui" ).Window.get().showDevTools();
+} catch ( e ) {}
+
+
 // "pre-load" certain native node modules
 // prevents a bug on Windows which causes all methods of stream.Writable.prototype to be missing
 // on stream.Duplex.prototype, more specifically stream.Duplex.prototype.cork. Also related to
diff --git a/src/app/package.json b/src/app/package.json
index 749f491b..80d3bfa3 100644
--- a/src/app/package.json
+++ b/src/app/package.json
@@ -19,5 +19,5 @@
                "show_in_taskbar": false
        },

-       "chromium-args": "--disable-devtools --enable-features=NativeNotifications --disable-smooth-scrolling --disable-features=nw2"
+       "chromium-args": "--enable-features=NativeNotifications --disable-smooth-scrolling --disable-features=nw2"
 }
diff --git a/src/config/main.json b/src/config/main.json
index 4da5acf7..2ca6d731 100644
--- a/src/config/main.json
+++ b/src/config/main.json
@@ -1,7 +1,7 @@
 {
        "display-name": "Streamlink Twitch GUI",
        "app-identifier": "streamlink-twitch-gui",
-       "nwjs-version": "0.68.1",
+       "nwjs-version": "0.69.1",
        "urls": {
                "homepage": "https://github.com/streamlink/streamlink-twitch-gui",
                "release": "https://github.com/streamlink/streamlink-twitch-gui/releases/tag/v{version}",

@bastimeyer
Copy link
Member

I have to make release builds

dev tools are not available on the "normal" NW.js flavor, only on the SDK flavor which is used by development and debug builds

@mik-at
Copy link
Author

mik-at commented Oct 12, 2022

dev tools are not available on the "normal" NW.js flavor, only on the SDK flavor

Thanks, that helped.

DevTools are now showing, but no error in the console, anything else I should try?

Screenshot 2022-10-12 at 14 15 59

@bastimeyer
Copy link
Member

but no error in the console

That's because it's not an application error. You'll have to figure out why the main window doesn't appear.

As said in your PR (which I'm going to close now), the application window starts hidden and only gets made visible once fully initialized if no launch arguments were passed that prevent it from being shown, like --tray for example.

So set a breakpoint here and reload the application via cmd+r:
https://github.com/streamlink/streamlink-twitch-gui/blob/v2.2.0/src/app/init/instance-initializers/nwjs/parameters.js#L44

Then see if the following call to nwWindow.show() works.
https://github.com/streamlink/streamlink-twitch-gui/blob/v2.2.0/src/app/nwjs/Window/index.js#L59

Another possibility is the window position, which could have an offset, so you can't see it on your screen. Streamlink Twitch GUI however does have an out-of-bounds detected implemented and should reset the window position. Either way, you can check the window coordinates as well now. Get the window object via require("nw.gui").Window.get() and check its properties.

@mik-at
Copy link
Author

mik-at commented Oct 12, 2022

So set a breakpoint here and reload the application via cmd+r: https://github.com/streamlink/streamlink-twitch-gui/blob/v2.2.0/src/app/init/instance-initializers/nwjs/parameters.js#L44

I can set as many breakpoints as I want in that function, it doesn't pause when refreshing.
Seems like that function does not get executed.

Another possibility is the window position, which could have an offset, so you can't see it on your screen. Streamlink Twitch GUI however does have an out-of-bounds detected implemented and should reset the window position. Either way, you can check the window coordinates as well now. Get the window object via require("nw.gui").Window.get() and check its properties.

If I do require("nw.gui").Window.get().show() the window appears on my screen, so it is in the right location.

@bastimeyer
Copy link
Member

Seems like that function does not get executed.

Then check here, which is one level up the call stack:
https://github.com/streamlink/streamlink-twitch-gui/blob/v2.2.0/src/app/init/instance-initializers/nwjs/instance-initializer.js#L75

Not reaching this code path is however a bit surprising and indicates that it's caused by a failure of the initialization (on your system). One of the init steps on macOS is the setup of the application menu bar, via the NW.js JS interfaces:

@mik-at
Copy link
Author

mik-at commented Oct 12, 2022

Then check here, which is one level up the call stack: https://github.com/streamlink/streamlink-twitch-gui/blob/v2.2.0/src/app/init/instance-initializers/nwjs/instance-initializer.js#L75

Last breakpoint that pauses is here:

await new Promise( resolve => requestAnimationFrame( resolve ) );

The breakpoint at requestAnimationFrame( resolve ) pauses, a breakpoint at i++ one line above does not pause.

@bastimeyer
Copy link
Member

So requestAnimationFrame(()=>console.log("done")) does not work (while the window is hidden)?

@bastimeyer
Copy link
Member

Looks like requestAnimationFrame behaves differently between the initial hidden window state and the window state after it has been set to hidden again.

I've uploaded a demo here:

As you can see, requesting an animation frame during the initial window state works fine, on both Linux and macOS, but when the window gets set to hidden again after making it visible, requesting an animation frame does not work. That doesn't explain though why Streamlink Twitch GUI's initialization isn't working on your system. Could you please clone the demo repo and pass the directory path as the first argument to the nwjs executable and post the resulting log output?

The whole requestAnimationFrame stuff could be unrelated though, because I don't know what exactly you did while debugging the app initialization. This could simply be due to reloading the application after it hasn't initialized during the first run, so the window state is different and causes the requestAnimationFrame calls to not execute the given callback.

And just for reference, requestAnimationFrame needs to be called here because this fixes a white screen from appearing for two frames when the application starts, which is annoying when using the dark theme.

If the source of this issue can't be found, then this can be worked around by creating a wrapping promise object that resolves automatically after a couple of milliseconds, as a fallback to the two requestAnimationFrame calls.

@mik-at
Copy link
Author

mik-at commented Oct 13, 2022

So requestAnimationFrame(()=>console.log("done")) does not work (while the window is hidden)?

Tried it with the fresh started application in console, not really sure what the output means.
Screenshot 2022-10-13 at 11 53 52

Could you please clone the demo repo and pass the directory path as the first argument to the nwjs executable and post the resulting log output?

nwjs-requestanimationframe % ./nwjs-v0.68.1-osx-x64/nwjs.app/Contents/MacOS/nwjs .
[1013/114848.417362:ERROR:zip.cc(179)] Cannot open '/Users/<removed>/nwjs-requestanimationframe/nwjs-v0.68.1-osx-x64/nwjs.app/Contents/Resources/app.nw': FILE_ERROR_NOT_FOUND: No such file or directory (2)
objc[6414]: Class WebSwapCGLLayer is implemented in both /System/Library/Frameworks/WebKit.framework/Versions/A/Frameworks/WebCore.framework/Versions/A/Frameworks/libANGLE-shared.dylib (0x7ffb41694ec8) and /Users/<removed>/nwjs-requestanimationframe/nwjs-v0.68.1-osx-x64/nwjs.app/Contents/Frameworks/nwjs Framework.framework/Versions/105.0.5195.102/Libraries/libGLESv2.dylib (0x110aa29e8). One of the two will be used. Which one is undefined.

initial window state (hidden)...
requesting animation frame with initially hidden window...
success
requesting animation frame with initially hidden window...
success
requesting animation frame with initially hidden window...
success

showing window...
requesting animation frame with shown window...
success
requesting animation frame with shown window...
success
requesting animation frame with shown window...
success

hiding window again...
requesting animation frame with hidden window...
success (expected failure)

exiting...

@mik-at
Copy link
Author

mik-at commented Oct 13, 2022

Also I just tried to comment out the for-loop and the window gets shown and no white window is shown beforehand like when I set show to true in package.json.

@bastimeyer
Copy link
Member

The log output doesn't say much. It's the same as the ones from the CI runners.

The requestAnimationFrame calls can be avoided though.

If we load the initial route first without awaiting its transition and then wait for the afterRender callback in EmberJS's run-loop, that should work because rendering will have started as soon as the route transition starts. The problem with this however is that part of the initial animation may be skipped on slow machines.

I also tried adding a Promise.race() with the two animation frames as the first promise and a strict timeout value as the second promise, but that resulted in the white screen being shown for some reason.

Please report back if the following diff fixes the issue:

diff --git a/src/app/init/instance-initializers/nwjs/instance-initializer.js b/src/app/init/instance-initializers/nwjs/instance-initializer.js
index 13288506..537f76f2 100644
--- a/src/app/init/instance-initializers/nwjs/instance-initializer.js
+++ b/src/app/init/instance-initializers/nwjs/instance-initializer.js
@@ -52,13 +52,6 @@ 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 the target route is loaded
 			const routeName = await routingPromise;
 			// then load the user's homepage, but don't await the completion of the transition
@@ -66,6 +59,9 @@ export default {
 				router.homepage( true );
 			}
 
+			// wait until Ember has rendered the app for the first time (window is still hidden)
+			await new Promise( resolve => scheduleOnce( "afterRender", resolve ) );
+
 			// add "initialized" class name to the document element just before showing the window
 			const document = application.lookup( "service:-document" );
 			document.documentElement.classList.add( "initialized" );

@mik-at
Copy link
Author

mik-at commented Oct 13, 2022

Please report back if the following diff fixes the issue

Did a fresh clone, applied the patch, built a release and yes, this fixes the issue.

Thank you! :)

@bastimeyer
Copy link
Member

I will push these changes once I've completed some further tests later today / tomorrow. Thanks for helping.

@bastimeyer
Copy link
Member

I found a better fix which doesn't involve starting the application routing before awaiting the first application rendering callback. This means that the initial animation when launching the app won't be cut off on slow(er) systems.

2d933e0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants