Electron 中的子窗口并不总是显示在顶部

nik*_*ssc 4 javascript electron

我正在尝试从主进程创建两个窗口。第二个窗口应始终显示在第一个窗口的顶部。在 Electron 网站上,我读到我必须创建一个父窗口和一个子窗口才能做到这一点。这是我的代码:

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);
Run Code Online (Sandbox Code Playgroud)

当我启动程序时,它会创建两个窗口,但子窗口并不总是在顶部。当我关闭父窗口 (win) 时,两个窗口都关闭了。如何使子窗口始终显示在顶部?我在 Gnome 上使用 Fedora 24。

teh*_*cpu 5

尝试child.setAlwaysOnTop(true);在 child-win init 之后使用方法。

  • 它总是在所有应用程序之上,如果我们只想在电子应用程序本身之上呢? (2认同)