以前的窗口焦点/电子 [英] Previous Window Focus / Electron

查看:22
本文介绍了以前的窗口焦点/电子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前正在为一个艰难的问题挠头.我刚从电子开始,到目前为止一切都很好.但是,当窗口被隐藏时(它是一个带有快捷方式的弹出窗口,当您按 Enter 时会消失),我想将焦点返回到前一个窗口.

Currently scratching my head on a tough one. I'm just starting with electron and so far so good. However, when the window gets hidden (it's a popup showing with a shortcut, that goes away when you press enter), I'd like to give the focus back to the previous window.

我使用的是 Mac,菜单栏显示了我以前的应用程序的名称,因此看起来焦点已返回给应用程序,但由于未选择窗口,因此并不完全.

I'm using Mac, and the menu bar shows my previous app's name so it looks like the focus is given back to the app, but not entirely since the window is not selected.

知道如何解决这个问题吗?

Any idea how to fix that?

谢谢!

推荐答案

对于Linux:我发现 browserWindow.hide() 正确地恢复了焦点.

For Linux: I found browserWindow.hide() correctly restores focus.

对于 Windows:browserWindow.minimize() 正确恢复焦点.

For Windows: browserWindow.minimize() correctly restores focus.

对于 Mac:app.hide() 正确恢复焦点.注意:不幸的是,调用 app.hide() 会隐藏所有窗口.没有已知的方法可以在不使用 app.hide() 隐藏所有窗口的情况下保持某些窗口打开.

For Mac: app.hide() correctly restores focus. Note: calling app.hide() unfortunately hides all windows. There is no known way of keeping some windows open without hiding all with app.hide().

这适用于 Mac、Linux 和 Windows:

This works both on Mac, Linux and Windows:

hide() {
    this.window.minimize();
    this.window.hide();
    if (process.platform == "darwin") this.app.hide()
}

show() {
    this.window.show();
    this.window.restore();
}

这篇关于以前的窗口焦点/电子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆