为了避免在渲染器进程上一起做这部分,同时以更干净的方式做,你可以尝试将调用 getFocusedWindow().show() 移动到电子端。通过做这样的事情:
应用程序.vue
let ipcRenderer = window.require("electron").ipcRenderer
ipcRenderer.send("bring-to-foreground");
电子.js
ipcMain.on("bring-to-foreground", (e) => {
electron.BrowserWindow.getFocusedWindow().show();
}
我还认为你应该使用保持你的主窗口,这样你就不要使用 getFocusedWindow 因为根据文档,如果窗口首先没有聚焦,它可能会返回 null 。像这样:
let mainWindow;
const createWindow = () => {
mainWindow = new BrowserWindow({...})
//rest of the function goes here
}
所以你可以简单地做:
mainwindow.show()