我有一个在 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.
最佳答案
我的错误和“去图”
- 我误用了
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
});
为了处理全屏切换,在设置我的菜单时我使用了快捷方式
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/