简体   繁体   English

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

[英]Hiding the Window Menu when app is full screen on Windows?

I have an Electron app running on OSX and Windows. 我有一个在OSX和Windows上运行的Electron应用程序。 When the Windows version is full screen it still shows a menu bar and I would like it not to. 当Windows版本全屏时它仍然显示一个菜单栏,我不希望它。 Basically I want what happens on OSX: when the app is "full screen" no menu bar or window 'chrome' should appear. 基本上我想要在OSX上发生的事情:当应用程序是“全屏”时,不会出现菜单栏或窗口“chrome”。

I've tried setAutoHideMenuBar during my window set up but that made no difference. 我在窗口设置期间尝试过setAutoHideMenuBar但没有区别。 Am I using it wrong or misunderstanding what it is supposted to do? 我使用它是错误的还是误解了它所做的是什么?

I've seen some QAs suggestin setMenu(null) but won't that blow out the menu entirely? 我在setMenu(null)看到了一些setMenu(null)建议,但是不会完全炸掉菜单吗? I do want the menu when in window mode or (on Windows) when the Alt key is pressed. 我想在窗口模式下按菜单,或者在按下Alt键时(在Windows上)。


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

From the docs : 来自文档

win.setAutoHideMenuBar(hide) win.setAutoHideMenuBar(隐藏)

 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. 设置后,菜单栏将仅在用户按下单个Alt键时显示。

If the menu bar is already visible, calling setAutoHideMenuBar(true) won't hide it immediately. 如果菜单栏已经可见,则调用setAutoHideMenuBar(true)将不会立即隐藏它。

From the docs 来自文档

win.setMenuBarVisibility(visible) Windows Linux win.setMenuBarVisibility(可见)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. 如果菜单栏是自动隐藏的,用户仍然可以通过按下单个Alt键调出菜单栏。

From the docs 来自文档

win.setMenu(menu) Linux Windows win.setMenu(菜单)Linux Windows

 menu Menu 

Sets the menu as the window's menu bar, setting it to null will remove the menu bar. 将菜单设置为窗口的菜单栏,将其设置为null将删除菜单栏。

An error on my part and a "go figure" 我的错误和“走向数字”

  1. I was misusing the setAutoHideMenuBar command, trying to use it as an option when creating the window. 我误用了setAutoHideMenuBar命令,尝试在创建窗口时将其用作选项。 The correct option syntax is autoHideMenuBar: true . 正确的选项语法是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. To handle toggling fullscreen, in setting up my menu I used the shortcut 要处理全屏切换,在设置菜单时我使用了快捷方式

    role: 'togglefullscreen'

While this works and includes the keyboard accelerators, the menu bar always appears and the autoHideMenuBar setting is apparently ignored. 虽然这有效并且包括键盘加速器,但菜单栏始终显示,并且autoHideMenuBar设置显然被忽略。 I don't understand why. 我不明白为什么。 So instead of the shortcut, I use this and the menu bar hides correctly. 因此,我使用此菜单栏而不是快捷方式,而是正确隐藏。

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

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

Use setFullScreen method. 使用setFullScreen方法。

function (item, focusedWindow) {
    if (focusedWindow) {
        focusedWindow.setFullScreen(!focusedWindow.isFullScreen())
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM