[英]How do I set the window name/title in ElectronJS?
Silly question, but I've been struggling just trying to change an Electron window's name for a while now, so hopefully someone here can just help me with it.愚蠢的问题,但我一直在努力尝试更改 Electron 窗口的名称一段时间,所以希望这里有人可以帮助我。
I'm trying to change it from "Electron" to anything else.我正在尝试将其从“Electron”更改为其他任何内容。 I can get every other title/name changed to what I want, but no matter what I seem to try, it always says "Electron"... :(我可以将所有其他标题/名称更改为我想要的,但无论我尝试什么,它总是说“Electron”... :(
<!-- index.html -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title> <!-- Window name isn't this -->
</head>
<body>
<h1>hi</h1>
</body>
</html>
// main.js
const { app, BrowserWindow } = require('electron')
function createWindow() {
const win = new BrowserWindow({
width: 800,
height: 600,
webPreferences: {
nodeIntegration: true
},
title: 'Foo' // Window name isn't this
})
app.setName('Bar') // Window name isn't this
win.setTitle('ReeeeeBar') // Window name isn't this
win.loadFile('index.html')
}
app.whenReady().then(createWindow)
// package.json
{
"name": "foobar-electron-app", // Window name isn't this
"main": "main.js",
"dependencies": {
"electron": "^9.1.2"
}
}
To be very specific, I'm trying to change this:非常具体地说,我正在尝试更改此设置:
Actually, you can change that particular name.实际上,您可以更改该特定名称。 But it's hacky and has no sense:).但它很老套,没有任何意义:)。
For MacOSX, go to node_modules/electron/dist/Electron.app/Contents/Info.plist
and change value for CFBundleName
.对于 MacOSX,go 到node_modules/electron/dist/Electron.app/Contents/Info.plist
并更改CFBundleName
的值。
For packaged apps electron/builder will look into productName
or name
field in package.json
- no need for hacks.对于打包的应用程序,electron/builder 将查看package.json
productName
name
字段——不需要 hack。
As it turns out, you can't change that during development.事实证明,您无法在开发过程中更改它。
When you build (with electron-builder ) it will change that to whatever the name
field is in package.json
.当您构建(使用electron-builder )时,它会将其更改为package.json
中的任何name
字段。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.