如何在 ElectronJS 中设置窗口名称/标题?

cor*_*ons 3 javascript electron electron-builder

愚蠢的问题,但我现在一直在努力尝试更改电子窗口的名称,所以希望这里有人可以帮助我。

我正在尝试将其从“电子”更改为其他任何名称。我可以将所有其他标题/名称更改为我想要的,但无论我尝试什么,它总是显示“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>
Run Code Online (Sandbox Code Playgroud)
// 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)
Run Code Online (Sandbox Code Playgroud)
// package.json
{
  "name": "foobar-electron-app", // Window name isn't this
  "main": "main.js",
  "dependencies": {
    "electron": "^9.1.2"
  }
}
Run Code Online (Sandbox Code Playgroud)

更具体地说,我正在尝试改变这一点: 在此输入图像描述

san*_*ier 6

实际上,您可以更改该特定名称。但它很hacky并且没有任何意义:)。

对于 MacOSX,请转至node_modules/electron/dist/Electron.app/Contents/Info.plist并更改 的值CFBundleName

对于打包应用程序,电子/构建器将研究productNamename现场输入package.json- 无需黑客。