nw.js icon indicating copy to clipboard operation
nw.js copied to clipboard

Increasing window size for same ID

Open pragma-git opened this issue 3 years ago • 3 comments

Bug Report

  1. Go into dev console (F12) from any nwjs app (including NWJS Default app)
  2. gui = require("nw.gui");
  3. open window gui.Window.open('https://google.com', { id: 'testWindowId', title: 'test-window' })
  4. again open window gui.Window.open('https://google.com', { id: 'testWindowId', title: 'test-window' })
  5. height has increase in second window
  6. resize last window
  7. again open window gui.Window.open('https://google.com', { id: 'testWindowId', title: 'test-window' })
  8. 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' });

pragma-git avatar Oct 04 '22 14:10 pragma-git

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?

ayushmanchhabra avatar Oct 15 '22 16:10 ayushmanchhabra

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

pragma-git avatar Oct 16 '22 18:10 pragma-git

when fix it?

fgt1t5y avatar Sep 13 '24 14:09 fgt1t5y

It seems that the issue is fixed in nw 0.100.1 (and maybe earlier than that?)

pragma-git avatar Jul 04 '25 21:07 pragma-git