Problems with NW not fully closing? Try this!

Discussion and feedback on Construct 2

Post » Wed Mar 09, 2016 7:21 pm

So in the bugs forum many people have been reporting a problem where NW.JS games don't fully close when exiting- they seem to close but processes are left behind, taking up resources. That thread is here: nwjs-not-completely-closing-when-exiting-app_t166669

So I've been working on a crudely-implemented but seemingly effective solution to this problem. If it works for other people then hopefully someone who actually knows what they're doing can redo my work in a better way. So this isn't really a full fix, but I think its a good start.

(EDIT- see the next post for an updated solution)
Last edited by Quicksand on Wed Mar 09, 2016 11:21 pm, edited 1 time in total.
FREEDOM: Diegesis - Out Now for Windows! http://freedom.quicksandgames.com
B
22
S
5
G
1
Posts: 83
Reputation: 1,818

Post » Wed Mar 09, 2016 11:20 pm

Ok I worked on it a little more with the help of a programmer friend and we figured out a better way. Ignore the solution in the first post.

1. Find your exported project's package.nw file and open it (it can be opened as a zip archive, you can even rename it to a .zip file if you remember to change it back after).

2. Open up the index.html file inside that archive.

3. Paste this code right before the last closing </script> tag:

var win = window['nwgui'].Window.get();

win.on('close', function () {
window['nwgui'].App.quit();
});

4. Save the new index.html file and the changed package.nw.

5. Test out your game to see if all processes close fully upon exit.
FREEDOM: Diegesis - Out Now for Windows! http://freedom.quicksandgames.com
B
22
S
5
G
1
Posts: 83
Reputation: 1,818

Post » Wed Mar 09, 2016 11:57 pm

you can test with this plugin nodewebkit extended
Image Image
B
26
S
15
G
143
Posts: 882
Reputation: 74,562

Post » Thu Mar 10, 2016 12:07 am

Pretty sure it's a file name issue. Renaming the project and deleting, and redoing the sounds fixes mine.
With that info, perhaps someone could figure out a fix for capx's.
Something like renaming the folder or something we don't have access to in the editor.
Image ImageImage
B
172
S
50
G
183
Posts: 8,443
Reputation: 115,605

Post » Thu Mar 10, 2016 12:33 am

MadSpy wrote:you can test with this plugin nodewebkit extended


I saw that in the other thread, but I'd prefer to have a solution where the user can close the window with the X like normal.

newt wrote:Pretty sure it's a file name issue. Renaming the project and deleting, and redoing the sounds fixes mine.
With that info, perhaps someone could figure out a fix for capx's.
Something like renaming the folder or something we don't have access to in the editor.


Does pasting my code into the index.html work for you? If that does work there's probably a way to insert it into the template index.html so it shows up in all exports automatically.
FREEDOM: Diegesis - Out Now for Windows! http://freedom.quicksandgames.com
B
22
S
5
G
1
Posts: 83
Reputation: 1,818

Post » Thu Mar 10, 2016 12:43 am

I add an event emitter, the user could close with window 'X'
Image Image
B
26
S
15
G
143
Posts: 882
Reputation: 74,562

Post » Thu Mar 10, 2016 12:47 am

MadSpy wrote:I add an event emitter, the user could close with window 'X'


Oh yeah? Can you explain further?
FREEDOM: Diegesis - Out Now for Windows! http://freedom.quicksandgames.com
B
22
S
5
G
1
Posts: 83
Reputation: 1,818

Post » Thu Mar 10, 2016 12:52 am

when the user click on window X, windows.close is send so I add an event when .close is send, I launch App.quit
Image Image
B
26
S
15
G
143
Posts: 882
Reputation: 74,562

Post » Thu Mar 10, 2016 12:56 am

Quicksand wrote:
newt wrote:Pretty sure it's a file name issue. Renaming the project and deleting, and redoing the sounds fixes mine.
With that info, perhaps someone could figure out a fix for capx's.
Something like renaming the folder or something we don't have access to in the editor.


Does pasting my code into the index.html work for you? If that does work there's probably a way to insert it into the template index.html so it shows up in all exports automatically.


I'm not talking about a hack. Changing the xml in a capx can offer a fix.
Nwjs changed its file structure, and thats the reason for the ghost processes.
I lack the knowledge to figure out where the issue is.
Image ImageImage
B
172
S
50
G
183
Posts: 8,443
Reputation: 115,605

Post » Thu Mar 10, 2016 10:58 am

Thanks! Your solution worked for me!
B
64
S
14
G
5
Posts: 265
Reputation: 6,103


Return to Construct 2 General

Who is online

Users browsing this forum: No registered users and 6 guests