Skip to content
Tauri 中文网

DMG

DMG(Apple 磁盘映像)格式是一种常见的 macOS 安装程序文件,可将你的 App Bundle 封装在一个用户友好的安装窗口中。

¥The DMG (Apple Disk Image) format is a common macOS installer file that wraps your App Bundle in a user-friendly installation window.

安装程序窗口包含你的应用图标和应用文件夹图标,用户需要将应用图标拖到应用文件夹图标上进行安装。这是在 App Store 之外分发的 macOS 应用最常见的安装方法。

¥The installer window includes your app icon and the Applications folder icon, where the user is expected to drag the app icon to the Applications folder icon to install it. It is the most common installation method for macOS applications distributed outside the App Store.

本指南仅介绍使用 DMG 格式在 App Store 之外分发应用的详细信息。有关配置选项的更多信息,请参阅 App Bundle 分发指南。要在 App Store 中分发你的 macOS 应用,请参阅 App Store 分发指南

¥This guide only covers details for distributing apps outside the App Store using the DMG format. See the App Bundle distribution guide for more information on macOS distribution options and configurations. To distribute your macOS app in the App Store, see the App Store distribution guide.

要为你的应用创建 Apple 磁盘映像,你可以使用 Tauri CLI 并在 Mac 电脑中运行 tauri build 命令:

¥To create an Apple Disk Image for your app you can use the Tauri CLI and run the tauri build command in a Mac computer:

npm run tauri build -- --bundles dmg
Standard DMG window Standard DMG window

窗口背景

¥Window background

你可以使用 [tauri.conf.json > bundle > macOS > dmg > background] 配置选项为 DMG 安装窗口设置自定义背景图片:

¥You can set a custom background image to the DMG installation window with the [tauri.conf.json > bundle > macOS > dmg > background] configuration option:

tauri.conf.json
{
"bundle": {
"macOS": {
"dmg": {
"background": "./images/"
}
}
}
}

例如,你的 DMG 背景图片可以包含一个箭头,以指示用户必须将应用图标拖到应用文件夹中。

¥For instance your DMG background image can include an arrow to indicate to the user that it must drag the app icon to the Applications folder.

窗口大小和位置

¥Window size and position

默认窗口大小为 660x400。如果你需要不同的尺寸以适合你的自定义背景图片,请设置 [tauri.conf.json > bundle > macOS > dmg > windowSize] 配置:

¥The default window size is 660x400. If you need a different size to fit your custom background image, set the [tauri.conf.json > bundle > macOS > dmg > windowSize] configuration:

tauri.conf.json
{
"bundle": {
"macOS": {
"dmg": {
"windowSize": {
"width": 800,
"height": 600
}
}
}
}
}

此外,你可以通过 [tauri.conf.json > bundle > macOS > dmg > windowPosition] 设置初始窗口位置:

¥Additionally you can set the initial window position via [tauri.conf.json > bundle > macOS > dmg > windowPosition]:

tauri.conf.json
{
"bundle": {
"macOS": {
"dmg": {
"windowPosition": {
"x": 400,
"y": 400
}
}
}
}
}

图标位置

¥Icon position

你可以分别使用 appPositionapplicationFolderPosition 配置值更改应用和应用文件夹图标位置:

¥You can change the app and Applications folder icon position with the appPosition and applicationFolderPosition configuration values respectively:

tauri.conf.json
{
"bundle": {
"macOS": {
"dmg": {
"appPosition": {
"x": 180,
"y": 220
},
"applicationFolderPosition": {
"x": 480,
"y": 220
}
}
}
}
}

:::caution 提醒

由于已知问题,在 CI/CD 平台上创建 DMG 时不应用图标大小和位置。有关更多信息,请参阅 tauri-apps/tauri#1731

¥Due to a known issue, icon sizes and positions are not applied when creating DMGs on CI/CD platforms. See tauri-apps/tauri#1731 for more information.

:::


Tauri v2.4 中文网 - 粤ICP备13048890号
Nodejs.cn 旗下网站