index.js
function(setup){
        const screen = Electron.screen;
        const screenSize = screen.getPrimaryDisplay().workAreaSize;
        const position = setup.position;
        let x = 0;
        let y = 0;
        const positionMargin = 0;
        let windowWidth = setup.width;
        let windowHeight = setup.height;

        // If the window dimensions are not set
        if(!windowWidth || !windowHeight){
            console.log('Cannot position a window with the width/height not defined!');

            // Put in in the center
            setup.center = true;
            return false;
        }

        // If the position name is incorrect
        if(['center', 'top', 'right', 'bottom', 'left', 'topLeft', 'leftTop', 'topRight',
                'rightTop', 'bottomRight', 'rightBottom', 'bottomLeft', 'leftBottom'].indexOf(position) < 0){

            console.log('The specified position "' + position + '" is\'not correct! Check the docs.');
            return false;
        }

        // It's center by default, no need to carry on
        if(position === 'center'){
            return false;
        }

        // Compensate for the frames
        if (setup.frame === true) {
            switch (position) {
                case 'left':
                    break;

                case 'right':
                    windowWidth += 8;
                    break;

                case 'top':
                    windowWidth += 13;
                    break;

                case 'bottom':
                    windowHeight += 50;
                    windowWidth += 13;
                    break;

                case 'leftTop':
                case 'topLeft':
                    windowWidth += 0;
                    windowHeight += 50;
                    break;

                case 'rightTop':
                case 'topRight':
                    windowWidth += 8;
                    windowHeight += 50;
                    break;

                case 'leftBottom':
                case 'bottomLeft':
                    windowWidth -= 0;
                    windowHeight += 50;
                    break;

                case 'rightBottom':
                case 'bottomRight':
                    windowWidth += 8;
                    windowHeight += 50;
                    break;
            }
        }

        switch (position) {
            case 'left':
                y = Math.floor((screenSize.height - windowHeight) / 2);
                x = positionMargin - 8;
                break;

            case 'right':
                y = Math.floor((screenSize.height - windowHeight) / 2);
                x = (screenSize.width - windowWidth) - positionMargin;
                break;

            case 'top':
                y = positionMargin;
                x = Math.floor((screenSize.width - windowWidth) / 2);
                break;

            case 'bottom':
                y = (screenSize.height - windowHeight) - positionMargin;
                x = Math.floor((screenSize.width - windowWidth) / 2);
                break;

            case 'leftTop':
            case 'topLeft':
                y = positionMargin;
                x = positionMargin - 8;
                break;

            case 'rightTop':
            case 'topRight':
                y = positionMargin;
                x = (screenSize.width - windowWidth) - positionMargin;
                break;

            case 'leftBottom':
            case 'bottomLeft':
                y = (screenSize.height - windowHeight) - positionMargin;
                x = positionMargin - 8;
                break;

            case 'rightBottom':
            case 'bottomRight':
                y = (screenSize.height - windowHeight) - positionMargin;
                x = (screenSize.width - windowWidth) - positionMargin;
                break;
        }

        return [x, y];
    }
function(setup){
        const screen = Electron.screen;
        const screenSize = screen.getPrimaryDisplay().workAreaSize;
        const position = setup.position;
        let x = 0;
        let y = 0;
        const positionMargin = 0;
        let windowWidth = setup.width;
        let windowHeight = setup.height;

        // If the window dimensions are not set
        if(!windowWidth || !windowHeight){
            console.log('Cannot position a window with the width/height not defined!');

            // Put in in the center
            setup.center = true;
            return false;
        }

        // If the position name is incorrect
        if(['center', 'top', 'right', 'bottom', 'left', 'topLeft', 'leftTop', 'topRight',
                'rightTop', 'bottomRight', 'rightBottom', 'bottomLeft', 'leftBottom'].indexOf(position) < 0){

            console.log('The specified position "' + position + '" is\'not correct! Check the docs.');
            return false;
        }

        // It's center by default, no need to carry on
        if(position === 'center'){
            return false;
        }

        // Compensate for the frames
        if (setup.frame === true) {
            switch (position) {
                case 'left':
                    break;

                case 'right':
                    windowWidth += 8;
                    break;

                case 'top':
                    windowWidth += 13;
                    break;

                case 'bottom':
                    windowHeight += 50;
                    windowWidth += 13;
                    break;

                case 'leftTop':
                case 'topLeft':
                    windowWidth += 0;
                    windowHeight += 50;
                    break;

                case 'rightTop':
                case 'topRight':
                    windowWidth += 8;
                    windowHeight += 50;
                    break;

                case 'leftBottom':
                case 'bottomLeft':
                    windowWidth -= 0;
                    windowHeight += 50;
                    break;

                case 'rightBottom':
                case 'bottomRight':
                    windowWidth += 8;
                    windowHeight += 50;
                    break;
            }
        }

        switch (position) {
            case 'left':
                y = Math.floor((screenSize.height - windowHeight) / 2);
                x = positionMargin - 8;
                break;

            case 'right':
                y = Math.floor((screenSize.height - windowHeight) / 2);
                x = (screenSize.width - windowWidth) - positionMargin;
                break;

            case 'top':
                y = positionMargin;
                x = Math.floor((screenSize.width - windowWidth) / 2);
                break;

            case 'bottom':
                y = (screenSize.height - windowHeight) - positionMargin;
                x = Math.floor((screenSize.width - windowWidth) / 2);
                break;

            case 'leftTop':
            case 'topLeft':
                y = positionMargin;
                x = positionMargin - 8;
                break;

            case 'rightTop':
            case 'topRight':
                y = positionMargin;
                x = (screenSize.width - windowWidth) - positionMargin;
                break;

            case 'leftBottom':
            case 'bottomLeft':
                y = (screenSize.height - windowHeight) - positionMargin;
                x = positionMargin - 8;
                break;

            case 'rightBottom':
            case 'bottomRight':
                y = (screenSize.height - windowHeight) - positionMargin;
                x = (screenSize.width - windowWidth) - positionMargin;
                break;
        }

        return [x, y];
    }
function ( setup ) { const screen = Electron . screen ; const screenSize = screen . getPrimaryDisplay ( ) . workAreaSize ; const position = setup . position ; let x = 0 ; let y = 0 ; const positionMargin = 0 ; let windowWidth = setup . width ; let windowHeight = setup . height ; // If the window dimensions are not set if ( ! windowWidth || ! windowHeight ) { console . log ( 'Cannot position a window with the width/height not defined!' ) ; // Put in in the center setup . center = true ; return false ; } // If the position name is incorrect if ( [ 'center' , 'top' , 'right' , 'bottom' , 'left' , 'topLeft' , 'leftTop' , 'topRight' , 'rightTop' , 'bottomRight' , 'rightBottom' , 'bottomLeft' , 'leftBottom' ] . indexOf ( position ) < 0 ) { console . log ( 'The specified position "' + position + '" is\'not correct! Check the docs.' ) ; return false ; } // It's center by default, no need to carry on if ( position === 'center' ) { return false ; } // Compensate for the frames if ( setup . frame === true ) { switch ( position ) { case 'left' : break ; case 'right' : windowWidth += 8 ; break ; case 'top' : windowWidth += 13 ; break ; case 'bottom' : windowHeight += 50 ; windowWidth += 13 ; break ; case 'leftTop' : case 'topLeft' : windowWidth += 0 ; windowHeight += 50 ; break ; case 'rightTop' : case 'topRight' : windowWidth += 8 ; windowHeight += 50 ; break ; case 'leftBottom' : case 'bottomLeft' : windowWidth -= 0 ; windowHeight += 50 ; break ; case 'rightBottom' : case 'bottomRight' : windowWidth += 8 ; windowHeight += 50 ; break ; } } switch ( position ) { case 'left' : y = Math . floor ( ( screenSize . height - windowHeight ) / 2 ) ; x = positionMargin - 8 ; break ; case 'right' : y = Math . floor ( ( screenSize . height - windowHeight ) / 2 ) ; x = ( screenSize . width - windowWidth ) - positionMargin ; break ; case 'top' : y = positionMargin ; x = Math . floor ( ( screenSize . width - windowWidth ) / 2 ) ; break ; case 'bottom' : y = ( screenSize . height - windowHeight ) - positionMargin ; x = Math . floor ( ( screenSize . width - windowWidth ) / 2 ) ; break ; case 'leftTop' : case 'topLeft' : y = positionMargin ; x = positionMargin - 8 ; break ; case 'rightTop' : case 'topRight' : y = positionMargin ; x = ( screenSize . width - windowWidth ) - positionMargin ; break ; case 'leftBottom' : case 'bottomLeft' : y = ( screenSize . height - windowHeight ) - positionMargin ; x = positionMargin - 8 ; break ; case 'rightBottom' : case 'bottomRight' : y = ( screenSize . height - windowHeight ) - positionMargin ; x = ( screenSize . width - windowWidth ) - positionMargin ; break ; } return [ x , y ] ; }
Resolves a position name into x & y coordinates.
@param setup The window setup object
Resolves a position name into x & y coordinates .