Skip to content
Tauri 中文网

macOS 应用包

应用包是 macOS 上执行的包格式。它是一个简单的目录,包含应用成功运行所需的所有内容,包括应用可执行文件、资源、Info.plist 文件以及其他文件,如 macOS 框架。

🌐 An application bundle is the package format that is executed on macOS. It is a simple directory that includes everything your application requires for successful operation, including your app executable, resources, the Info.plist file and other files such as macOS frameworks.

要将你的应用打包为 macOS 应用打包包,你可以使用 Tauri CLI,并在 Mac 电脑上运行 tauri build 命令:

🌐 To package your app as a macOS application bundle you can use the Tauri CLI and run the tauri build command in a Mac computer:

npm run tauri build -- --bundles app

🌐 File structure

macOS 应用包是一个具有以下结构的目录:

🌐 The macOS app bundle is a directory with the following structure:

├── <productName>.app
│ ├── Contents
│ │ ├── Info.plist
│ │ ├── ...additional files from [`tauri.conf.json > bundle > macOS > files`]
│ ├── MacOS
│ │ ├── <app-name> (app executable)
│ ├── Resources
│ │ ├── icon.icns (app icon)
│ │ ├── ...resources from [`tauri.conf.json > bundle > resources`]
│ ├── _CodeSignature (codesign information generated by Apple)
│ ├── Frameworks
│ ├── PlugIns
│ ├── SharedSupport

有关更多信息,请参阅官方文档

🌐 See the official documentation for more information.

🌐 Native configuration

应用包由 Info.plist 文件配置,该文件包括包含你的应用标识和 macOS 读取的配置值的键值对。

🌐 The app bundle is configured by the Info.plist file, which includes key-value pairs with your app identity and configuration values read by macOS.

Tauri 会自动配置最重要的属性,例如你的应用二进制名称、版本、包标识符、最低系统版本等。

🌐 Tauri automatically configures the most important properties such as your app binary name, version. bundle identifier, minimum system version and more.

要扩展配置文件,请在 src-tauri 文件夹中创建一个 Info.plist 文件,并包含你想要的键值对:

🌐 To extend the configuration file, create an Info.plist file in the src-tauri folder and include the key-pairs you desire:

src-tauri/Info.plist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>NSCameraUsageDescription</key>
<string>Request camera access for WebRTC</string>
<key>NSMicrophoneUsageDescription</key>
<string>Request microphone access for WebRTC</string>
</dict>
</plist>

Info.plist 文件与 Tauri CLI 生成的值合并。覆盖默认值时请小心,例如应用版本,因为它们可能与其他配置值冲突并引入意外行为。

🌐 This Info.plist file is merged with the values generated by the Tauri CLI. Be careful when overwriting default values such as application version as they might conflict with other configuration values and introduce unexpected behavior.

有关更多信息,请参阅[官方 Info.plist 文档]。

🌐 See the official Info.plist documentation for more information.

🌐 Info.plist localization

Info.plist 文件本身只支持一种语言,通常是英语。如果你想支持多种语言,可以为每种额外的语言创建 InfoPlist.strings 文件。每个文件应放置在应用包中 Resources 目录下的各自语言专用 lproj 目录中。

🌐 The Info.plist file by itself only supports a single language, typically English. If you want to support multiple languages, you can create InfoPlist.strings files for each additional language. Each file belongs in its own language specific lproj directory in the Resources directory in the application bundle.

要自动打包这些文件,你可以利用 Tauri 的 resources 功能。为此,请在你的项目中创建如下模式的文件结构:

🌐 To bundle these files automatically you can leverage Tauri’s resources feature. To do that, create a file structure in your project following this pattern:

├── src-tauri
│ ├── tauri.conf.json
│ ├── infoplist
│ │ ├── de.lproj
│ │ │ ├── InfoPlist.strings
│ │ ├── fr.lproj
│ │ │ ├── InfoPlist.strings

虽然 infoplist 目录名称可以自由选择,只要你在下面的资源配置中更新它,但 lproj 目录必须遵循 <lang-code>.lproj 命名,并且字符串目录文件必须命名为 InfoPlist.strings(大写的 i 和 p)。在大多数情况下,语言代码应该是符合 BCP 47 的两字母代码。

🌐 While the infoplist directory name can be chosen freely, as long as you update it in the resources config below, the lproj directories must follow the <lang-code>.lproj naming and the string catalogue files must be named InfoPlist.strings (capital i and p). For most cases the language code should be a two letter code following BCP 47.

对于上面显示的 Info.plist 示例,de.lproj > InfoPlist.strings 文件可能如下所示:

🌐 For the Info.plist example shown above, the de.lproj > InfoPlist.strings file could look like this:

de.lproj/InfoPlist.strings
NSCameraUsageDescription = "Kamera Zugriff wird benötigt für WebRTC Funktionalität";
NSMicrophoneUsageDescription = "Mikrofon Zugriff wird benötigt für WebRTC Funktionalität";

最后,使用上面提到的资源功能让 Tauri 拾取这些文件:

🌐 Lastly, make Tauri pick up these files by using the resources feature mentioned above:

src-tauri/tauri.conf.json
{
"bundle": {
"resources": {
"infoplist/**": "./"
}
}
}

🌐 Entitlements

权限是一种特殊的 Apple 配置键值对,作为一种权利或特权,赋予你的应用特定的功能,例如作为用户的默认电子邮件客户端和使用 App 沙箱功能。

🌐 An entitlement is a special Apple configuration key-value pair that acts as a right or privilege that grants your app particular capabilities, such as act as the user’s default email client and using the App Sandbox feature.

当你的应用被签名时,将应用权限。更多信息请参见[代码签名文档]。

🌐 Entitlements are applied when your application is signed. See the code signing documentation for more information.

要定义应用所需的权利,你必须创建权利文件并配置 Tauri 以使用它。

🌐 To define the entitlements required by your application, you must create the entitlements file and configure Tauri to use it.

  1. src-tauri 文件夹中创建一个 Entitlements.plist 文件,并配置你的应用所需的键值对:
src-tauri/Entitlements.plist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>com.apple.security.app-sandbox</key>
<true/>
</dict>
</plist>
  1. 配置 Tauri 以使用 Entitlements.plist 文件:
tauri.conf.json
{
"bundle": {
"macOS": {
"entitlements": "./Entitlements.plist"
}
}
}

有关更多信息,请参阅官方文档

🌐 See the official documentation for more information.

🌐 Minimum system version

默认情况下,你的 Tauri 应用支持 macOS 10.13 及更高版本。如果你使用的 API 需要更新的 macOS 系统,并且希望在应用包中强制该要求,你可以配置 tauri.conf.json > bundle > macOS > minimumSystemVersion 值:

🌐 By default your Tauri application supports macOS 10.13 and above. If you are using an API that requires a newer macOS system and want to enforce that requirement in your app bundle, you can configure the tauri.conf.json > bundle > macOS > minimumSystemVersion value:

tauri.conf.json
{
"bundle": {
"macOS": {
"minimumSystemVersion": "12.0"
}
}
}

🌐 Including macOS frameworks

如果你的应用运行需要额外的 macOS 框架,你可以在 tauri.conf.json > bundle > macOS > frameworks 配置中列出它们。框架列表可以包括系统框架、自定义框架以及 dylib 文件。

🌐 If your application requires additional macOS frameworks to run, you can list them in the tauri.conf.json > bundle > macOS > frameworks configuration. The frameworks list can include either system or custom frameworks and dylib files.

tauri.conf.json
{
"bundle": {
"macOS": {
"frameworks": [
"CoreAudio",
"./libs/libmsodbcsql.18.dylib",
"./frameworks/MyApp.framework"
]
}
}
}

🌐 Adding custom files

你可以使用 tauri.conf.json > bundle > macOS > files 配置将自定义文件添加到你的应用包中,这会将目标路径映射到相对于 tauri.conf.json 文件的源文件。这些文件会被添加到 <product-name>.app/Contents 文件夹中。

🌐 You can use the tauri.conf.json > bundle > macOS > files configuration to add custom files to your application bundle, which maps the destination path to its source relative to the tauri.conf.json file. The files are added to the <product-name>.app/Contents folder.

tauri.conf.json
{
"bundle": {
"macOS": {
"files": {
"embedded.provisionprofile": "./profile-name.provisionprofile",
"SharedSupport/docs.md": "./docs/index.md"
}
}
}
}

在上面的例子中,profile-name.provisionprofile 文件被复制到 <product-name>.app/Contents/embedded.provisionprofiledocs/index.md 文件被复制到 <product-name>.app/Contents/SharedSupport/docs.md

🌐 In the above example, the profile-name.provisionprofile file is copied to <product-name>.app/Contents/embedded.provisionprofile and the docs/index.md file is copied to <product-name>.app/Contents/SharedSupport/docs.md.


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