As mentioned here: https://developer.chrome.com/apps/app_window#method-create

If you use ID's for you windows (as you need if you don't like to start you app twice) the position an size is getting stored. And they advice you to create the window hidden an move and re-size it before showing.

If I try to create a window on a particular screen like this:

var left =  parseInt(displayInfo.workArea.left);

chrome.app.window.create('index.html', {
      id: 'window-'+displayInfo.id,
      hidden: true,
      bounds: {left: left, top: 0, width: 100 , height: 100  }
, callbackWindow.bind(null, left, 0, displayInfo));

var callbackWindow = function (left, top, displayInfo, createdWindow) {
    createdWindow.moveTo(displayInfo.workArea.left, displayInfo.workArea.top);
    console.log(createdWindow.id, createdWindow.getBounds());
    createdWindow.show();
};

The first time the application starts the window is on the correct position, now if we move the window and re-size it and then restart the app. The stay on the same potion as before closing.

In other words, we can not override the stored position. Is this a Bug or should it work like this?

I've made my tests on Windows 7 with Chrome 32.0.1700.107 dev-m

有帮助吗?

解决方案

moveTo is the standard DOM moveTo. The AppWindow object just forwards moveTo and resizeTo functions to the window object.

What happens if you try to use the AppWindow.setBounds instead? I'm guessing, but haven't tested, that the DOM functions are being ignored as the window is not visible.

Also, you are using a fairly old version of Chrome. I think the current stable version is 34.

其他提示

The documentation is a bit unclear on how moveTo should be called.

Please try the following format instead, in line with other parametrized calls:

createdWindow.moveTo({
    left: displayInfo.workArea.left,
    top: displayInfo.workArea.top
});
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top