How to use the nw.gui.Screen function in nw

To help you get started, we’ve selected a few nw examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github nekobato / Polidium / app / app.js View on Github external
var gui = require('nw.gui');
var win = gui.Window.get();
gui.Screen.Init();
var screens = gui.Screen.screens;
var CustomTrayMenu = require('./custom-tray');

var customTray;

process.on('log', function(msg) { console.log(msg); });

function init() {

  // win.width = screens[0].work_area.width;
  // win.height = screens[0].work_area.height;

  win.showDevTools();

  if (!customTray) {
    customTray = new CustomTrayMenu();
github mauvilsa / nw-page-editor / js / nw-winstate.js View on Github external
function restoreWindowState() {
    // deltaHeight already saved, so just restore it and adjust window height
    if (deltaHeight !== 'disabled' && typeof winState.deltaHeight !== 'undefined') {
      deltaHeight = winState.deltaHeight;
      winState.height = winState.height - deltaHeight;
    }


    //Make sure that the window is displayed somewhere on a screen that is connected to the PC. 
    //Imagine you run the program on a secondary screen connected to a laptop - and then the next time you start the 
    //program the screen is not connected...
    gui.Screen.Init();
    var screens = gui.Screen.screens;
    var locationIsOnAScreen = false;
    for (var i = 0; i < screens.length; i++) {
      var screen = screens[i];
      if (winState.x > screen.bounds.x && winState.x < screen.bounds.x + screen.bounds.width) {
        if (winState.y > screen.bounds.y && winState.y < screen.bounds.y + screen.bounds.height) {
          console.debug("Location of window (" + winState.x + "," + winState.y + ") is on screen " + JSON.stringify(screen));
          locationIsOnAScreen = true;
        }
      }
    }

    if (!locationIsOnAScreen) {
      console.debug("Last saved position of windows is not usable on current monitor setup. Moving window to center!");
      win.setPosition("center");
    }
    else {
github fritx / nw-remote / src / remote.js View on Github external
/* global Peer */
const gui = require('nw.gui')
const uuid = require('node-uuid')
const fixMacMenu = require('./util').fixMacMenu
const bindHotkeys = require('./util').bindHotkeys
const peerConfig = require('./util').peerConfig
const isWin32 = require('./util').isWin32

gui.Screen.Init()
gui.Window.get().focus()

const screenId = isWin32 ? 0 : gui.Screen.screens[0].id // random screen
const mediaConfig = {
  audio: false,
  video: {
    mandatory: {
      chromeMediaSource: 'desktop',
      // chromeMediaSourceId: 'screen:0',
      chromeMediaSourceId: `screen:${screenId}`,
      maxWidth: 1,
      maxHeight: 1,
      maxFrameRate: 1, // minimum
    }
  }
}

const host = location.search.match(/[?&]host=([^&]+)/)[1]
const port = +location.search.match(/[?&]port=([^&]+)/)[1]
github loktar00 / web-screensavers / src / screensaver.js View on Github external
var ngui            = require('nw.gui'),
    nwin            = ngui.Window.get();

// go through the arguments check for config or preview
ngui.App.argv.forEach(function(elm){
    var argVal = elm.toLowerCase();
    if(argVal.indexOf('/c') > -1 || argVal.indexOf('/p') > -1){
        // right now just dont run the screensaver
        ngui.App.closeAllWindows();
    }
});


ngui.Screen.Init();

var screens         = ngui.Screen.screens,
    screenWidth     = 0,
    screenHeight    = 0;

// iterate through the screens get the dimensions
for(var i = 0; i < screens.length; i++) {
  screenWidth += screens[i].bounds.width;
  screenHeight = Math.max(screenHeight, screens[i].bounds.height);
}

// add event listeners to kill the screensaver on user input
document.body.addEventListener('keyup', function(){
    ngui.App.closeAllWindows();
});
github nwjs / nw.js / tests / manual_tests / custom_tray_menu / index.html View on Github external
function trayAreaIsTop(pos) {
      var screen;
      if (gui.Screen.Init) gui.Screen.Init();
      function posInBounds(s) {
        return pos.y > s.bounds.y && pos.y < (s.bounds.y + s.bounds.height) &&
          pos.x > s.bounds.x && pos.x < (s.bounds.x + s.bounds.width);
      }
      screen = gui.Screen.screens.filter(posInBounds)[0];
      return pos.y < (screen.bounds.y + screen.bounds.height) / 2;
    }
    function showCustomTrayMenuAt(position) {
github teak / Pussh / Resources / js / index.js View on Github external
this.settings = new Settings();
    this.name = gui.App.manifest.name;
    this.version = gui.App.manifest.version;
    this.window = gui.Window.get();
    this.tink = new Audio('aud/ts-tink.ogg');

    this.services = new Services(this);

    this._settingsWindow = null;

    this.watch();
    this.launchAtStartup();
    this.setupTray();
    this.buildTrayMenu(false);

    gui.Screen.Init();

    var _self = this;

    gui.App.on('reopen', function() {
        _self.showSettingsWindow();
    });
}
github jitsi / jitsi-meet / resources / nwjs-integration / index.html View on Github external
function obtainDesktopStream (callback, errorCallback) {
                if (!screenInitialized) {
                    gui.Screen.Init();
                    screenInitialized = true;
                }
                gui.Screen.chooseDesktopMedia(
                    ["window","screen"],
                    function(streamId) {
                        var vid_constraint = {
                            mandatory: {
                                chromeMediaSource: 'desktop',
                                chromeMediaSourceId: streamId,
                                maxWidth: 1920,
                                maxHeight: 1080
                            },
                            optional: []
                        };
                        navigator.webkitGetUserMedia({
                            audio: false, video: vid_constraint
                        }, callback, function (error) {
                            errorCallback &&
                                errorCallback(error, vid_constraint);
github jaruba / PowderPlayer / src / updater.html View on Github external
if (jsonData[mn]["assets"][kl]["browser_download_url"].split(".").pop() == appExt.split(".").pop()) {
						file_url = jsonData[mn]["assets"][kl]["browser_download_url"];
						$("#update-header").text("Update to Powder "+jsonData[mn]["tag_name"]);
						$(".spinner").fadeOut();
						$("#starter").fadeIn();
						return;
					}
				}
			}
			if (!file_url) win.close();
		});
	});
	
	apiRequest.end();
		
	gui.Screen.Init();
	
	var win = gui.Window.get();
	win.setMaximumSize(320,133);
	win.setMinimumSize(320,133);
	win.resizeTo(320,133);
	win.setResizable(false);
	
	var total = 0;
	var current = 0;
	
	var focused = true;
	win.focus();
	win.on('focus', function() { focused = true; }); 
	win.on('blur', function() { focused = false; });
		
	function getReadableFileSizeString(fileSizeInBytes) {
github armadito / armadito-av / app / index.html View on Github external
function trayAreaIsTop(pos) {
                var screen;
                if (gui.Screen.Init) gui.Screen.Init();
                function posInBounds(s) {
                    return pos.y > s.bounds.y && pos.y < (s.bounds.y + s.bounds.height) &&
                        pos.x > s.bounds.x && pos.x < (s.bounds.x + s.bounds.width);
                }
                screen = gui.Screen.screens.filter(posInBounds)[0];
                return pos.y < (screen.bounds.y + screen.bounds.height) / 2;
            }
            function showCustomTrayMenuAt(position) {