Electron child window not always displayed on top

I am trying to create two windows from the main process. The second window should always be displayed on top of the first window. I read on the Electron website that you need to create a parent and child window for this. This is my code:

let win;
let child;

function createWindow(){
  // Create the browser window.
  win = new BrowserWindow({width: 1024, height: 768, show: false});

  child = new BrowserWindow({parent: win});
  child.show();

  win.once('ready-to-show', () => {
    win.show()
  })
  // and load the index.html of the app.
  win.loadURL(`file://${__dirname}/index.html`);

  // Emitted when the window is closed.
  win.on('closed', () => {
    win = null;
  });
}

app.on('ready', createWindow);

When I run the program, it creates two windows, but the child window is not always on top. When I close the parent window (win), both windows close. How to make the child window always appear on top? I am using Fedora 24 with Gnome.

+4
source share
1 answer

Try using the method child.setAlwaysOnTop(true);after initialization with win-win.

+2
source

Source: https://habr.com/ru/post/1649835/


All Articles