跳到內容
Tauri

設定

Tauri 設定物件。它從檔案中讀取,您可以在其中定義前端資源、設定打包器和定義系統托盤圖示。

設定檔由 tauri init 命令產生,該命令位於您的 Tauri 應用程式原始碼目錄 (src-tauri) 中。

產生後,您可以隨意修改它以自訂您的 Tauri 應用程式。

檔案格式

預設情況下,設定定義為名為 tauri.conf.json 的 JSON 檔案。

Tauri 也分別透過 config-json5config-toml Cargo 功能支援 JSON5 和 TOML 檔案。JSON5 檔案名稱必須是 tauri.conf.jsontauri.conf.json5。TOML 檔案名稱為 Tauri.toml

平台特定設定

除了預設設定檔外,Tauri 還可以從 tauri.linux.conf.jsontauri.windows.conf.jsontauri.macos.conf.jsontauri.android.conf.jsontauri.ios.conf.json(或 Tauri.linux.tomlTauri.windows.tomlTauri.macos.tomlTauri.android.tomlTauri.ios.toml,如果使用 Tauri.toml 格式)讀取平台特定的設定,這將與主要設定物件合併。

設定結構

設定由以下物件組成

tauri.config.json 檔案範例

{
"productName": "tauri-app",
"version": "0.1.0",
"build": {
"beforeBuildCommand": "",
"beforeDevCommand": "",
"devUrl": "http://localhost:3000",
"frontendDist": "../dist"
},
"app": {
"security": {
"csp": null
},
"windows": [
{
"fullscreen": false,
"height": 600,
"resizable": true,
"title": "Tauri App",
"width": 800
}
]
},
"bundle": {},
"plugins": {}
}

物件屬性:

  • app
  • build
  • bundle
  • identifier (必填)
  • mainBinaryName
  • plugins
  • productName
  • version

app

AppConfig

應用程式設定。

預設值
{
"enableGTKAppId": false,
"macOSPrivateApi": false,
"security": {
"assetProtocol": {
"enable": false,
"scope": []
},
"capabilities": [],
"dangerousDisableAssetCspModification": false,
"freezePrototype": false,
"pattern": {
"use": "brownfield"
}
},
"windows": [],
"withGlobalTauri": false
}

build

BuildConfig

建置設定。

預設值{}

bundle

BundleConfig

捆綁器設定。

預設值
{
"active": false,
"android": {
"minSdkVersion": 24
},
"createUpdaterArtifacts": false,
"iOS": {
"minimumSystemVersion": "13.0"
},
"icon": [],
"linux": {
"appimage": {
"bundleMediaFramework": false,
"files": {}
},
"deb": {
"files": {}
},
"rpm": {
"epoch": 0,
"files": {},
"release": "1"
}
},
"macOS": {
"dmg": {
"appPosition": {
"x": 180,
"y": 170
},
"applicationFolderPosition": {
"x": 480,
"y": 170
},
"windowSize": {
"height": 400,
"width": 660
}
},
"files": {},
"hardenedRuntime": true,
"minimumSystemVersion": "10.13"
},
"targets": "all",
"useLocalToolsDir": false,
"windows": {
"allowDowngrades": true,
"certificateThumbprint": null,
"digestAlgorithm": null,
"nsis": null,
"signCommand": null,
"timestampUrl": null,
"tsp": false,
"webviewInstallMode": {
"silent": true,
"type": "downloadBootstrapper"
},
"wix": null
}
}

identifier

string

應用程式識別符,採用反向網域名稱表示法(例如 com.tauri.example)。此字串在所有應用程式中必須是唯一的,因為它用於系統設定中,例如捆綁包 ID 和 webview 資料目錄的路徑。此字串必須僅包含字母數字字元 (A-Z、a-z 和 0-9)、連字號 (-) 和句點 (.)。

mainBinaryName

string | null

應用程式主二進制檔案名稱。預設為您的 Cargo crate 名稱。

plugins

PluginConfig

外掛程式設定。

預設值{}

productName

string | null 符合 ^[^/\:*?"<>|]+$ 模式

應用程式名稱。

version

string | null

應用程式版本。它是一個 semver 版本號碼或包含 version 欄位的 package.json 檔案路徑。如果移除,則使用 Cargo.toml 中的版本號碼。

預設情況下,Android 上使用版本 1.0。

定義

AndroidConfig

Android 目標的一般設定。

物件屬性:

  • minSdkVersion
  • versionCode
minSdkVersion

integer 格式為 uint32

應用程式運作所需的最低 API 等級。如果系統的 API 等級低於指定的值,Android 系統將阻止使用者安裝應用程式。

預設值24

versionCode

integer | null 最大值為 2100000000,最小值為 1,格式為 uint32

應用程式的版本代碼。根據 Google Play 商店的要求,它限制為 2,100,000,000。

預設情況下,我們使用您設定的版本並執行以下數學運算:versionCode = version.major * 1000000 + version.minor * 1000 + version.patch

AppConfig

應用程式設定物件。

更多資訊:<https://v2.tauri.app/reference/config/#appconfig>

物件屬性:

  • enableGTKAppId
  • macOSPrivateApi
  • security
  • trayIcon
  • windows
  • withGlobalTauri
enableGTKAppId

boolean

如果設定為 true,“identifier” 將設定為 GTK 應用程式 ID(在使用 GTK 的系統上)。

macOSPrivateApi

boolean

MacOS 私有 API 設定。啟用透明背景 API 並將 fullScreenEnabled 偏好設定為 true

security

SecurityConfig

安全性設定。

預設值
{
"assetProtocol": {
"enable": false,
"scope": []
},
"capabilities": [],
"dangerousDisableAssetCspModification": false,
"freezePrototype": false,
"pattern": {
"use": "brownfield"
}
}
trayIcon

TrayIconConfig | null

應用程式系統托盤圖示的設定。

windows

WindowConfig[]

應用程式視窗設定。

預設值[]

withGlobalTauri

boolean

我們是否應該在 window.__TAURI__ 上注入 Tauri API。

AppImageConfig

AppImage 捆綁包的設定。

更多資訊:<https://v2.tauri.app/reference/config/#appimageconfig>

物件屬性:

  • bundleMediaFramework
  • files
bundleMediaFramework

boolean

包含音訊和視訊播放所需的額外 gstreamer 依賴項。這會增加捆綁包大小約 15-35MB,具體取決於您的建置系統。

files

要包含在 Appimage 二進制檔案中的檔案。

允許額外屬性string

預設值{}

AssetProtocolConfig

資產自訂協定的設定。

更多資訊:<https://v2.tauri.app/reference/config/#assetprotocolconfig>

物件屬性:

  • enable
  • scope
enable

boolean

啟用資產協定。

scope

FsScope

資產協定的存取範圍。

預設值[]

AssociationExt

string

[FileAssociation] 的擴展名。

前導 . 會自動移除。

BackgroundThrottlingPolicy

以下其中一項:

  • "disabled" 停用背景節流的策略
  • "suspend" 一種策略,當 web view 不在視窗中時,會完全暫停任務。這通常是在未設定策略的情況下的預設行為。
  • "throttle" 一種策略,當 web view 不在視窗中時,會限制處理,但不會完全暫停任務。

背景節流策略。

BeforeDevCommand

以下任何一項:

  • string 使用預設選項執行給定的腳本。
  • 使用自訂選項執行給定的腳本。物件屬性:- cwd - script (必填) - wait ##### cwd string | null 目前工作目錄。##### script string 要執行的腳本。##### wait boolean tauri dev 是否應等待命令完成。預設為 false

描述在 tauri dev 之前要執行的 shell 命令。

BuildConfig

建置設定物件。

更多資訊:<https://v2.tauri.app/reference/config/#buildconfig>

物件屬性:

  • beforeBuildCommand
  • beforeBundleCommand
  • beforeDevCommand
  • devUrl
  • features
  • frontendDist
  • runner
beforeBuildCommand

HookCommand | null

tauri build 開始之前要執行的 shell 命令。

如果您執行條件編譯,則會設定 TAURI_ENV_PLATFORM、TAURI_ENV_ARCH、TAURI_ENV_FAMILY、TAURI_ENV_PLATFORM_VERSION、TAURI_ENV_PLATFORM_TYPE 和 TAURI_ENV_DEBUG 環境變數。

beforeBundleCommand

HookCommand | null

tauri build 中的捆綁階段開始之前要執行的 shell 命令。

如果您執行條件編譯,則會設定 TAURI_ENV_PLATFORM、TAURI_ENV_ARCH、TAURI_ENV_FAMILY、TAURI_ENV_PLATFORM_VERSION、TAURI_ENV_PLATFORM_TYPE 和 TAURI_ENV_DEBUG 環境變數。

beforeDevCommand

BeforeDevCommand | null

tauri dev 開始之前要執行的 shell 命令。

如果您執行條件編譯,則會設定 TAURI_ENV_PLATFORM、TAURI_ENV_ARCH、TAURI_ENV_FAMILY、TAURI_ENV_PLATFORM_VERSION、TAURI_ENV_PLATFORM_TYPE 和 TAURI_ENV_DEBUG 環境變數。

devUrl

string | null 格式為 uri

在開發中要載入的 URL。

這通常是開發伺服器的 URL,它使用熱重載和 HMR 提供您的應用程式資源。大多數現代 JavaScript 捆綁器(如 vite)都提供了一種預設啟動開發伺服器的方法。

如果您沒有開發伺服器或不想使用開發伺服器,請忽略此選項並使用 frontendDist 並指向 web 資源目錄,Tauri CLI 將執行其內建開發伺服器並提供簡單的熱重載體驗。

features

string[] | null

傳遞給 cargo 命令的功能。

frontendDist

FrontendDist | null

應用程式資源的路徑(通常是 javascript 捆綁器的 dist 資料夾)或 URL,該 URL 可以是在 tauri 應用程式中註冊的自訂協定(例如:myprotocol://)或遠端 URL(例如:https://site.com/app)。

當提供相對於設定檔的路徑時,它會被遞迴讀取,並且所有檔案都嵌入到應用程式二進制檔案中。然後,Tauri 會尋找 index.html 並將其作為應用程式的預設進入點。

您也可以提供要嵌入的路徑列表,這允許精細控制要添加到二進制檔案中的檔案。在這種情況下,所有檔案都會添加到根目錄,您必須在 HTML 檔案中以這種方式引用它。

當提供 URL 時,應用程式將不會捆綁資源,並且應用程式預設會載入該 URL。

runner

string | null

用於建置和執行應用程式的二進制檔案。

BundleConfig

tauri-bundler 的設定。

更多資訊:<https://v2.tauri.app/reference/config/#bundleconfig>

物件屬性:

  • active
  • android
  • category
  • copyright
  • createUpdaterArtifacts
  • externalBin
  • fileAssociations
  • homepage
  • icon
  • iOS
  • license
  • licenseFile
  • linux
  • longDescription
  • macOS
  • publisher
  • resources
  • shortDescription
  • targets
  • useLocalToolsDir
  • windows
active

boolean

Tauri 是否應捆綁您的應用程式或僅輸出可執行檔。

android

AndroidConfig

Android 設定。

預設值
{
"minSdkVersion": 24
}
category

string | null

應用程式種類。

應為以下其中一項:Business、DeveloperTool、Education、Entertainment、Finance、Game、ActionGame、AdventureGame、ArcadeGame、BoardGame、CardGame、CasinoGame、DiceGame、EducationalGame、FamilyGame、KidsGame、MusicGame、PuzzleGame、RacingGame、RolePlayingGame、SimulationGame、SportsGame、StrategyGame、TriviaGame、WordGame、GraphicsAndDesign、HealthcareAndFitness、Lifestyle、Medical、Music、News、Photography、Productivity、Reference、SocialNetworking、Sports、Travel、Utility、Video、Weather。

string | null

與您的應用程式關聯的版權字串。

createUpdaterArtifacts

更新器

是否產生更新器及其簽名

externalBin

string[] | null

要與您的應用程式一起嵌入的二進制檔案的路徑列表,可以是絕對路徑或相對路徑。

請注意,Tauri 將按照模式 “binary-name{-target-triple}{.system-extension}” 尋找系統特定的二進制檔案。

例如,對於外部二進制檔案 “my-binary”,Tauri 會尋找

  • Windows 的 “my-binary-x86_64-pc-windows-msvc.exe”
  • macOS 的 “my-binary-x86_64-apple-darwin”
  • Linux 的 “my-binary-x86_64-unknown-linux-gnu”

因此,別忘了為所有目標平台提供二進制檔案。

fileAssociations

FileAssociation[] | null

應用程式的檔案關聯。

homepage

string | null

您的應用程式首頁的 URL。如果未設定,將回退到 Cargo.toml 中定義的 homepage

支援的捆綁目標:debrpmnsismsi

icon

string[]

應用程式的圖示

預設值[]

iOS

IosConfig

iOS 設定。

預設值
{
"minimumSystemVersion": "13.0"
}
license

string | null

要包含在適當捆綁包中的套件授權識別符。如果未設定,則預設為 Cargo.toml 檔案中的授權。

licenseFile

string | null

要包含在適當捆綁包中的授權檔案路徑。

linux

LinuxConfig

Linux 捆綁包的設定。

預設值
{
"appimage": {
"bundleMediaFramework": false,
"files": {}
},
"deb": {
"files": {}
},
"rpm": {
"epoch": 0,
"files": {},
"release": "1"
}
}
longDescription

string | null

應用程式的較長、多行描述。

macOS

MacConfig

macOS 捆綁包的設定。

預設值
{
"dmg": {
"appPosition": {
"x": 180,
"y": 170
},
"applicationFolderPosition": {
"x": 480,
"y": 170
},
"windowSize": {
"height": 400,
"width": 660
}
},
"files": {},
"hardenedRuntime": true,
"minimumSystemVersion": "10.13"
}
publisher

string | null

應用程式的發布者。預設為識別符字串中的第二個元素。

目前映射到 Windows 安裝程式的 Manufacturer 屬性和 debian 套件的 Maintainer 欄位(如果 Cargo.toml 沒有 authors 欄位)。

resources

BundleResources | null

要捆綁的應用程式資源。每個資源都是檔案或目錄的路徑。支援 Glob 模式。

shortDescription

string | null

您的應用程式的簡短描述。

targets

BundleTarget

捆綁目標,目前支援 [“deb”, “rpm”, “appimage”, “nsis”, “msi”, “app”, “dmg”] 或 “all”。

預設值"all"

useLocalToolsDir

boolean

在建置此應用程式時,是否使用專案的 target 目錄來快取建置工具(例如 Wix 和 NSIS)。預設為 false

如果為 true,工具將快取在 target/.tauri/ 中。如果為 false,工具將快取在當前使用者的平台特定快取目錄中。

將此設定為 true 可能合適的一個範例是在以 Windows 系統使用者(例如 AWS EC2 工作負載)身分建置此應用程式時,因為 Windows 系統的應用程式資料目錄受到限制。

windows

WindowsConfig

Windows 捆綁包的設定。

預設值
{
"allowDowngrades": true,
"certificateThumbprint": null,
"digestAlgorithm": null,
"nsis": null,
"signCommand": null,
"timestampUrl": null,
"tsp": false,
"webviewInstallMode": {
"silent": true,
"type": "downloadBootstrapper"
},
"wix": null
}

BundleResources

以下任何一項:

  • string[] 要包含的路徑列表。
  • 從來源到目標路徑的映射。允許額外屬性string

捆綁資源的定義。可以是包含路徑的列表,也可以是從來源到目標路徑的映射。

BundleTarget

以下任何一項:

要捆綁的目標。每個值都不區分大小寫。

BundleType

以下其中一項:

  • "deb" debian 捆綁包 (.deb)。
  • "rpm" RPM 捆綁包 (.rpm)。
  • "appimage" AppImage 捆綁包 (.appimage)。
  • "msi" Microsoft Installer 捆綁包 (.msi)。
  • "nsis" NSIS 捆綁包 (.exe)。
  • "app" macOS 應用程式捆綁包 (.app)。
  • "dmg" Apple Disk Image 捆綁包 (.dmg)。

tauri-bundler 引用的捆綁包。

BundleTypeRole

以下其中一項:

  • "Editor" CFBundleTypeRole.Editor。檔案可以讀取和編輯。
  • "Viewer" CFBundleTypeRole.Viewer。檔案可以讀取。
  • "Shell" CFBundleTypeRole.Shell
  • "QLGenerator" CFBundleTypeRole.QLGenerator
  • "None" CFBundleTypeRole.None

僅限 macOS。對應於 CFBundleTypeRole

能力

開發人員可以用於隔離 IPC 層存取權的分組和邊界機制。

它控制應用程式視窗對 Tauri 核心、應用程式或外掛程式命令的精細存取權。如果視窗與任何功能都不匹配,則它完全沒有權限存取 IPC 層。

這樣做可以建立視窗組,根據它們所需的系統存取權限,這可以減少權限較低的視窗中前端漏洞的影響。可以透過精確名稱(例如 main-window)或 glob 模式(如 *admin-*)將視窗新增到功能中。一個視窗可以沒有、有一個或多個關聯的功能。

範例
{
"identifier": "main-user-files-write",
"description": "This capability allows the `main` window on macOS and Windows access to `filesystem` write related commands and `dialog` commands to enable programatic access to files selected by the user.",
"windows": [
"main"
],
"permissions": [
"core:default",
"dialog:open",
{
"identifier": "fs:allow-write-text-file",
"allow": [{ "path": "$HOME/test.txt" }]
},
],
"platforms": ["macOS","windows"]
}

物件屬性:

  • description
  • identifier (必填)
  • local
  • permissions (必填)
  • platforms
  • remote
  • webviews
  • windows
description

string

功能旨在允許關聯視窗的功能描述。

它應包含分組權限應允許的功能描述。

範例

此功能允許 main 視窗存取 filesystem 寫入相關命令和 dialog 命令,以啟用對使用者選取檔案的程式化存取。

identifier

string

功能的識別符。

範例

main-user-files-write

local

boolean

此功能是否針對本機應用程式 URL 啟用。預設為 true

預設值true

permissions

PermissionEntry[] 每個項目都必須是唯一的

附加到此功能的權限列表。

必須包含外掛程式名稱作為前綴,格式為 ${plugin-name}:${permission-name}。對於直接在應用程式本身中實作的命令,僅需要 ${permission-name}

範例
[
"core:default",
"shell:allow-open",
"dialog:open",
{
"identifier": "fs:allow-write-text-file",
"allow": [{ "path": "$HOME/test.txt" }]
}
]
platforms

Target[] | null

限制此功能適用的目標平台。

預設情況下,所有平台都是目標平台。

範例

["macOS","windows"]

remote

CapabilityRemote | null

設定可以使用功能權限的遠端 URL。

此設定是可選的,預設為未設定,因為我們的預設用例是內容從我們的本機應用程式提供。

範例
{
"urls": ["https://*.mydomain.dev"]
}
webviews

string[]

受此功能影響的 webview 列表。可以是 glob 模式。

這僅在使用多個 webview 環境時才需要,預設情況下,與 [Self::windows] 匹配的視窗的所有子 webview 都會連結。

範例

["sub-webview-one", "sub-webview-two"]

windows

string[]

受此功能影響的視窗列表。可以是 glob 模式。

在多個 webview 視窗上,首選 [Self::webviews] 以進行精細的存取控制。

範例

["main"]

CapabilityEntry

以下任何一項:

  • Capability 內聯功能。
  • string 參考功能識別符。

功能條目,可以是內聯功能,也可以是對在其自身檔案中定義的功能的參考。

CapabilityRemote

與功能關聯的遠端 URL 設定。

物件屬性:

  • urls (必填)
urls

string[]

此功能參考使用 URLPattern 標準 的遠端網域。

範例
  • “https://*.mydomain.dev”:允許 mydomain.dev 的子網域
  • https://mydomain.dev/api/*”:允許 mydomain.dev/api 的任何子路徑

Color

以下任何一項:

  • string 符合 ^#?([A-Fa-f0-9]{3}|[A-Fa-f0-9]{6}|[A-Fa-f0-9]{8})$ 模式的顏色十六進位字串,例如:#fff、#ffffff 或 #ffffffff。
  • integer 格式為 uint8 | integer 格式為 uint8 | integer 格式為 uint8[] 最大 3 個項目,最小 3 個項目 RGB 顏色陣列。每個值最小值為 0,最大值為 255。
  • integer 格式為 uint8 | integer 格式為 uint8 | integer 格式為 uint8 | integer 格式為 uint8[] 最大 4 個項目,最小 4 個項目 RGBA 顏色陣列。每個值最小值為 0,最大值為 255。
  • 紅色、綠色、藍色、Alpha 色彩值的物件。每個值最小值為 0,最大值為 255。 物件屬性: - alpha - blue (required) - green (required) - red (required) ##### alpha integer 格式為 uint8 預設值255 ##### blue integer 格式為 uint8 ##### green integer 格式為 uint8 ##### red integer 格式為 uint8

Csp

以下任何一項:

  • string 單一文字字串形式的完整 CSP 策略。
  • 一個物件,將指令對應到其來源值,以字串列表形式呈現。 允許額外屬性CspDirectiveSources

內容安全策略定義。請參閱 <https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP>。

CspDirectiveSources

以下任何一項:

  • string CSP 來源的行內列表。與 [Self::List] 相同,但以空格分隔符號串連。
  • string[] CSP 來源的列表。此集合將以空格分隔符號串連,形成 CSP 字串。

內容安全策略指令來源列表。請參閱 <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/Sources#sources>。

CustomSignCommandConfig

以下任何一項:

  • string 要執行的腳本的字串表示法。「%1」將被替換為要簽署的二進制檔案路徑。這是命令的更簡潔表示法。Tauri 將使用空格 ' ' 分割字串,並使用第一個元素作為命令名稱,其餘作為參數。如果您需要在命令或參數中使用空格,請使用物件表示法 [Self::ScriptWithOptions]。
  • 命令的物件表示法。這是命令的更複雜表示法,但允許您在命令和參數中使用空格。 物件屬性: - args (required) - cmd (required) ##### args string[] 傳遞給命令的參數。「%1」將被替換為要簽署的二進制檔案路徑。 ##### cmd string 要執行以簽署二進制檔案的命令。

自訂簽署命令設定。

DebConfig

Debian (.deb) 捆綁包的設定。

更多資訊請參閱: <https://v2.tauri.app/reference/config/#debconfig>

物件屬性:

  • changelog
  • conflicts
  • depends
  • desktopTemplate
  • files
  • postInstallScript
  • postRemoveScript
  • preInstallScript
  • preRemoveScript
  • priority
  • provides
  • recommends
  • replaces
  • section
changelog

string | null

未壓縮的 Changelog 檔案路徑,將儲存在 /usr/share/doc/package-name/changelog.gz。請參閱 <https://www.debian.org/doc/debian-policy/ch-docs.html#changelog-files-and-release-notes>

conflicts

string[] | null

套件衝突列表。

depends

string[] | null

您的應用程式依賴的 deb 相依性列表。

desktopTemplate

string | null

自訂 desktop 檔案 Handlebars 模板的路徑。

可用變數: categoriescomment (選用)、 execiconname

files

要包含在套件中的檔案。

允許額外屬性string

預設值{}

postInstallScript

string | null

將在套件解壓縮後執行的腳本路徑。請參閱 <https://www.debian.org/doc/debian-policy/ch-maintainerscripts.html>

postRemoveScript

string | null

將在套件移除後執行的腳本路徑。請參閱 <https://www.debian.org/doc/debian-policy/ch-maintainerscripts.html>

preInstallScript

string | null

將在套件解壓縮前執行的腳本路徑。請參閱 <https://www.debian.org/doc/debian-policy/ch-maintainerscripts.html>

preRemoveScript

string | null

將在套件移除前執行的腳本路徑。請參閱 <https://www.debian.org/doc/debian-policy/ch-maintainerscripts.html>

priority

string | null

變更 Debian 套件的優先順序。預設情況下,設定為 optional。目前可辨識的優先順序為: requiredimportantstandardoptionalextra

provides

string[] | null

套件提供的相依性列表。

recommends

string[] | null

您的應用程式建議的 deb 相依性列表。

replaces

string[] | null

套件取代列表。

section

string | null

定義 Debian Control 檔案中的 section。請參閱: https://www.debian.org/doc/debian-policy/ch-archive.html#s-subsections

DisabledCspModificationKind

以下任何一項:

  • boolean 若為 true,則停用所有 CSP 修改。false 為預設值,並設定 Tauri 控制 CSP。
  • string[] 停用給定 CSP 指令修改列表。

dangerous_disable_asset_csp_modification 設定選項的可能值。

DmgConfig

Apple 磁碟映像檔 (.dmg) 捆綁包的設定。

更多資訊請參閱: <https://v2.tauri.app/reference/config/#dmgconfig>

物件屬性:

  • applicationFolderPosition
  • appPosition
  • background
  • windowPosition
  • windowSize
applicationFolderPosition

Position

應用程式資料夾在視窗上的位置。

預設值
{
"x": 480,
"y": 170
}
appPosition

Position

應用程式檔案在視窗上的位置。

預設值
{
"x": 180,
"y": 170
}
background

string | null

用作 dmg 檔案背景的圖片。接受的格式: png/jpg/gif

windowPosition

Position | null

磁碟區視窗在螢幕上的位置。

windowSize

Size

磁碟區視窗的大小。

預設值
{
"height": 400,
"width": 660
}

FileAssociation

檔案關聯

物件屬性:

  • description
  • ext (required)
  • mimeType
  • name
  • role
description

string | null

關聯描述。僅限 Windows。它顯示在 Windows 檔案總管的「類型」欄位中。

ext

AssociationExt[]

要與此應用程式關聯的檔案擴展名。例如 'png'

mimeType

string | null

MIME 類型,例如 'image/png' 或 'text/plain'。僅限 Linux。

name

string | null

名稱。對應到 macOS 上的 CFBundleTypeName。預設為 ext[0]

role

BundleTypeRole

應用程式在類型方面的角色。對應到 macOS 上的 CFBundleTypeRole

預設值"Editor"

FrontendDist

以下任何一項:

  • string 格式為 uri 應作為預設應用程式 URL 使用的外部 URL。
  • string 包含前端 dist 資產的目錄路徑。
  • string[] 要嵌入到應用程式中的檔案陣列。

定義要嵌入在應用程式中的 URL 或資產。

FsScope

以下任何一項:

  • string[] 此範圍允許的路徑列表。
  • 完整的範圍設定。 物件屬性: - allow - deny - requireLiteralLeadingDot ##### allow string[] 此範圍允許的路徑列表。 預設值[] ##### deny string[] 此範圍不允許的路徑列表。這優先於 [Self::Scope::allow] 列表。 預設值[] ##### requireLiteralLeadingDot boolean | null 是否包含以 . 開頭的元件的路徑將需要 . 實際出現在模式中;*?**[...] 將不匹配。這很有用,因為此類檔案在 Unix 系統上通常被視為隱藏檔案,並且在列出檔案時可能需要跳過它們。在 Unix 系統上預設為 true,在 Windows 上預設為 false

協定範圍定義。它是一個 glob 模式列表,用於限制從 webview 存取 API。

每個模式都可以以變數開頭,該變數解析為系統基本目錄。變數包括: $AUDIO$CACHE$CONFIG$DATA$LOCALDATA$DESKTOP$DOCUMENT$DOWNLOAD$EXE$FONT$HOME$PICTURE$PUBLIC$RUNTIME$TEMPLATE$VIDEO$RESOURCE$APP$LOG$TEMP$APPCONFIG$APPDATA$APPLOCALDATA$APPCACHE$APPLOG

HeaderConfig

一個結構,其中鍵是一些特定的 http 標頭名稱。如果定義了這些鍵的值,則它們將作為響應訊息的一部分發送。這不包括錯誤訊息和 ipc 訊息

範例設定
{
//..
app:{
//..
security: {
headers: {
"Cross-Origin-Opener-Policy": "same-origin",
"Cross-Origin-Embedder-Policy": "require-corp",
"Timing-Allow-Origin": [
"https://developer.mozilla.org",
"https://example.com",
],
"Access-Control-Expose-Headers": "Tauri-Custom-Header",
"Tauri-Custom-Header": {
"key1": "'value1' 'value2'",
"key2": "'value3'"
}
},
csp: "default-src 'self'; connect-src ipc: http://ipc.localhost",
}
//..
}
//..
}

在此範例中,Cross-Origin-Opener-PolicyCross-Origin-Embedder-Policy 設定為允許使用 SharedArrayBuffer。結果是,這些標頭隨後會在 crates/tauri/src/protocol/tauri.rs 中的 get_response 函數發送的每個響應中設定。Content-Security-Policy 標頭是單獨定義的,因為它也是單獨處理的。

對於 helloworld 範例,此設定轉換為這些響應標頭

access-control-allow-origin: http://tauri.localhost
access-control-expose-headers: Tauri-Custom-Header
content-security-policy: default-src 'self'; connect-src ipc: http://ipc.localhost; script-src 'self' 'sha256-Wjjrs6qinmnr+tOry8x8PPwI77eGpUFR3EEGZktjJNs='
content-type: text/html
cross-origin-embedder-policy: require-corp
cross-origin-opener-policy: same-origin
tauri-custom-header: key1 'value1' 'value2'; key2 'value3'
timing-allow-origin: https://developer.mozilla.org, https://example.com

由於產生的標頭值始終是「類字串」。因此,根據 HeaderSource 的資料類型,它們需要轉換。

  • String(JS/Rust):對於產生的標頭值保持不變
  • Array(JS)/Vec\&lt;String\&gt;(Rust):項目以 ”, ” 連接,作為產生的標頭值
  • Object(JS)/ Hashmap\&lt;String,String\&gt;(Rust):項目由:鍵 + 空格 + 值組成。項目然後以 ”; ” 連接,作為產生的標頭值 允許額外屬性string

物件屬性:

  • Access-Control-Allow-Credentials
  • Access-Control-Allow-Headers
  • Access-Control-Allow-Methods
  • Access-Control-Expose-Headers
  • Access-Control-Max-Age
  • Cross-Origin-Embedder-Policy
  • Cross-Origin-Opener-Policy
  • Cross-Origin-Resource-Policy
  • Permissions-Policy
  • Tauri-Custom-Header
  • Timing-Allow-Origin
  • X-Content-Type-Options
Access-Control-Allow-Credentials

HeaderSource | null

Access-Control-Allow-Credentials 響應標頭告知瀏覽器伺服器是否允許跨來源 HTTP 請求包含憑證。

請參閱 <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Allow-Credentials>

Access-Control-Allow-Headers

HeaderSource | null

Access-Control-Allow-Headers 響應標頭用於響應包含 Access-Control-Request-Headers 的預檢請求,以指示在實際請求期間可以使用哪些 HTTP 標頭。

如果請求具有 Access-Control-Request-Headers 標頭,則此標頭是必需的。

請參閱 <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Allow-Headers>

Access-Control-Allow-Methods

HeaderSource | null

Access-Control-Allow-Methods 響應標頭指定在響應預檢請求時,存取資源時允許的一種或多種方法。

請參閱 <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Allow-Methods>

Access-Control-Expose-Headers

HeaderSource | null

Access-Control-Expose-Headers 響應標頭允許伺服器指示應將哪些響應標頭提供給在瀏覽器中運行的腳本,以響應跨來源請求。

請參閱 <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Expose-Headers>

Access-Control-Max-Age

HeaderSource | null

Access-Control-Max-Age 響應標頭指示可以快取預檢請求結果(即 Access-Control-Allow-Methods 和 Access-Control-Allow-Headers 標頭中包含的資訊)多長時間。

請參閱 <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Max-Age>

Cross-Origin-Embedder-Policy

HeaderSource | null

HTTP Cross-Origin-Embedder-Policy (COEP) 響應標頭設定將跨來源資源嵌入到文件中。

請參閱 <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cross-Origin-Embedder-Policy>

Cross-Origin-Opener-Policy

HeaderSource | null

HTTP Cross-Origin-Opener-Policy (COOP) 響應標頭允許您確保頂層文件不與跨來源文件共享瀏覽上下文組。COOP 將進程隔離您的文件,潛在的攻擊者如果以彈出視窗打開您的文件,則無法存取您的全域物件,從而防止一組稱為 XS-Leaks 的跨來源攻擊。

請參閱 <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cross-Origin-Opener-Policy>

Cross-Origin-Resource-Policy

HeaderSource | null

HTTP Cross-Origin-Resource-Policy 響應標頭傳達了瀏覽器阻止對給定資源的無 CORS 跨來源/跨站點請求的意願。

請參閱 <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cross-Origin-Resource-Policy>

Permissions-Policy

HeaderSource | null

HTTP Permissions-Policy 標頭提供了一種機制,允許和拒絕在文件或文件中的任何 &lt;iframe&gt; 元素中使用瀏覽器功能。

請參閱 <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Permissions-Policy>

Tauri-Custom-Header

HeaderSource | null

自訂標頭欄位 Tauri-Custom-Header,請勿使用它。請記得相應地設定 Access-Control-Expose-Headers

不適用於生產環境

Timing-Allow-Origin

HeaderSource | null

Timing-Allow-Origin 響應標頭指定允許查看透過 Resource Timing API 功能檢索的屬性值的來源,否則由於跨來源限制,這些屬性值將報告為零。

請參閱 <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Timing-Allow-Origin>

X-Content-Type-Options

HeaderSource | null

X-Content-Type-Options 響應 HTTP 標頭是伺服器使用的標記,用於指示應遵循 Content-Type 標頭中宣告的 MIME 類型,而不應更改。此標頭允許您透過聲明 MIME 類型是經過刻意配置的來避免 MIME 類型嗅探。

請參閱 <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Content-Type-Options>

HeaderSource

以下任何一項:

  • string 標頭值的字串版本
  • string[] 標頭值的列表版本。項目以 ”, ” 連接,作為實際的標頭值
  • (Rust struct | Json | JavaScript Object) 標頭值的等效項。項目由:鍵 + 空格 + 值組成。項目然後以 ”;” 連接,作為實際的標頭值 允許額外屬性string

標頭來源的定義

標頭名稱的標頭值

HookCommand

以下任何一項:

  • string 使用預設選項執行給定的腳本。
  • 使用自訂選項執行給定的腳本。 物件屬性: - cwd - script (required) ##### cwd string | null 目前的工作目錄。 ##### script string 要執行的腳本。

描述在觸發 CLI hook 時要執行的 shell 命令。

Identifier

string

IosConfig

iOS 目標的一般設定。

物件屬性:

  • developmentTeam
  • frameworks
  • minimumSystemVersion
  • template
developmentTeam

string | null

開發團隊。此值是 iOS 開發的必要條件,因為強制執行程式碼簽署。APPLE_DEVELOPMENT_TEAM 環境變數可以設定為覆寫它。

frameworks

string[] | null

指示任何需要與應用程式捆綁在一起的 iOS framework 的字串列表。

請注意,您需要重新建立 iOS 專案才能套用變更。

minimumSystemVersion

string

指示捆綁應用程式支援的最低 iOS 版本的版本字串。預設為 13.0

對應到 IPHONEOS_DEPLOYMENT_TARGET 值。

預設值"13.0"

template

string | null

要使用的自訂 XcodeGen project.yml 模板。

LinuxConfig

Linux 捆綁包的設定。

更多資訊請參閱: <https://v2.tauri.app/reference/config/#linuxconfig>

物件屬性:

  • appimage
  • deb
  • rpm
appimage

AppImageConfig

AppImage 捆綁包的設定。

預設值
{
"bundleMediaFramework": false,
"files": {}
}
deb

DebConfig

Debian 捆綁包的設定。

預設值
{
"files": {}
}
rpm

RpmConfig

RPM 捆綁包的設定。

預設值
{
"epoch": 0,
"files": {},
"release": "1"
}

MacConfig

macOS 捆綁包的設定。

更多資訊請參閱: <https://v2.tauri.app/reference/config/#macconfig>

物件屬性:

  • dmg
  • entitlements
  • exceptionDomain
  • files
  • frameworks
  • hardenedRuntime
  • minimumSystemVersion
  • providerShortName
  • signingIdentity
dmg

DmgConfig

DMG 特定設定。

預設值
{
"appPosition": {
"x": 180,
"y": 170
},
"applicationFolderPosition": {
"x": 480,
"y": 170
},
"windowSize": {
"height": 400,
"width": 660
}
}
entitlements

string | null

entitlements 檔案的路徑。

exceptionDomain

string | null

允許您的應用程式與外部世界通訊。它應該是小寫,不帶埠號和協定的網域名稱。

files

要包含在應用程式中的檔案,相對於 Contents 目錄。

允許額外屬性string

預設值{}

frameworks

string[] | null

指示任何需要與應用程式捆綁在一起的 macOS X framework 的字串列表。

如果使用名稱,則必須省略 “.framework”,它將在標準安裝位置尋找。您也可以使用特定 framework 的路徑。

hardenedRuntime

boolean

程式碼簽署是否應啟用 hardened runtime(針對可執行檔)。

預設值true

minimumSystemVersion

string | null

指示捆綁應用程式支援的最低 macOS X 版本的版本字串。預設為 10.13

將其設定為 null 會完全移除捆綁包 Info.plist 上的 LSMinimumSystemVersion 欄位和 MACOSX_DEPLOYMENT_TARGET 環境變數。

空字串被視為無效值,因此使用預設值。

預設值"10.13"

providerShortName

string | null

用於公證的供應商簡短名稱。

signingIdentity

string | null

用於程式碼簽署的身分。

NsisCompression

以下其中一項:

  • "zlib" ZLIB 使用 deflate 演算法,這是一種快速而簡單的方法。使用預設壓縮級別,它大約使用 300 KB 的記憶體。
  • "bzip2" BZIP2 通常提供比 ZLIB 更好的壓縮比,但它速度稍慢且使用更多記憶體。使用預設壓縮級別,它大約使用 4 MB 的記憶體。
  • "lzma" LZMA(預設)是一種新的壓縮方法,可提供非常好的壓縮比。解壓縮速度很快(在 2 GHz CPU 上為 10-20 MB/s),壓縮速度較慢。將用於解壓縮的記憶體大小是字典大小加上幾 KB,預設為 8 MB。
  • "none" 停用壓縮

NSIS 安裝程式中使用的壓縮演算法。

請參閱 <https://nsis.sourceforge.io/Reference/SetCompressor>

NsisConfig

使用 NSIS 的安裝程式捆綁包的設定。

物件屬性:

  • compression
  • customLanguageFiles
  • displayLanguageSelector
  • headerImage
  • installerHooks
  • installerIcon
  • installMode
  • languages
  • minimumWebview2Version
  • sidebarImage
  • startMenuFolder
  • template
compression

NsisCompression

設定用於壓縮安裝程式中檔案的壓縮演算法。

請參閱 <https://nsis.sourceforge.io/Reference/SetCompressor>

預設值"lzma"

customLanguageFiles

| null

鍵值對,其中鍵是語言,值是自訂 .nsh 檔案的路徑,該檔案保存 tauri 自訂訊息的翻譯文字。

請參閱 <https://github.com/tauri-apps/tauri/blob/dev/crates/tauri-bundler/src/bundle/windows/nsis/languages/English.nsh> 以取得 .nsh 檔案範例。

注意:鍵必須是有效的 NSIS 語言,並且必須添加到 [NsisConfig] languages 陣列中,

允許額外屬性string

displayLanguageSelector

boolean

是否在安裝程式和解除安裝程式視窗呈現之前顯示語言選擇器對話方塊。預設情況下,會選取作業系統語言,並回退到 languages 陣列中的第一種語言。

headerImage

string | null

要在安裝程式頁面標頭上顯示的點陣圖檔案路徑。

建議尺寸為 150 像素 x 57 像素。

installerHooks

string | null

包含要掛鉤到主要 installer.nsi 腳本中的特殊 NSIS 巨集的 .nsh 檔案路徑。

支援的 hooks 有

  • NSIS_HOOK_PREINSTALL:此 hook 在複製檔案、設定登錄機碼值和建立捷徑之前執行。
  • NSIS_HOOK_POSTINSTALL:此 hook 在安裝程式完成複製所有檔案、設定登錄機碼和建立捷徑之後執行。
  • NSIS_HOOK_PREUNINSTALL:此 hook 在移除任何檔案、登錄機碼和捷徑之前執行。
  • NSIS_HOOK_POSTUNINSTALL:此 hook 在檔案、登錄機碼和捷徑移除之後執行。
範例
!macro NSIS_HOOK_PREINSTALL
MessageBox MB_OK "PreInstall"
!macroend
!macro NSIS_HOOK_POSTINSTALL
MessageBox MB_OK "PostInstall"
!macroend
!macro NSIS_HOOK_PREUNINSTALL
MessageBox MB_OK "PreUnInstall"
!macroend
!macro NSIS_HOOK_POSTUNINSTALL
MessageBox MB_OK "PostUninstall"
!macroend
installerIcon

string | null

用作安裝程式圖示的圖示檔案路徑。

installMode

NSISInstallerMode

安裝將適用於所有使用者還是僅適用於目前使用者。

預設值"currentUser"

languages

string[] | null

安裝程式語言列表。預設情況下使用作業系統語言。如果作業系統語言不在語言列表中,則將使用第一種語言。若要允許使用者選取語言,請將 display_language_selector 設定為 true

請參閱 <https://github.com/kichik/nsis/tree/9465c08046f00ccb6eda985abbdbf52c275c6c4d/Contrib/Language%20files> 以取得完整的語言列表。

minimumWebview2Version

string | null

嘗試確保 WebView2 版本等於或新於此版本,如果使用者的 WebView2 版本舊於此版本,安裝程式將嘗試觸發 WebView2 更新。

sidebarImage

string | null

用於歡迎頁面和完成頁面的點陣圖檔案路徑。

建議尺寸為 164 像素 x 314 像素。

startMenuFolder

string | null

設定開始功能表捷徑的資料夾名稱。

如果您有多個應用程式並希望將其捷徑分組在一個資料夾下,或者如果您通常希望將捷徑設定在資料夾內,請使用此選項。

範例

  • AwesomePublisher,捷徑將放置在 %AppData%\Microsoft\Windows\Start Menu\Programs\AwesomePublisher\&lt;your-app&gt;.lnk
  • 如果未設定,捷徑將放置在 %AppData%\Microsoft\Windows\Start Menu\Programs\&lt;your-app&gt;.lnk
template

string | null

要使用的自訂 .nsi 模板。

NSISInstallerMode

以下其中一項:

  • "currentUser" 安裝程式的預設模式。預設情況下,將應用程式安裝在不需要管理員權限的目錄中。安裝程式中繼資料將儲存在 HKCU 登錄路徑下。
  • "perMachine" 預設情況下,將應用程式安裝在 Program Files 資料夾目錄中,安裝需要管理員權限。安裝程式中繼資料將儲存在 HKLM 登錄路徑下。
  • "both" 結合了兩種模式,並允許使用者在安裝時選擇是為目前使用者安裝還是為每台機器安裝。請注意,即使使用者只想為目前使用者安裝,此模式也需要管理員權限。安裝程式中繼資料將根據使用者的選擇儲存在 HKLMHKCU 登錄路徑下。

NSIS 安裝程式的安裝模式。

Number

以下任何一項:

  • integer 格式為 int64 表示 [i64]。
  • number 格式為 double 表示 [f64]。

有效的 ACL 數字。

PatternKind

以下其中一項:

  • Brownfield 模式。 物件屬性: - use (required) ##### use "brownfield"
  • 隔離模式。建議用於安全目的。 物件屬性: - options (required) - use (required) ##### options 物件屬性: - dir (required) ###### dir string 包含 index.html 檔案的目錄,該檔案包含安全隔離應用程式。 ##### use "isolation"

應用程式模式。

PermissionEntry

以下任何一項:

  • Identifier 依據識別碼參考權限或權限集。
  • 依據識別碼參考權限或權限集,並擴展其範圍。 物件屬性: - allow - deny - identifier (required) ##### allow Value[] | null 定義範圍允許的資料。 ##### deny Value[] | null 定義範圍拒絕的資料。驗證邏輯應優先考慮此項。 ##### identifier Identifier 權限或權限集的識別碼。

[Capability] 中的權限值項目可以是原始權限 [Identifier] 或參考權限並擴展其範圍的物件。

PluginConfig

plugin configs 保留一個 HashMap,將外掛程式名稱對應到其設定物件。

更多資訊請參閱: <https://v2.tauri.app/reference/config/#pluginconfig>

允許額外屬性true

Position

位置座標結構。

物件屬性:

  • x (required)
  • y (required)
x

integer 格式為 uint32

X 座標。

y

integer 格式為 uint32

Y 座標。

RpmCompression

以下其中一項:

  • Gzip 壓縮 物件屬性: - level (required) - type (required) ##### level integer 格式為 uint32 Gzip 壓縮級別 ##### type "gzip"
  • Zstd 壓縮 物件屬性: - level (required) - type (required) ##### level integer 格式為 int32 Zstd 壓縮級別 ##### type "zstd"
  • Xz 壓縮 物件屬性: - level (required) - type (required) ##### level integer 格式為 uint32 Xz 壓縮級別 ##### type "xz"
  • Bzip2 壓縮 物件屬性: - level (required) - type (required) ##### level integer 格式為 uint32 Bzip2 壓縮級別 ##### type "bzip2"
  • 停用壓縮 物件屬性: - type (required) ##### type "none"

捆綁 RPM 套件時使用的壓縮演算法。

RpmConfig

RPM 捆綁包的設定。

物件屬性:

  • compression
  • conflicts
  • depends
  • desktopTemplate
  • epoch
  • files
  • obsoletes
  • postInstallScript
  • postRemoveScript
  • preInstallScript
  • preRemoveScript
  • provides
  • recommends
  • release
compression

RpmCompression | null

壓縮演算法和級別。預設為級別 6 的 Gzip

conflicts

string[] | null

您的應用程式衝突的 RPM 相依性列表。為了安裝套件,它們不能存在。

depends

string[] | null

您的應用程式依賴的 RPM 相依性列表。

desktopTemplate

string | null

自訂 desktop 檔案 Handlebars 模板的路徑。

可用變數: categoriescomment (選用)、 execiconname

epoch

integer 格式為 uint32

RPM epoch。

files

要包含在套件中的檔案。

允許額外屬性string

預設值{}

obsoletes

string[] | null

您的應用程式取代的 RPM 相依性列表 - 如果安裝了此套件,則會自動移除列為「obsoletes」的套件(如果它們存在)。

postInstallScript

string | null

將在套件解壓縮後執行的腳本路徑。請參閱 <http://ftp.rpm.org/max-rpm/s1-rpm-inside-scripts.html>

postRemoveScript

string | null

將在套件移除後執行的腳本路徑。請參閱 <http://ftp.rpm.org/max-rpm/s1-rpm-inside-scripts.html>

preInstallScript

string | null

將在套件解壓縮前執行的腳本路徑。請參閱 <http://ftp.rpm.org/max-rpm/s1-rpm-inside-scripts.html>

preRemoveScript

string | null

將在套件移除前執行的腳本路徑。請參閱 <http://ftp.rpm.org/max-rpm/s1-rpm-inside-scripts.html>

provides

string[] | null

您的應用程式提供的 RPM 相依性列表。

recommends

string[] | null

您的應用程式建議的 RPM 相依性列表。

release

string

RPM 發行標籤。

預設值"1"

SecurityConfig

安全性設定。

更多資訊請參閱: <https://v2.tauri.app/reference/config/#securityconfig>

物件屬性:

  • assetProtocol
  • capabilities
  • csp
  • dangerousDisableAssetCspModification
  • devCsp
  • freezePrototype
  • headers
  • pattern
assetProtocol

AssetProtocolConfig

自訂協定設定。

預設值
{
"enable": false,
"scope": []
}
capabilities

CapabilityEntry[]

應用程式上啟用的功能列表。

如果列表為空,則包含所有功能。

預設值[]

csp

Csp | null

將注入到建置應用程式上所有 HTML 檔案中的內容安全策略。如果未指定 dev_csp,則此值也會注入到開發環境中。

這是設定中非常重要的一部分,因為它可以幫助您確保 WebView 的安全性。請參閱 <https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP>。

dangerousDisableAssetCspModification

DisabledCspModificationKind

停用 Tauri 注入的 CSP 來源。

在編譯時,Tauri 會解析所有前端資產,並變更內容安全策略,僅允許透過注入 nonce 和雜湊來源來載入您自己的腳本和樣式。這會限制您的 CSP,這可能會在使用其他彈性來源時引入問題。

此設定選項允許布林值和字串列表作為值。布林值指示 Tauri 停用所有 CSP 注入的注入,字串列表指示 Tauri 無法注入的 CSP 指令。

警告: 僅在您知道自己在做什麼並且已正確設定 CSP 的情況下停用此功能。如果沒有此 Tauri 保護,您的應用程式可能會容易受到 XSS 攻擊。

devCsp

Csp | null

將注入到開發環境上所有 HTML 檔案中的內容安全策略。

這是設定中非常重要的一部分,因為它可以幫助您確保 WebView 的安全性。請參閱 <https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP>。

freezePrototype

boolean

在使用自訂協定時凍結 Object.prototype

headers

HeaderConfig | null

標頭,這些標頭會新增到從 tauri 到 web view 的每個 http 響應中。這不包括 IPC 訊息和錯誤響應

pattern

PatternKind

要使用的模式。

預設值
{
"use": "brownfield"
}

Size

視窗的大小。

物件屬性:

  • height (required)
  • width (required)
height

integer 格式為 uint32

視窗的高度。

width

integer 格式為 uint32

視窗的寬度。

Target

以下其中一項:

  • "macOS" MacOS。
  • "windows" Windows。
  • "linux" Linux。
  • "android" Android。
  • "iOS" iOS。

平台目標。

Theme

以下其中一項:

  • "Light" 淺色主題。
  • "Dark" 深色主題。

系統主題。

TitleBarStyle

以下其中一項:

  • "Visible" 一般標題列。
  • "Transparent" 使標題列透明,因此會顯示視窗背景顏色。如果您不需要在標題列下方有實際的 HTML,這很有用。這可讓您避免使用 TitleBarStyle::Overlay 的注意事項。當 Tauri 允許您設定自訂視窗背景顏色時,將會更有用。
  • "Overlay" 「Overlay」將標題列顯示為覆蓋於視窗內容之上的透明覆蓋層。請注意: - 標題列的高度在不同的作業系統版本上有所不同,這可能導致視窗控制項和標題不在您預期的位置。 - 您需要定義自訂拖曳區域以使您的視窗可拖曳,然而由於限制,當視窗未處於焦點時,您無法拖曳視窗 <https://github.com/tauri-apps/tauri/issues/4316>。 - 視窗標題的顏色取決於系統主題。

視窗標題列在 macOS 上應如何顯示。

TrayIconConfig

應用程式系統匣圖示的設定。

參閱更多: <https://v2.tauri.app/reference/config/#trayiconconfig>

物件屬性:

  • iconAsTemplate
  • iconPath (必填)
  • id
  • menuOnLeftClick
  • showMenuOnLeftClick
  • title
  • tooltip
iconAsTemplate

boolean

布林值,決定影像是否代表 macOS 上的 template 影像。

iconPath

string

用於系統匣圖示的預設圖示路徑。

注意:這會將影像以原始像素儲存在最終二進位檔中,因此請保持圖示尺寸(寬度和高度)小,否則會使最終可執行檔膨脹

id

string | null

為此系統匣圖示設定 ID,以便稍後參考,預設為 main

boolean

布林值,決定當系統匣圖示收到滑鼠左鍵點擊時是否應顯示選單。

平台特定
  • Linux:不支援。

預設值true

showMenuOnLeftClick

boolean

布林值,決定當系統匣圖示收到滑鼠左鍵點擊時是否應顯示選單。

平台特定
  • Linux:不支援。

預設值true

title

string | null

MacOS 系統匣的標題

tooltip

string | null

Windows 和 macOS 上的系統匣圖示工具提示

更新器

以下任何一項:

  • V1Compatible 產生舊版壓縮 v1 相容更新器
  • boolean 是否產生更新器及其簽章

更新器類型

V1Compatible

"v1Compatible",產生舊版壓縮 v1 相容更新器

產生舊版壓縮 v1 相容更新器

Value

以下任何一項:

  • null 代表空值 JSON 值。
  • boolean 代表 [bool]。
  • Number 代表有效的 ACL [Number]。
  • string 代表 [String]。
  • Value[] 代表其他 [Value] 的列表。
  • 代表從 [String] 鍵到 [Value] 的映射。允許其他屬性Value

所有支援的 ACL 值。

WebviewInstallMode

以下其中一項:

  • 不安裝 Webview2 作為 Windows Installer 的一部分。物件屬性: - type (必填) ##### type "skip"
  • 下載啟動載入器並執行它。需要網路連線。會產生較小的安裝程式大小,但不建議在 Windows 7 上使用。物件屬性: - silent - type (必填) ##### silent boolean 指示安裝程式以靜默模式執行啟動載入器。預設為 true預設值true ##### type "downloadBootstrapper"
  • 嵌入啟動載入器並執行它。需要網路連線。安裝程式大小會增加約 1.8MB,但在 Windows 7 上提供更好的支援。物件屬性: - silent - type (必填) ##### silent boolean 指示安裝程式以靜默模式執行啟動載入器。預設為 true預設值true ##### type "embedBootstrapper"
  • 嵌入離線安裝程式並執行它。不需要網路連線。安裝程式大小會增加約 127MB。物件屬性: - silent - type (必填) ##### silent boolean 指示安裝程式以靜默模式執行安裝程式。預設為 true預設值true ##### type "offlineInstaller"
  • 嵌入固定版本的 webview2 並在執行時使用它。安裝程式大小會增加約 180MB。物件屬性: - path (必填) - type (必填) ##### path string 要使用的固定執行階段路徑。固定版本可以從 官方網站 下載。.cab 檔案必須解壓縮到資料夾,且此資料夾路徑必須在此欄位中定義。 ##### type "fixedRuntime"

Webview2 執行階段的安裝模式。請注意,對於更新器套件,使用 [Self::DownloadBootstrapper]。

如需更多資訊,請參閱 <https://v2.tauri.app/distribute/windows-installer/#webview2-installation-options>。

WebviewUrl

以下任何一項:

  • string 格式為 uri 外部 URL。必須使用 httphttps 協定。
  • string 應用程式 URL 的路徑部分。例如,若要載入 tauri://localhost/users/john,您只需在此設定中提供 users/john 即可。
  • string 格式為 uri 自訂協定 URL,例如,doom://index.html

要在 Tauri webview 視窗中開啟的 URL。

WindowConfig

視窗設定物件。

參閱更多: <https://v2.tauri.app/reference/config/#windowconfig>

物件屬性:

  • acceptFirstMouse
  • additionalBrowserArgs
  • alwaysOnBottom
  • alwaysOnTop
  • backgroundColor
  • backgroundThrottling
  • browserExtensionsEnabled
  • center
  • closable
  • contentProtected
  • create
  • decorations
  • devtools
  • dragDropEnabled
  • focus
  • fullscreen
  • height
  • hiddenTitle
  • incognito
  • label
  • maxHeight
  • maximizable
  • maximized
  • maxWidth
  • minHeight
  • minimizable
  • minWidth
  • parent
  • proxyUrl
  • resizable
  • shadow
  • skipTaskbar
  • tabbingIdentifier
  • theme
  • title
  • titleBarStyle
  • transparent
  • url
  • useHttpsScheme
  • userAgent
  • visible
  • visibleOnAllWorkspaces
  • width
  • windowClassname
  • windowEffects
  • x
  • y
  • zoomHotkeysEnabled
acceptFirstMouse

boolean

在 macOS 上,點擊非使用中視窗是否也會點擊穿透至 webview。

additionalBrowserArgs

string | null

定義 Windows 上的其他瀏覽器引數。依預設,wry 會傳遞 --disable-features=msWebOOUI,msPdfOOUI,msSmartScreenProtection,因此如果您使用此方法,您也需要自行停用這些元件(如果需要)。

alwaysOnBottom

boolean

視窗是否應始終位於其他視窗之下。

alwaysOnTop

boolean

視窗是否應始終位於其他視窗之上。

backgroundColor

Color | null

設定視窗和 webview 背景顏色。

平台特定
  • Windows:視窗圖層會忽略 alpha 通道。
  • Windows:在 Windows 7 上,webview 圖層會忽略 alpha 通道。
  • Windows:在 Windows 8 及更新版本上,如果 alpha 通道不是 0,則 webview 圖層會忽略它。
backgroundThrottling

BackgroundThrottlingPolicy | null

變更預設背景節流行為。

依預設,瀏覽器使用暫停原則,當視圖最小化或隱藏後約 5 分鐘,將節流計時器甚至卸載整個索引標籤(視圖)以釋放資源。這將暫停所有任務,直到文件可見性狀態從隱藏變回可見,方法是將視圖帶回前景。

平台特定
  • Linux / Windows / Android:不支援。類似待處理 WebLock 交易的解決方案可能就足夠了。
  • iOS:自 17.0+ 版本起支援。
  • macOS:自 14.0+ 版本起支援。

請參閱 https://github.com/tauri-apps/tauri/issues/5250#issuecomment-2569380578

browserExtensionsEnabled

boolean

是否可以為 webview 處理程序安裝瀏覽器擴充功能

平台特定
center

boolean

視窗是否應在啟動時置中。

closable

boolean

視窗的原生關閉按鈕是否啟用。

平台特定
  • Linux:「GTK+ 將盡力說服視窗管理員不要顯示關閉按鈕。根據系統,當在已可見的視窗上呼叫此函式時,可能不會有任何效果」
  • iOS / Android:不支援。

預設值true

contentProtected

boolean

防止視窗內容被其他應用程式擷取。

create

boolean

Tauri 是否應在應用程式啟動時建立此視窗。

當設定為 false 時,您必須透過 app.config().app.windows 手動抓取設定物件,並使用 WebviewWindowBuilder::from_config 建立它。

預設值true

decorations

boolean

視窗是否應具有邊框和標題列。

預設值true

devtools

boolean | null

啟用網頁檢查器,通常稱為瀏覽器開發人員工具。依預設啟用。

此 API 在 debug 建置中運作,但需要 devtools 功能旗標才能在 release 建置中啟用它。

平台特定
  • macOS:這將在 macOS 上呼叫私有函式。
  • Android:在 Chrome 中開啟 chrome://inspect/#devices 以取得開發人員工具視窗。Wry 的 WebView 開發人員工具 API 在 Android 上不受支援。
  • iOS:開啟 Safari > 開發 > [您的裝置名稱] > [您的 WebView] 以取得開發人員工具視窗。
dragDropEnabled

boolean

webview 上是否啟用拖放功能。依預設為啟用。

在 Windows 上,若要在前端使用 HTML5 拖放功能,則必須停用它。

預設值true

focus

boolean

視窗是否會在初始時取得焦點。

預設值true

fullscreen

boolean

視窗是否以全螢幕啟動。

height

number 格式為 double

視窗高度。

預設值600

hiddenTitle

boolean

若為 true,則在 macOS 上將視窗標題設定為隱藏。

incognito

boolean

webview 是否應以無痕模式啟動。

平台特定
  • Android:不支援。
label

string

視窗識別碼。必須是英數字元。

預設值"main"

maxHeight

number | null 格式為 double

視窗最大高度。

maximizable

boolean

視窗的原生最大化按鈕是否啟用。如果 resizable 設定為 false,則會忽略此設定。

平台特定
  • macOS:停用視窗標題列中的「縮放」按鈕,該按鈕也用於進入全螢幕模式。
  • Linux / iOS / Android:不支援。

預設值true

maximized

boolean

視窗是否已最大化。

maxWidth

number | null 格式為 double

視窗最大寬度。

minHeight

number | null 格式為 double

視窗最小高度。

minimizable

boolean

視窗的原生最小化按鈕是否啟用。

平台特定
  • Linux / iOS / Android:不支援。

預設值true

minWidth

number | null 格式為 double

視窗最小寬度。

parent

string | null

將與此標籤相關聯的視窗設定為要建立的視窗的父視窗。

平台特定
proxyUrl

string | null 格式為 uri

WebView 對於所有網路請求的 Proxy URL。

必須是 http://socks5:// URL。

平台特定
  • macOS:需要 macos-proxy 功能旗標,且僅適用於 macOS 14+ 編譯。
resizable

boolean

視窗是否可調整大小。當 resizable 設定為 false 時,原生視窗的最大化按鈕會自動停用。

預設值true

shadow

boolean

視窗是否具有陰影。

平台特定
  • Windows
    • false 對於已裝飾的視窗沒有任何作用,陰影始終為開啟狀態。
    • true 將使未裝飾的視窗具有 1 像素的白色邊框,並且在 Windows 11 上,它將具有圓角。
  • Linux:不支援。

預設值true

skipTaskbar

boolean

若為 true,則在 Windows 和 Linux 上從工作列中隱藏視窗圖示。

tabbingIdentifier

string | null

定義 macOS 的視窗 索引標籤識別碼

具有相符索引標籤識別碼的視窗將分組在一起。如果未設定索引標籤識別碼,則會停用自動索引標籤功能。

theme

Theme | null

初始視窗主題。預設為系統主題。僅在 Windows 和 macOS 10.14+ 上實作。

title

string

視窗標題。

預設值"Tauri App"

titleBarStyle

TitleBarStyle

macOS 標題列的樣式。

預設值"Visible"

transparent

boolean

視窗是否為透明。

請注意,在 macOS 上,這需要 macos-private-api 功能旗標,在 tauri &gt; macOSPrivateApi 下啟用。警告:在 macOS 上使用私有 API 會阻止您的應用程式被 App Store 接受。

url

WebviewUrl

視窗 webview URL。

預設值"index.html"

useHttpsScheme

boolean

設定自訂協定是否應使用 https://&lt;scheme&gt;.localhost 而不是預設的 http://&lt;scheme&gt;.localhost 在 Windows 和 Android 上。預設為 false

注意

當嘗試提取 http 端點時,使用 https 協定將不允許混合內容,因此將不會符合在 macOS 和 Linux 上使用的 &lt;scheme&gt;://localhost 協定的行為。

警告

在版本之間變更此值將會變更 IndexedDB、Cookie 和本機儲存位置,且您的應用程式將無法存取舊資料。

userAgent

string | null

webview 的使用者代理程式

visible

boolean

視窗是否可見。

預設值true

visibleOnAllWorkspaces

boolean

視窗是否應在所有工作區或虛擬桌面中可見。

平台特定
  • Windows / iOS / Android:不支援。
width

number 格式為 double

視窗寬度。

預設值800

windowClassname

string | null

在 Windows 上建立視窗所建立的視窗類別名稱。僅限 Windows

windowEffects

WindowEffectsConfig | null

視窗效果。

需要視窗為透明。

平台特定
x

number | null 格式為 double

視窗左上角的水平位置

y

number | null 格式為 double

視窗左上角的垂直位置

zoomHotkeysEnabled

boolean

是否啟用熱鍵頁面縮放

平台特定
  • Windows:控制 WebView2 的 IsZoomControlEnabled 設定。

  • MacOS / Linux:注入一個 polyfill,使用 ctrl/command + -/= 放大和縮小,每個步驟 20%,範圍從 20% 到 1000%。需要 webview:allow-set-webview-zoom 權限

  • Android / iOS:不支援。

WindowEffect

以下其中一項:

  • "appearanceBased" 適用於視圖有效外觀的預設材質。macOS 10.14-
  • "light" macOS 10.14-
  • "dark" macOS 10.14-
  • "mediumLight" macOS 10.14-
  • "ultraDark" macOS 10.14-
  • "titlebar" macOS 10.10+
  • "selection" macOS 10.10+
  • "menu" macOS 10.11+
  • "popover" macOS 10.11+
  • "sidebar" macOS 10.11+
  • "headerView" macOS 10.14+
  • "sheet" macOS 10.14+
  • "windowBackground" macOS 10.14+
  • "hudWindow" macOS 10.14+
  • "fullScreenUI" macOS 10.14+
  • "tooltip" macOS 10.14+
  • "contentBackground" macOS 10.14+
  • "underWindowBackground" macOS 10.14+
  • "underPageBackground" macOS 10.14+
  • "mica" 符合系統深色偏好的 Mica 效果 僅限 Windows 11
  • "micaDark" 具有深色模式的 Mica 效果,但僅在系統上啟用深色模式時 僅限 Windows 11
  • "micaLight" 具有淺色模式的 Mica 效果 僅限 Windows 11
  • "tabbed" 符合系統深色偏好的索引標籤效果 僅限 Windows 11
  • "tabbedDark" 具有深色模式的索引標籤效果,但僅在系統上啟用深色模式時 僅限 Windows 11
  • "tabbedLight" 具有淺色模式的索引標籤效果 僅限 Windows 11
  • "blur" 僅限 Windows 7/10/11(22H1) ##### 注意:在 Windows 11 組建 22621 上調整視窗大小/拖曳視窗時,此效果效能不佳。
  • "acrylic" 僅限 Windows 10/11 ##### 注意:在 Windows 10 v1903+ 和 Windows 11 組建 22000 上調整視窗大小/拖曳視窗時,此效果效能不佳。

平台特定的視窗效果

WindowEffectsConfig

視窗效果設定物件

物件屬性:

  • color
  • effects (必填)
  • radius
  • state
color

Color | null

視窗效果顏色。僅影響 Windows 10 v1903+ 上的 [WindowEffect::Blur] 和 [WindowEffect::Acrylic]。在 Windows 7 或 Windows 11 上沒有任何效果。

effects

WindowEffect[]

要套用至視窗的視窗效果列表。衝突的效果將套用第一個,並忽略其餘效果。

radius

number | null 格式為 double

視窗效果圓角半徑 僅限 macOS

state

WindowEffectState | null

視窗效果狀態 僅限 macOS

WindowEffectState

以下其中一項:

  • "followsWindowActiveState" 使視窗效果狀態跟隨視窗的活動狀態
  • "active" 使視窗效果狀態始終處於活動狀態
  • "inactive" 使視窗效果狀態始終處於非活動狀態

視窗效果狀態 僅限 macOS

<https://developer.apple.com/documentation/appkit/nsvisualeffectview/state>

WindowsConfig

Windows 捆綁器設定。

參閱更多: <https://v2.tauri.app/reference/config/#windowsconfig>

物件屬性:

  • allowDowngrades
  • certificateThumbprint
  • digestAlgorithm
  • nsis
  • signCommand
  • timestampUrl
  • tsp
  • webviewInstallMode
  • wix
allowDowngrades

boolean

驗證第二個應用程式安裝,如果設定為 false,則阻止使用者安裝舊版本。

例如,如果安裝了 1.2.1,使用者將無法安裝應用程式版本 1.2.01.1.5

此旗標的預設值為 true

預設值true

certificateThumbprint

string | null

指定簽署憑證的 SHA1 雜湊。

digestAlgorithm

string | null

指定用於建立檔案簽章的檔案摘要演算法。程式碼簽署是必要的。建議使用 SHA-256。

nsis

NsisConfig | null

使用 NSIS 產生的安裝程式的設定。

signCommand

CustomSignCommandConfig | null

指定用於簽署二進位檔的自訂命令。此命令需要在 args 中具有 %1,這只是一個二進位檔路徑的預留位置,我們將在呼叫命令之前偵測並取代它。

依預設,我們使用 signtool.exe,它只能在 Windows 上找到,因此如果您在另一個平台上並想要跨編譯和簽署,您將需要使用另一個工具,例如 osslsigncode

timestampUrl

string | null

在時間戳記期間使用的伺服器。

tsp

boolean

是否對時間戳記伺服器使用時間戳記協定 (TSP,又名 RFC 3161)。您的程式碼簽署提供者可能會使用 TSP 時間戳記伺服器,例如 SSL.com 所做的。如果是這樣,請將設定為 true 以啟用 TSP。

webviewInstallMode

WebviewInstallMode

Webview2 執行階段的安裝模式。

預設值
{
"silent": true,
"type": "downloadBootstrapper"
}
wix

WixConfig | null

使用 WiX 產生的 MSI 的設定。

WixConfig

使用 WiX 的 MSI 套件的設定。

參閱更多: <https://v2.tauri.app/reference/config/#wixconfig>

物件屬性:

  • bannerPath
  • componentGroupRefs
  • componentRefs
  • dialogImagePath
  • enableElevatedUpdateTask
  • featureGroupRefs
  • featureRefs
  • fragmentPaths
  • language
  • mergeRefs
  • template
  • upgradeCode
  • version
bannerPath

string | null

要用作安裝使用者介面橫幅的點陣圖檔案路徑。此點陣圖將出現在安裝程式的所有頁面(除了第一頁)的頂部。

所需尺寸為 493px × 58px。

componentGroupRefs

string[]

您想要從片段參考的 ComponentGroup 元素 ID。

預設值[]

componentRefs

string[]

您想要從片段參考的 Component 元素 ID。

預設值[]

dialogImagePath

string | null

要在安裝使用者介面對話方塊上使用的點陣圖檔案路徑。它用於歡迎和完成對話方塊。

所需尺寸為 493px × 312px。

enableElevatedUpdateTask

boolean

在 Windows 工作排程器中建立提升權限的更新工作。

featureGroupRefs

string[]

您想要從片段參考的 FeatureGroup 元素 ID。

預設值[]

featureRefs

string[]

您想要從片段參考的 Feature 元素 ID。

預設值[]

fragmentPaths

string[]

要使用的 WiX 片段的 .wxs 檔案路徑列表。

預設值[]

language

WixLanguage

要建置的安裝程式語言。請參閱 <https://docs.microsoft.com/en-us/windows/win32/msi/localizing-the-error-and-actiontext-tables>。

預設值"en-US"

mergeRefs

string[]

您想要從片段參考的 Merge 元素 ID。

預設值[]

template

string | null

要使用的自訂 .wxs 範本。

upgradeCode

string | null 格式為 uuid

MSI 安裝程式的 GUID 升級代碼。此代碼在您的所有更新中必須保持不變,否則,Windows 會將您的更新視為不同的應用程式,並且您的使用者將擁有應用程式的重複版本。

依預設,tauri 會透過在 DNS 命名空間中使用字串 &lt;productName&gt;.exe.app.x64 產生 Uuid v5 來產生此代碼。您可以使用 Tauri 的 CLI 來產生和列印此代碼,執行 tauri inspect wix-upgrade-code

建議您在 tauri 設定檔中設定此值,以避免在您想要變更產品名稱時意外變更升級代碼。

version

string | null

MSI 安裝程式版本,格式為 major.minor.patch.build(組建是選用的)。

由於 MSI 安裝程式需要有效的版本,因此如果未設定此欄位,將會從 [Config::version] 衍生而來。

第一個欄位是主要版本,最大值為 255。第二個欄位是次要版本,最大值為 255。第三個和第四個欄位的最大值為 65,535。

如需更多資訊,請參閱 <https://learn.microsoft.com/en-us/windows/win32/msi/productversion>。

WixLanguage

以下任何一項:

  • string 要建置的單一語言,無需設定。
  • string[] 要建置的語言列表,無需設定。
  • 語言及其設定的映射。允許其他屬性WixLanguageConfig

要使用 WiX 建置的語言。

WixLanguageConfig

WiX 建置目標語言的設定。

參閱更多: <https://v2.tauri.app/reference/config/#wixlanguageconfig>

物件屬性:

  • localePath
localePath

string | null

locale (.wxl) 檔案的路徑。請參閱 <https://wixtoolset.org/documentation/manual/v3/howtos/ui_and_localization/build_a_localized_version.html>。


© 2025 Tauri 貢獻者。CC-BY / MIT