0

I am using latest nodewebkit and running the following code as per documentation ( https://github.com/rogerwang/node-webkit/wiki/Screen ) but its always failing. Can anyone please tell me why i have this error please and how do you fix it?

<!DOCTYPE html>
<html>
<body>
    <script>
      function ScreenToString(screen) {
        var string = "";
        string += "screen: "+ screen.id;
        return string;
      } 

      var gui = require('nw.gui');
      gui.Screen.Init();
      var string  = "" ; 
      var screens = gui.Screen.screens;

      for(var i=0;i<screens.length; i++) {
        string += ScreenToString(screens[i]);
      }
      document.write(string);
    </script>
</body>
</html>

ERROR:

Uncaught node.js Error 

SyntaxError: Unexpected end of input
    at Object.parse (native)
    at Screen.screens (screen.js:65:15)
    at file:///C:/Users/xxx/Downloads/node-webkit-v0.11.0-pre-win-x64/node-webkit-v0.11.0-pre-win-x64/test.html:14:28
  • 1
    The above code works for me. It shows the text _screen: 2528732444screen: 2779098405_. What version of node-webkit are you using, and is the HTML you posted currently the entire content of the application? – Troy Gizzi Oct 16 '14 at 05:24
  • @TroyGizzi: i am using version 0.10.2 and i see now i have output. But how can i tell my application to run in second screen not in first screen? for example i have main screen and i have a monitor connected. i want to open my nodewebkit in the second monitor when its launched how can i do this? –  Oct 16 '14 at 05:47

1 Answers1

1

This script moves the window to the center of the other screen (if there is one).

var gui = require('nw.gui');

// initialize the Screen singleton
gui.Screen.Init();

// get the current window
var win = gui.Window.get();

function moveToOtherWindow() {
    for(var i = 0; i < gui.Screen.screens.length; i++) {
        var screen = gui.Screen.screens[i];
        // check if the window is horizontally outside the bounds of this screen
        if (win.x < screen.bounds.x || win.x > screen.bounds.x + screen.bounds.width) {
            // move the window to this screen
            win.x = screen.bounds.x + (screen.bounds.width - win.width) / 2;
            win.y = screen.bounds.y + (screen.bounds.height - win.height) / 2;
            break;
        }
    }
}

moveToOtherWindow();
Troy Gizzi
  • 2,480
  • 1
  • 14
  • 15
  • http://paste.ubuntu.com/8577493/ - i have this package.json, When i have single monitor it works to do full-screen. But when i used your example in dual screen then it does not make full-screen. –  Oct 17 '14 at 05:46
  • 1
    `"kiosk": true` never works for me. I have to do it programatically, using `gui.Window.get().enterKioskMode();`. When I did that, at the bottom of the code above, and using your _package.json_, it moved the app to the other screen and maximized it in kiosk mode. Is that what you're trying to make it do? – Troy Gizzi Oct 17 '14 at 06:09