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

标签 javascript electron electron-builder

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

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

enter image description here

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

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

最佳答案

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

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

对于打包的应用程序,electron/builder 将查看 package.json 中的 productNamename 字段 - 不需要 hack。

关于javascript - 如何在 ElectronJS 中设置窗口名称/标题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63232399/

相关文章:

javascript - 覆盖 ui-bootstrap 的默认分页模板

javascript - WebGL-渲染一个又一个形状时出现问题

typescript - tsc 不移动 html 资源

javascript - 在 Electron 应用程序中使用 sql.js

javascript - Electron Js - 主进程发生javascript错误

javascript - 将图像与文本叠加、保存并共享

javascript - 表示 2 个或更多 dimple.js 图表

operating-system - Electron 会影响其他操作系统应用程序吗?

electron - Electron 构建时如何保留所选文件

electron - Electron Builder用户可编辑的资源?