Increasing window size for same ID
Bug Report
- Go into dev console (F12) from any nwjs app (including NWJS Default app)
-
gui = require("nw.gui"); - open window
gui.Window.open('https://google.com', { id: 'testWindowId', title: 'test-window' }) - again open window
gui.Window.open('https://google.com', { id: 'testWindowId', title: 'test-window' }) - height has increase in second window
- resize last window
- again open window
gui.Window.open('https://google.com', { id: 'testWindowId', title: 'test-window' }) - the new window has increased in size relative the last manually resized window
Expected/Proposed Behavior
I would expect same window height in two opened windows.
The real problem is not that two windows open different sizes, that could be forced to be the same.
The real problem is that the mechanism storing the size of a window (that a user has changed manually) is faulty, and opens the new window about 28 pixels larger (on my computer, at least). This breaks the memory of child-window sizes between runs.
Additional Info
- Operating System: macos
- NW.js Version: 0.69.1 SDK (but works in 0.64.0)
- Code snippet: First :
gui = require("nw.gui");
gui.Window.open('https://google.com', { id: 'testWindowId', title: 'test-window' });
and then, run this (giving the system time to register the previous window size) :
gui.Window.open('https://google.com', { id: 'testWindowId', title: 'test-window' });
It's possible this is related to https://github.com/nwjs/nw.js/issues/4217 based on the discussion in https://bugs.chromium.org/p/chromium/issues/detail?id=357533 which is linked in the mentioned NW issue. The upstream issue got closed due to inactivity. I can see you already have a workaround - could you post it here for people who come across the same bug?
This is a work-around that seems to fix this growing-window bug
The idea is to intercept the close event for a new window, and resize before closing it in my new close-function (so the new size will be remembered next time)
Open new window and intercept close-event:
let gui = require('nw.gui');
gui.Window.open('notes.html',
{
id: 'notesWindowId',
position: 'center',
width: 600,
height: 600,
title: 'Notes'
},
win=>win.on('loaded', () => {
notes_win = nw.Window.get(win.window);addWindowMenu(title, 'notes_win');
win.on('close', function() { fixNwjsBug7973( win)} );
})
)
The function called from new close-event (as defined above):
function fixNwjsBug7973( win){
// This function should be called after intercepting 'close' event for a spawned window
// Nwjs bug 7973 is related to windows with same id growing each time they are opened again
// Hide and resize
win.hide();
resizeHeightBy = win.window.outerHeight - win.window.innerHeight;
win.resizeBy(0,-resizeHeightBy);
// Remove 'close' event handler, and then close window
win.removeAllListeners('close');
win.close()
}
Tested on MacOS and Windows
when fix it?
It seems that the issue is fixed in nw 0.100.1 (and maybe earlier than that?)