NWJS - capture close event (window [X] button) on new NWJS version

0 favourites
  • 2 posts
From the Asset Store
Create your game with this complete pack of images and animations!
  • This is in response to this post, which I cannot reply to as it is over 1 year old:

    https://www.construct.net/en/forum/new-post?topicID=157025

    in turn, that post was a response to this post:

    https://www.construct.net/en/forum/construct-2/how-do-i-18/window-close-113911

    The above mentioned Browser -> Execute Javascript solution works on NWJS v0.54.0, but I can't get this to work with NWJS v0.84.0 - now I recognize that version is not officially supported by Construct 2, but everything else NWJS-related works just fine, this is the only item that is not working. Any ideas?

    This is for the game Hypnospace Outlaw, and before you suggest it we cannot port to Construct 3 for a number of reasons. I'm trying to update the game to fix (1) Steam Cloud Saves, (2) mod.io integration, and (3) issues with newer graphics cards that new NWJS versions seem to resolve. While I was at it I figured I'd add some quality-of-life fixes and additions, like overriding clicking the [X] button so that players don't accidentally close the game when they're trying to click something at the top-right corner of the window.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • I got it working! First, whenever I call my function that captures the windows [X] close button, I first release control (to help prevent duplicate "listeners") by removing all listeners from the 'close' signal. You'll note the below code is very similar to previous solutions, but adds an extra line that I guess was a recent requirement to listen for 'close' signals: var gui = require("nw.gui")

    Browser -> Execute javascript:

    "var gui = require(""nw.gui""); var win_main=gui.Window.get(); win_main.removeAllListeners('close');"

    Then, I run a second command that listens for the 'close' signal.

    Browser -> Execute javascript

    "var gui = require(""nw.gui""); var win_main = gui.Window.get(); win.on('close', function() { c2_callFunction('nw.js close',[]); });"

    I have a Function titled "nw.js close" where I run the code I want to run when the player clicks the window [X] close button.

    And then when I want to release control I run just that code at the top of my post, removeAllListeners.

    This works in the latest NWJS 0.84.0 on Windows, and I'll be testing my update on Mac and Linux next week.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)