【问题标题】:How to bring window into foreground in electron-vue如何在electron-vue中将窗口置于前台
【发布时间】:2021-03-10 09:40:34
【问题描述】:

我想在倒计时结束后将主要的BrowserWindow 带到前台。在App.vue 中调用electron.BrowserWindow.getFocusedWindow().show() 时,出现错误

Uncaught TypeError: Cannot read property 'getFocusedWindow' of undefined

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

【问题讨论】:

标签: vue.js electron electron-vue


【解决方案1】:

为了避免在渲染器进程上一起做这部分,同时以更干净的方式做,你可以尝试将调用 getFocusedWindow().show() 移到电子端。 通过这样做:

App.vue

 let ipcRenderer = window.require("electron").ipcRenderer
 ipcRenderer.send("bring-to-foreground");

electron.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()

【讨论】:

    猜你喜欢
    • 2012-10-21
    • 2010-10-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-09-17
    相关资源
    最近更新 更多