|
| 1 | +--- |
| 2 | +title: DMG |
| 3 | +sidebar: |
| 4 | + order: 1 |
| 5 | +--- |
| 6 | + |
| 7 | +import CommandTabs from '@components/CommandTabs.astro'; |
| 8 | +import { Image } from 'astro:assets'; |
| 9 | +import StandardDmgLight from '@assets/distribute/dmg/standard-dmg-light.png'; |
| 10 | +import StandardDmgDark from '@assets/distribute/dmg/standard-dmg-dark.png'; |
| 11 | + |
| 12 | +DMG(苹果磁盘镜像)格式是一个常见的 macOS 安装程序文件,它将你的 [App Bundle][App Bundle 分发指南]包裹在一个用户友好的安装窗口中。 |
| 13 | + |
| 14 | +安装程序窗口包括你的应用程序图标和应用程序文件夹图标,用户需要将应用程序图标拖动到应用程序文件夹图标来安装它。 |
| 15 | +对于发布在 App Store 之外的 macOS 应用来说,这是最常见的安装方法。 |
| 16 | + |
| 17 | +本指南仅涵盖使用 DMG 格式在 App Store 之外发布应用程序的细节。 |
| 18 | +有关 macOS 分发选项和配置的更多信息,请参阅 [App Bundle 分发指南]。 |
| 19 | +要在 App Store 中发布你的 macOS 应用,请参阅 [App Store 分发指南]。 |
| 20 | + |
| 21 | +要为你的应用创建一个苹果磁盘镜像(DMG),你可以使用 Tauri 命令行并在 Mac 电脑上运行 `tauri build` 命令。 |
| 22 | + |
| 23 | +<CommandTabs |
| 24 | + npm="npm run tauri build --bundles dmg" |
| 25 | + yarn="yarn tauri build --bundles dmg" |
| 26 | + pnpm="pnpm tauri build --bundles dmg" |
| 27 | + cargo="cargo tauri build --bundles dmg" |
| 28 | +/> |
| 29 | + |
| 30 | +<Image |
| 31 | + class="dark:sl-hidden" |
| 32 | + src={StandardDmgLight} |
| 33 | + alt="Standard DMG window" |
| 34 | +/> |
| 35 | +<Image |
| 36 | + class="light:sl-hidden" |
| 37 | + src={StandardDmgDark} |
| 38 | + alt="Standard DMG window" |
| 39 | +/> |
| 40 | + |
| 41 | +## 窗口背景 |
| 42 | + |
| 43 | +你可以用 [`tauri.conf.json > bundle > macOS > dmg > background`] 配置选项设置 DMG 安装窗口的自定义背景图像。 |
| 44 | + |
| 45 | +```json title="tauri.conf.json" ins={4-6} |
| 46 | +{ |
| 47 | + "bundle": { |
| 48 | + "macOS": { |
| 49 | + "dmg": { |
| 50 | + "background": "./images/" |
| 51 | + } |
| 52 | + } |
| 53 | + } |
| 54 | +} |
| 55 | +``` |
| 56 | + |
| 57 | +例如,你的 DMG 背景图像可以包括一个箭头,告诉用户它必须将应用程序图标拖动到应用程序文件夹。 |
| 58 | + |
| 59 | +## 窗口大小和位置 |
| 60 | + |
| 61 | +默认窗口大小为 660x400。如果你需要不同的尺寸来适应你的自定义背景图片,请设置 [`tauri.conf.json > bundle > macOS > dmg > windowSize`] 配置。 |
| 62 | + |
| 63 | +```json title="tauri.conf.json" ins={5-8} |
| 64 | +{ |
| 65 | + "bundle": { |
| 66 | + "macOS": { |
| 67 | + "dmg": { |
| 68 | + "windowSize": { |
| 69 | + "width": 800, |
| 70 | + "height": 600 |
| 71 | + } |
| 72 | + } |
| 73 | + } |
| 74 | + } |
| 75 | +} |
| 76 | +``` |
| 77 | + |
| 78 | +此外,你可以通过 [`tauri.conf.json > bundle > macOS > dmg > windowPosition`] 设置初始窗口位置。 |
| 79 | + |
| 80 | +```json title="tauri.conf.json" ins={5-8} |
| 81 | +{ |
| 82 | + "bundle": { |
| 83 | + "macOS": { |
| 84 | + "dmg": { |
| 85 | + "windowPosition": { |
| 86 | + "x": 400, |
| 87 | + "y": 400 |
| 88 | + } |
| 89 | + } |
| 90 | + } |
| 91 | + } |
| 92 | +} |
| 93 | +``` |
| 94 | + |
| 95 | +## 图标位置 |
| 96 | + |
| 97 | +你可以使用 [appPosition] and [applicationFolderPosition] 配置值分别更改 app 和*应用程序文件夹*的图标位置。 |
| 98 | + |
| 99 | +```json title="tauri.conf.json" ins={5-12} |
| 100 | +{ |
| 101 | + "bundle": { |
| 102 | + "macOS": { |
| 103 | + "dmg": { |
| 104 | + "appPosition": { |
| 105 | + "x": 180, |
| 106 | + "y": 220 |
| 107 | + }, |
| 108 | + "applicationFolderPosition": { |
| 109 | + "x": 480, |
| 110 | + "y": 220 |
| 111 | + } |
| 112 | + } |
| 113 | + } |
| 114 | + } |
| 115 | +} |
| 116 | +``` |
| 117 | + |
| 118 | +:::caution |
| 119 | +由于一个已知的问题,在 CI/CD 平台上创建 DMG 时,图标大小和位置不适用。 |
| 120 | +请参阅 [tauri-apps/tauri#1731] 了解更多信息。 |
| 121 | +::: |
| 122 | + |
| 123 | +[App Bundle 分发指南]: /distribute/macos-application-bundle |
| 124 | +[App Store 分发指南]: /distribute/app-store |
| 125 | +[appPosition]: /reference/config/#appposition |
| 126 | +[applicationFolderPosition]: /reference/config/#applicationfolderposition |
| 127 | +[tauri-apps/tauri#1731]: https://github.com/tauri-apps/tauri/issues/1731 |
0 commit comments