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

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

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

http://img4.mukewang.com/639ecd840001c93a15870576.jpg

<!-- index.html -->

<!DOCTYPE html>

<html>

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

  }

}

非常具体地说,我正在尝试更改此设置:

http://img4.mukewang.com/639ecd9b0001383604960129.jpg

绝地无双
浏览 599回答 2
2回答

侃侃尔雅

实际上,您可以更改该特定名称。但它很老套,没有任何意义 :)。对于 MacOSX,转到node_modules/electron/dist/Electron.app/Contents/Info.plist并更改 的值CFBundleName。对于打包的应用程序,electron/builder 将调查productName或name参与package.json- 不需要 hack。

繁星淼淼

事实证明,您无法在开发过程中更改它。当您构建(使用electron-builder)时,它会将其更改name为package.json.
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript