Getting a Chrome app window to open at the bottom right of screen

后端 未结 1 1585
半阙折子戏
半阙折子戏 2021-01-22 03:39

I would like my Chrome app to open so it\'s touching the task bar and just offset from the right of the screen.

My current code:

chrome.app.runtime.onLau         


        
相关标签:
1条回答
  • 2021-01-22 04:20

    If you're okay with setting the outer bounds, that is, the full window size (and the content is potentially smaller), then it's simple:

    chrome.app.runtime.onLaunched.addListener(function() {
      var windowWidth = 300;
      var windowHeight = 325;
      chrome.app.window.create('window.html', {
        outerBounds: { // 'bounds' is deprecated, and you want full window size
          width: windowWidth,
          height: windowHeight,
          left: screen.availWidth - windowWidth,
          top: screen.availHeight - windowHeight,
        },
        resizable: false,
        frame: 'none'
      });      
    });
    

    If you want to set inner bounds, that is the exact size of the window content, then you can't predict the size of the window accurately. You'll have to first create it and then reposition it in the callback:

    chrome.app.runtime.onLaunched.addListener(function() {
      var windowWidth = 300;
      var windowHeight = 325;
      chrome.app.window.create(
        'window.html',
        {
          innerBounds: {
            width: windowWidth,
            height: windowHeight
          },
          resizable: false,
          frame: 'none'
        },
        function(win) {
          win.outerBounds.setPosition(
            screen.availWidth - win.outerBounds.width, // left
            screen.availHeight - win.outerBounds.height // top
          );
        }
      );      
    });
    

    All in all, it'a a good idea to review the actual documentation of chrome.app.window API.

    0 讨论(0)
提交回复
热议问题