如何添加 Electron DMG 背景图片?

How do I add an Electron DMG background image?

我有一个 Electron 应用程序在 DMG 构建中不显示背景图像。我的 package.json(顶级)包含:

"pack": "build --dir",
"dist": "build"

我的 "build" 目录也有一个有效的 "background.png"。还需要配置什么?

以上配置正确。如果配置了 non-default OS X 安装文件夹,electron-builder 中曾有一个错误导致背景不显示。

Update for PKG build in electron-builder

package.json

  "build": {
    "appId": "com.audio.application",
    "productName": "Audio-App",
    "artifactName": "${productName}-Setup-${version}.${ext}",
    "copyright": "Copyright © 2020 Audio Corp",
    "mac": {
      "category": "com.audio.application",
      "target": [
        "pkg"
      ],
      "icon": "dist",
      "identity": "identity",
      "darkModeSupport": true,
      "hardenedRuntime": true,
      "gatekeeperAssess": false,
      "artifactName": "${productName}.${ext}"
    },
    "pkg": {
      "scripts": "../build/pkg-scripts",
      "installLocation": "/Applications",
      "background": {
        "file": "build/icon/background.png",
        "alignment": "bottomleft"
      },
      "allowAnywhere": true,
      "allowCurrentUserHome": true,
      "allowRootDirectory": true,
      "license": "build/license.html",
      "welcome": "build/resources/welcome.txt",
      "conclusion": "build/resources/conclusion.txt",
      "isVersionChecked": true,
      "isRelocatable": false,
      "overwriteAction": "upgrade"
    },
    "directories": {
      "buildResources": "release",
      "output": "release"
    }
    },

构建目录的文件夹结构 -
(在项目的根级别)


背景(数据类型:PkgBackgroundOptions

PkgBackgroundOptions

  • 文件(数据类型:字符串)
  • 对齐方式(数据类型:BackgroundAlignment | null)
  • 缩放(数据类型:BackgroundScaling | null)

背景对齐

  • "center" | "left" | "right" | "top" | "bottom" | "topleft" | "topright" | "bottomleft" | "bottomright"

背景缩放

  • "tofit" | "none" | "proportional"

参考:pkgOptions