【问题标题】:How do I set the window name/title in ElectronJS?如何在 ElectronJS 中设置窗口名称/标题?
【发布时间】:2020-11-23 16:40:43
【问题描述】:

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

我正在尝试将其从“电子”更改为其他任何内容。我可以将其他所有标题/名称更改为我想要的,但无论我尝试什么,它总是说“电子”...... :(

<!-- 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"
  }
}

具体来说,我正在尝试改变这一点:

【问题讨论】:

    标签: javascript electron electron-builder


    【解决方案1】:

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

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

    对于打包的应用程序,electron/builder 将查看 package.json 中的 productName 或 name 字段 - 无需破解。

    【讨论】:

    • 非常有趣。我可能不需要,因为现在我相信构建会拥有它,但很高兴知道!谢谢。
    【解决方案2】:

    事实证明,在开发过程中您无法更改。

    当您构建(使用electron-builder)时,它会将其更改为name 字段在package.json 中的任何内容。

    【讨论】:

      猜你喜欢
      • 2010-09-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-03-30
      相关资源
      最近更新 更多