-
Notifications
You must be signed in to change notification settings - Fork 3.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
NW2: Size and position are not retained in 0.44.1 after app restart on macOS #7370
Comments
It should be retained when the window has Otherwise it's undefined behavior. |
@rogerwang When other windows are opened with window.open and an ID is given - their position isn't retained. This was the case with NW1 |
@rogerwang, I just tested latest nightly build with the following setup:
nwjs-size-and-position-test.zip You are right, after I add id to window it attempts to retain size, but it seems that position is not retained, it always goes back to "center". It seems that position is retained if I don't specify initial value, but then window is positioned somewhere in the top left corner of the screen on the first start. Also, if I increase windows size to max (500 x 500 in this case) by dragging right bottom corner of the window, then close the window and restart the app the window will be opened maximized to the size of the screen, will not be within those 500 x 500 limits that are set. Same goes with this (position is retained, but by default it's in top left corner): nw.Window.open('index.html', {id: 'dialog', max_width: 500, max_height: 500}) and this (position is not retained): nw.Window.open('index.html', {id: 'dialog', position: 'center', max_width: 500, max_height: 500}) In both cases if I stretch window to the max_width / max_height it shows as maximized to full size of the screen after re-open. My expectation was that "position" there would be used as initial value and on subsequent calls to Window.open it would be retained and then after re-open window is not maximized. I never noticed link to https://developer.chrome.com/apps/app_window#type-CreateWindowOptions in https://nwjs.readthedocs.io/en/latest/References/Window/#windowopenurl-options-callback, I'm wondering if we should just use innerBounds / outerBounds instead of min/max_width/height... |
It's expected that the function call parameter ( |
I have not thought about all possible use cases, but the way it worked in nw1 mode seemed logical to me on the use cases where we called nw.Window.open. So, in nw1 mode the parameters are used to size and position the window for the first open, but on subsequent open previously saved size and position would be used instead of provided options.
In particular, if window is opened like this:
and then user changes size and position of that window it would retain previously saved size and position on subsequent open, which is not the case in nw2 mode. If we could use innerBounds / outerBounds with behavior defined in referenced https://developer.chrome.com/apps/app_window#type-CreateWindowOptions and have position / width / height parameters to have different behavior (i.e. override previous user selection with values of parameter of the call) that would be fine, but it does not look like innerBounds / outerBounds are accepted as the options (it errors out with something like this: Uncaught TypeError: Error in invocation of nw.Window.open(string url, optional nw.Window.CreateWindowOptions options, optional function callback): Error at parameter 'options': Unexpected property: 'innerBounds'.) If we want to override user selection we probably can always go with some implementation that does not use id and instead tracks and periodically persists size and position after resize and move by user, then intelligently calculates values that should be used for next open based on previously saved state and whatever other considerations that should be taken into account. |
This is fixed in git and will be available in the next nightly build. |
@rogerwang, I've just tested http://dl.nwjs.io/live-build/nw44/20200227-162000/8a3755e42/, it seems that it restores to previous size and position with the exception of one case that I mentioned above. If you increase windows size to max (500 x 500 in this case) by dragging right bottom corner of the window, then close the window and restart the app the window will be opened maximized to the size of the screen, will not be within those 500 x 500 limits that are set. It can be demonstrated either via attached example or simply by running something like this in dev tools, then expanding window to 500 x 500, closing and re-running the code: nw.Window.open('data:,test', {id: 'dialog', position: 'center', width:200, height: 200, max_width: 500, max_height: 500}) Also, for some reason initial position of the window is not centered vertically, only horizontally. So, if I run the following it shows window centered around 1/3 of screen hight, closer to the top of the screen.
|
I actually did not notice this before, but it seems that not centering window vertically is present in nw1 as well, going back all the way to 0.42.x (I have not checked with earlier versions). The defect were window is expanded to max bounds and then shows maximized on re-open is not present in nw1 mode, only in nw2. |
@arudnev I just fixed the maximize issue. For the position problem, please file another issue for it. |
@rogerwang, thanks for the fix, I'll test it once nightly build is available. I've created #7402 for the issue with vertical centering |
Related to #7322 (covers Linux and Windows), #7230
NWJS Version : 0.44.1
Operating System : macOS Catalina (10.15.3)
Expected behavior
Window size and position should be retained after app restart.
Actual behavior
Window is centered and has default window size after app restart in
nw2
mode.When running with
--disable-features=nw2
the app retains size and position if quit viaCmd+Q
or by pressing close button on window frame, but does not remember size or position if quit viaQuit
menu item on dock item.The issue with saving size and position in
nw1
mode might be related to the following error that is being logged in that case (quit viaQuit
menu item on dock item when Devtools are not opened):How to reproduce
Running vanilla sdk build on macOS in
nw2
andnw1
modes without opening Devtools and checking that size and position are retained after quit (might behave differently forCmd+Q
, close button on window frame andQuit
menu item on dock icon) should be enough to reproduceThe text was updated successfully, but these errors were encountered: