0

倒计时完成后,我想将主要BrowserWindow内容带到前台。打电话electron.BrowserWindow.getFocusedWindow().show()App.vue,我收到错误消息

Uncaught TypeError: Cannot read property 'getFocusedWindow' of undefined

electron正在通过const electron = window.require("electron");in导入App.vue

4

1 回答 1

1

为了避免在渲染器进程上一起做这部分,同时以更干净的方式做,你可以尝试将调用 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()
于 2020-11-27T20:55:58.667 回答