javascript - 当应用程序在 Windows 上全屏显示时隐藏窗口菜单?

标签 javascript electron

我有一个在 OSX 和 Windows 上运行的 Electron 应用程序。当 Windows 版本全屏显示时,它仍然显示一个菜单栏,我不希望它显示。基本上我想要在 OSX 上发生的事情:当应用程序是“全屏”时,不应出现菜单栏或窗口“chrome”。

我在窗口设置期间尝试了 setAutoHideMenuBar 但这没有任何区别。我是不是用错了它或者误解了它应该做什么?

我已经看到一些 QA 建议 setMenu(null) 但这不会完全破坏菜单吗?在窗口模式下或(在 Windows 上)按下 Alt 键时,我确实需要菜单。


   mainWindow = new BrowserWindow({
        show: false,
        width: 1024,
        height: 768,
        minWidth: 400,
        minHeight: 200,
        resizable: true,
        backgroundColor: '#222',
        center: true,
        setAutoHideMenuBar: true
    });

来自docs :

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.

来自docs

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.

来自docs

win.setMenu(menu) Linux Windows

menu Menu

Sets the menu as the window’s menu bar, setting it to null will remove the menu bar.

最佳答案

我的错误和“去图”

  1. 我误用了 setAutoHideMenuBar 命令,试图在创建窗口时将其用作选项。正确的选项语法是 autoHideMenuBar: true

app.on('ready', function () {
    mainWindow = new BrowserWindow({
        show: false,
        width: 1024,
        height: 768,
        minWidth: 400,
        minHeight: 200,
        resizable: true,
        backgroundColor: '#222',
        center: true,
        autoHideMenuBar: true
    }); 

  1. 为了处理全屏切换,在设置我的菜单时我使用了快捷方式

    Angular 色:'togglefullscreen'

虽然这有效并且包括键盘加速器,但菜单栏总是出现并且 autoHideMenuBar 设置显然被忽略了。我不明白为什么。所以我没有使用快捷方式,而是使用它并且菜单栏正确隐藏。

            {
                label: 'Toggle Full Screen',
                click: () => { toggleFullscreen();},
                accelerator: 'CmdOrCtrl+f'
            }

function toggleFullscreen() {
    if (mainWindow.isFullScreen()) {
        mainWindow.setFullScreen(false);
    } else {
        mainWindow.setFullScreen(true);
    }
}

关于javascript - 当应用程序在 Windows 上全屏显示时隐藏窗口菜单?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45850802/

相关文章:

javascript - 使用JQuery实时大写用户输入的第一个字符

javascript - 按 StudentId 对数组进行分组并查找具有相同元素的子数组的总和

electron - 在Electron中的窗口之间共享数据

node.js - Electron handle 正常崩溃

javascript - 如何从 NodeJs 启动和停止 Electron 应用程序

javascript - 突出显示点击栏系列

javascript - 使用 v-model 和 v-bind 的单选按钮上的值的 Vue JS Prop 错误 ="$attrs"

javascript - 使用 momentjs 进行时间验证

angularjs - 如何用 Electron 构建一个微星?

node.js - 窗口值未定义 - Electron js