Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Child window in Electron does not always show on top

I am trying to create two windows from the main process. The second window should always be shown on top of the first window. On the Electron website I have read that I have to create a parent and a child window to do 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 start the program it creates two windows but the child window is not always on top. When I close the parent window (win) both windows are closed. How do I make the child window always be shown on top? I'm using Fedora 24 with Gnome.

like image 538
niklassc Avatar asked Feb 07 '23 11:02

niklassc


1 Answers

Try to use child.setAlwaysOnTop(true); method after child-win init.

like image 100
tehcpu Avatar answered Feb 10 '23 23:02

tehcpu