javascript - 动态切换 “autohideMenuBar”不起作用吗?

标签 javascript electron

Electron 7.1.10,Windows 10

当我的应用进入全屏模式时,我正在尝试关闭菜单可见性并将其设置为“自动隐藏”,以便可以通过Alt键对其进行访问。下面的代码确实将其关闭,但是没有启用“通过Alt键显示”行为。

我尝试注释掉mainindow.setMenuBarVisibility();调用,因为这可能是绝对的:菜单永远不会显示,但是菜单仍然以全屏显示。我还尝试过更改顺序,以便在将可见性设置为false之前先调用mainindow.autohideMenuBar = true。没运气。

有人遇到过这种情况么?

BrowserWindow文档似乎表明我正在尝试执行的工作:

win.setMenuBarVisibility(visible) Windows Linux

visible Boolean

Sets whether the menu bar should be visible. If the menu bar is auto-hide, users can still bring up the menu bar by pressing the single Alt key.


    if (mainindow.isFullScreen()) {
        // coming out of full screen
        mainindow.setMenuBarVisibility(true);
        mainindow.autohideMenuBar = false
        mainindow.setFullScreen(false);
    } else {
        // entering full screen
        mainindow.setMenuBarVisibility(false);
        mainindow.autohideMenuBar = true
        mainindow.setFullScreen(true);
    }

最佳答案

因此设置该属性不起作用,但是使用较旧的方法setAutoHideMenuBar可以-尽管docs状态为deprecated。好像是个错误。

The Electron team is currently undergoing an initiative to convert separate getter and setter functions in Electron to bespoke properties with get and set functionality. During this transition period, both the new properties and old getters and setters of these functions will work correctly and be documented.



win.setAutoHideMenuBar(hide)

hide Boolean

Sets whether the window menu bar should hide itself automatically. Once set the menu bar will only show when users press the single Alt key.

If the menu bar is already visible, calling setAutoHideMenuBar(true) won't hide it immediately.

Deprecated


if (mainWindow.isFullScreen()) {
    // coming out of FS
    // mainWindow.autohideMenuBar = false
    mainWindow.setAutoHideMenuBar(false);
    mainWindow.setMenuBarVisibility(true);
    mainWindow.setFullScreen(false);
} else {
    // mainWindow.autohideMenuBar = true
    mainWindow.setAutoHideMenuBar(true);
    mainWindow.setMenuBarVisibility(false);
    mainWindow.setFullScreen(true);
}

关于javascript - 动态切换 “autohideMenuBar”不起作用吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60080376/

相关文章:

javascript - 引导模式+ajax+jquery+验证+.net core 2.0

javascript - Angular/JavaScript 解析并仅获取 paramMap 的值

javascript - 如何用chartJS链接2个轴?

javascript - Electron 对话框不保存文件

electron - 如何在 Electron 中包含 Chrome DevTools?

javascript - React-native - this.setState 仅在第二次单击后更新

javascript - JS 字符串解析像 jQuery 一样添加和删除值

javascript - 当在对象中指定自定义键时,它会将其转换为数字

javascript - Electron 初学者,如何从菜单读取文件到html?

node.js - Electron : please install sqlite3 package manually