javascript - How do I remove the menu bar from a specific window in electron?
问题描述
I have a menu in my application that when you click on document properties another window pops up, but the application menu is also being inherited by this window, so you can open the document properties window from the document properties window. I just want to disable the menu for the document properties window,the only way I've been able to achieve this was by making the window frameless, but I still want the title bar to show, so that's not the solution I'm looking for.
I've tried using docProps.removeMenu(), docProps.setMenu(null), and even docProps.setApplicationMenu(null). I've moved it around, tried making docProps a global variable, nothing has worked.
This is my code:
//Create references for modules that require electron
const { app, BrowserWindow, Menu } = require('electron')
//Create a global reference for the main window
let mainWindow
function createWindow () {
//Create the browser window
mainWindow = new BrowserWindow({
minWidth: 300,
minHeight: 300,
backgroundColor: '#888888'
})
//Load the index.html file
mainWindow.loadFile('index.html')
//Reload the main window on resize
mainWindow.on('resize', function () {
mainWindow.reload()
})
}
function createAppMenu () {
//Create application menu template
const template = [
{
label: 'File',
submenu: [
{
label: 'Document Properties...',
click: function () {
docProps = new BrowserWindow({
width: 250,
height: 300,
resizable: false,
title: 'Document Properties'
})
//This isn't working and I'm not sure why
docProps.removeMenu()
}
}
]
},
{
label: 'Edit'
},
{
label: 'View'
},
{
label: 'Window'
},
{
label: 'Help'
}
]
//Build app menu from template
const menu = Menu.buildFromTemplate(template)
Menu.setApplicationMenu(menu)
}
//Call the createWindow function once electron has finished initializing
app.on('ready', function () {
createWindow()
mainWindow.maximize()
createAppMenu()
})
You can see the entire project at https://github.com/Leglaine/ElectroText
The only error message I get is when I try to call docProps.setApplicationMenu(null), it says that setApplicationMenu cannot be called on docProps, but I didn't really expect that to work anyway. Thanks in advance for your help!
解决方案
win.removeMenu()
当win.setMenu(null)
您已经通过Menu.setApplicationMenu()
尝试像这样设置一个空菜单
docProps.setMenu(Menu.buildFromTemplate([]))
推荐阅读
- spring-boot - Jacoco 与 Spring Boot 应用程序的集成在检测时出现错误
- kubernetes - 将 kiali 仪表板的时间范围从 6 小时增加到更高的数字
- java - 在不同的 chrome 选项卡中运行测试方法
- matplotlib - 根据列中的值使用 matplotlib 生成图例
- ms-access - 比较 Access 查询中的 2 个以上字段
- c++ - C ++中线程中带有while循环的条件变量
- android - 动态获取 XML 中的应用程序 ID
- reactjs - 如何将文件附件按钮更改为发送消息“重置”的重置按钮
- python - 查找与文档中单词出现相关的单词频率
- sql-server - 获取状态变化数据