2
votes

I'm making a game with Dart and I'm packaging it with node-webkit and node-webkit.dart (a Dart wrapper for node-webkit modules).

My goal is to have the node-webkit app game appear as a standalone native app. To achieve this I've stripped the navigation bar and some other things. All my assets are local, the game never has to connect to the internet.

I have a few anchor links within my HTML (leading to my site for example). When I click them currently my node-webkit window opens the link within itself. Besides this never being my plan, there's no way to return to the game since I took the navigation bar away.

So my question: Is it possible to make a handler that opens anchor links externally (in the user's browser of choice)? Bearing in mind that anchor links may be added dynamically.

I know about Shell.openExternal(url) but I can't think of a way to make every anchor link call it.

Thanks!

1
I think you can use the onclick event of your link or button to call the Shell.openExternal() function. - luizmineo
@luizmineo indeed, but the problem I'm facing is setting the onClick for newly added anchor elements (during runtime). I actually found a solution using a new node-webkit feature (which doesn't appear to be supported by node-webkit.dart), I will be posting it as an answer to my question in a little bit. Thanks for the reply! - moomoohk
Are you using angular, polymer or other lib/framework? If you share more details on how you are building your UI, I can provide an example. - luizmineo
I'm not using any frameworks. - moomoohk

1 Answers

2
votes

As it turns out, there's a node-webkit event to handle links but node-webkit.dart doesn't appear to support it.

To solve my issue I added an inline JS script to my main HTML file:

<script type="text/javascript">
  try {
    var gui = require('nw.gui');
    var win = gui.Window.get();
    win.on('new-win-policy', function (frame, url, policy) {
        gui.Shell.openExternal(url);
        policy.ignore();
    });
  } catch(e) { }
</script>

(The empty try/catch is there because an error is thrown when my game is run outside of the node environment).