Skip to main content

tauri_utils/
config.rs

1// Copyright 2019-2024 Tauri Programme within The Commons Conservancy
2// SPDX-License-Identifier: Apache-2.0
3// SPDX-License-Identifier: MIT
4
5//! The Tauri configuration used at runtime.
6//!
7//! It is pulled from a `tauri.conf.json` file and the [`Config`] struct is generated at compile time.
8//!
9//! # Stability
10//!
11//! This is a core functionality that is not considered part of the stable API.
12//! If you use it, note that it may include breaking changes in the future.
13//!
14//! These items are intended to be non-breaking from a de/serialization standpoint only.
15//! Using and modifying existing config values will try to avoid breaking changes, but they are
16//! free to add fields in the future - causing breaking changes for creating and full destructuring.
17//!
18//! To avoid this, [ignore unknown fields when destructuring] with the `{my, config, ..}` pattern.
19//! If you need to create the Rust config directly without deserializing, then create the struct
20//! the [Struct Update Syntax] with `..Default::default()`, which may need a
21//! `#[allow(clippy::needless_update)]` attribute if you are declaring all fields.
22//!
23//! [ignore unknown fields when destructuring]: https://doc.rust-lang.org/book/ch18-03-pattern-syntax.html#ignoring-remaining-parts-of-a-value-with-
24//! [Struct Update Syntax]: https://doc.rust-lang.org/book/ch05-01-defining-structs.html#creating-instances-from-other-instances-with-struct-update-syntax
25
26#[cfg(feature = "schema")]
27use schemars::JsonSchema;
28use semver::Version;
29use serde::{
30  Deserialize, Serialize, Serializer,
31  de::{Deserializer, Error as DeError, Visitor},
32};
33use serde_json::Value as JsonValue;
34use serde_untagged::UntaggedEnumVisitor;
35use serde_with::skip_serializing_none;
36use url::Url;
37
38use std::{
39  collections::{BTreeMap, HashMap, HashSet},
40  fmt::{self, Display},
41  fs::read_to_string,
42  path::PathBuf,
43  str::FromStr,
44};
45
46/// Items to help with parsing content into a [`Config`].
47pub mod parse;
48
49use crate::{TitleBarStyle, WindowEffect, WindowEffectState, acl::capability::Capability};
50
51pub use self::parse::parse;
52
53fn default_true() -> bool {
54  true
55}
56
57/// An URL to open on a Tauri webview window.
58#[derive(PartialEq, Eq, Debug, Clone, Serialize)]
59#[cfg_attr(feature = "schema", derive(JsonSchema))]
60#[serde(untagged)]
61#[non_exhaustive]
62pub enum WebviewUrl {
63  /// An external URL. Must use either the `http` or `https` schemes.
64  External(Url),
65  /// The path portion of an app URL.
66  /// For instance, to load `tauri://localhost/users/john`,
67  /// you can simply provide `users/john` in this configuration.
68  App(PathBuf),
69  /// A custom protocol url, for example, `doom://index.html`
70  CustomProtocol(Url),
71}
72
73impl<'de> Deserialize<'de> for WebviewUrl {
74  fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
75  where
76    D: Deserializer<'de>,
77  {
78    #[derive(Deserialize)]
79    #[serde(untagged)]
80    enum WebviewUrlDeserializer {
81      Url(Url),
82      Path(PathBuf),
83    }
84
85    match WebviewUrlDeserializer::deserialize(deserializer)? {
86      WebviewUrlDeserializer::Url(u) => {
87        if u.scheme() == "https" || u.scheme() == "http" {
88          Ok(Self::External(u))
89        } else {
90          Ok(Self::CustomProtocol(u))
91        }
92      }
93      WebviewUrlDeserializer::Path(p) => Ok(Self::App(p)),
94    }
95  }
96}
97
98impl fmt::Display for WebviewUrl {
99  fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
100    match self {
101      Self::External(url) | Self::CustomProtocol(url) => write!(f, "{url}"),
102      Self::App(path) => write!(f, "{}", path.display()),
103    }
104  }
105}
106
107impl Default for WebviewUrl {
108  fn default() -> Self {
109    Self::App("index.html".into())
110  }
111}
112
113/// A bundle referenced by tauri-bundler.
114#[derive(Debug, PartialEq, Eq, Clone)]
115#[cfg_attr(feature = "schema", derive(JsonSchema))]
116#[cfg_attr(feature = "schema", schemars(rename_all = "lowercase"))]
117pub enum BundleType {
118  /// The debian bundle (.deb).
119  Deb,
120  /// The RPM bundle (.rpm).
121  Rpm,
122  /// The AppImage bundle (.appimage).
123  AppImage,
124  /// The Microsoft Installer bundle (.msi).
125  Msi,
126  /// The NSIS bundle (.exe).
127  Nsis,
128  /// The macOS application bundle (.app).
129  App,
130  /// The Apple Disk Image bundle (.dmg).
131  Dmg,
132}
133
134impl BundleType {
135  /// All bundle types.
136  fn all() -> &'static [Self] {
137    &[
138      BundleType::Deb,
139      BundleType::Rpm,
140      BundleType::AppImage,
141      BundleType::Msi,
142      BundleType::Nsis,
143      BundleType::App,
144      BundleType::Dmg,
145    ]
146  }
147}
148
149impl Display for BundleType {
150  fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
151    write!(
152      f,
153      "{}",
154      match self {
155        Self::Deb => "deb",
156        Self::Rpm => "rpm",
157        Self::AppImage => "appimage",
158        Self::Msi => "msi",
159        Self::Nsis => "nsis",
160        Self::App => "app",
161        Self::Dmg => "dmg",
162      }
163    )
164  }
165}
166
167impl Serialize for BundleType {
168  fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
169  where
170    S: Serializer,
171  {
172    serializer.serialize_str(self.to_string().as_ref())
173  }
174}
175
176impl<'de> Deserialize<'de> for BundleType {
177  fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
178  where
179    D: Deserializer<'de>,
180  {
181    let s = String::deserialize(deserializer)?;
182    match s.to_lowercase().as_str() {
183      "deb" => Ok(Self::Deb),
184      "rpm" => Ok(Self::Rpm),
185      "appimage" => Ok(Self::AppImage),
186      "msi" => Ok(Self::Msi),
187      "nsis" => Ok(Self::Nsis),
188      "app" => Ok(Self::App),
189      "dmg" => Ok(Self::Dmg),
190      _ => Err(DeError::custom(format!("unknown bundle target '{s}'"))),
191    }
192  }
193}
194
195/// Targets to bundle. Each value is case insensitive.
196#[derive(Debug, PartialEq, Eq, Clone, Default)]
197#[cfg_attr(
198  feature = "schema",
199  derive(JsonSchema),
200  schemars(rename_all = "lowercase")
201)]
202pub enum BundleTarget {
203  /// Bundle all targets.
204  #[default]
205  All,
206  #[cfg_attr(feature = "schema", schemars(untagged))]
207  /// A list of bundle targets.
208  List(Vec<BundleType>),
209  #[cfg_attr(feature = "schema", schemars(untagged))]
210  /// A single bundle target.
211  One(BundleType),
212}
213
214impl Serialize for BundleTarget {
215  fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
216  where
217    S: Serializer,
218  {
219    match self {
220      Self::All => serializer.serialize_str("all"),
221      Self::List(l) => l.serialize(serializer),
222      Self::One(t) => serializer.serialize_str(t.to_string().as_ref()),
223    }
224  }
225}
226
227impl<'de> Deserialize<'de> for BundleTarget {
228  fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
229  where
230    D: Deserializer<'de>,
231  {
232    #[derive(Deserialize, Serialize)]
233    #[serde(untagged)]
234    pub enum BundleTargetInner {
235      List(Vec<BundleType>),
236      One(BundleType),
237      All(String),
238    }
239
240    match BundleTargetInner::deserialize(deserializer)? {
241      BundleTargetInner::All(s) if s.to_lowercase() == "all" => Ok(Self::All),
242      BundleTargetInner::All(t) => Err(DeError::custom(format!(
243        "invalid bundle type {t}, expected one of `all`, {}",
244        BundleType::all()
245          .iter()
246          .map(|b| format!("`{b}`"))
247          .collect::<Vec<_>>()
248          .join(", ")
249      ))),
250      BundleTargetInner::List(l) => Ok(Self::List(l)),
251      BundleTargetInner::One(t) => Ok(Self::One(t)),
252    }
253  }
254}
255
256impl BundleTarget {
257  /// Gets the bundle targets as a [`Vec`]. The vector is empty when set to [`BundleTarget::All`].
258  #[allow(dead_code)]
259  pub fn to_vec(&self) -> Vec<BundleType> {
260    match self {
261      Self::All => BundleType::all().to_vec(),
262      Self::List(list) => list.clone(),
263      Self::One(i) => vec![i.clone()],
264    }
265  }
266}
267
268/// Configuration for AppImage bundles.
269///
270/// See more: <https://v2.tauri.app/reference/config/#appimageconfig>
271#[derive(Debug, Default, PartialEq, Eq, Clone, Deserialize, Serialize)]
272#[cfg_attr(feature = "schema", derive(JsonSchema))]
273#[serde(rename_all = "camelCase", deny_unknown_fields)]
274pub struct AppImageConfig {
275  /// Include additional gstreamer dependencies needed for audio and video playback.
276  /// This increases the bundle size by ~15-35MB depending on your build system.
277  #[serde(default, alias = "bundle-media-framework")]
278  pub bundle_media_framework: bool,
279  /// The files to include in the Appimage Binary.
280  #[serde(default)]
281  pub files: HashMap<PathBuf, PathBuf>,
282}
283
284/// Configuration for Debian (.deb) bundles.
285///
286/// See more: <https://v2.tauri.app/reference/config/#debconfig>
287#[skip_serializing_none]
288#[derive(Debug, Default, PartialEq, Eq, Clone, Deserialize, Serialize)]
289#[cfg_attr(feature = "schema", derive(JsonSchema))]
290#[serde(rename_all = "camelCase", deny_unknown_fields)]
291pub struct DebConfig {
292  /// The list of deb dependencies your application relies on.
293  pub depends: Option<Vec<String>>,
294  /// The list of deb dependencies your application recommends.
295  pub recommends: Option<Vec<String>>,
296  /// The list of dependencies the package provides.
297  pub provides: Option<Vec<String>>,
298  /// The list of package conflicts.
299  pub conflicts: Option<Vec<String>>,
300  /// The list of package replaces.
301  pub replaces: Option<Vec<String>>,
302  /// The files to include on the package.
303  #[serde(default)]
304  pub files: HashMap<PathBuf, PathBuf>,
305  /// Define the section in Debian Control file. See : https://www.debian.org/doc/debian-policy/ch-archive.html#s-subsections
306  pub section: Option<String>,
307  /// Change the priority of the Debian Package. By default, it is set to `optional`.
308  /// Recognized Priorities as of now are :  `required`, `important`, `standard`, `optional`, `extra`
309  pub priority: Option<String>,
310  /// Path of the uncompressed Changelog file, to be stored at /usr/share/doc/package-name/changelog.gz. See
311  /// <https://www.debian.org/doc/debian-policy/ch-docs.html#changelog-files-and-release-notes>
312  pub changelog: Option<PathBuf>,
313  /// Path to a custom desktop file Handlebars template.
314  ///
315  /// Available variables: `categories`, `comment` (optional), `exec`, `icon` and `name`.
316  #[serde(alias = "desktop-template")]
317  pub desktop_template: Option<PathBuf>,
318  /// Path to script that will be executed before the package is unpacked. See
319  /// <https://www.debian.org/doc/debian-policy/ch-maintainerscripts.html>
320  #[serde(alias = "pre-install-script")]
321  pub pre_install_script: Option<PathBuf>,
322  /// Path to script that will be executed after the package is unpacked. See
323  /// <https://www.debian.org/doc/debian-policy/ch-maintainerscripts.html>
324  #[serde(alias = "post-install-script")]
325  pub post_install_script: Option<PathBuf>,
326  /// Path to script that will be executed before the package is removed. See
327  /// <https://www.debian.org/doc/debian-policy/ch-maintainerscripts.html>
328  #[serde(alias = "pre-remove-script")]
329  pub pre_remove_script: Option<PathBuf>,
330  /// Path to script that will be executed after the package is removed. See
331  /// <https://www.debian.org/doc/debian-policy/ch-maintainerscripts.html>
332  #[serde(alias = "post-remove-script")]
333  pub post_remove_script: Option<PathBuf>,
334}
335
336/// Configuration for Linux bundles.
337///
338/// See more: <https://v2.tauri.app/reference/config/#linuxconfig>
339#[skip_serializing_none]
340#[derive(Debug, Default, PartialEq, Eq, Clone, Deserialize, Serialize)]
341#[cfg_attr(feature = "schema", derive(JsonSchema))]
342#[serde(rename_all = "camelCase", deny_unknown_fields)]
343pub struct LinuxConfig {
344  /// Configuration for the AppImage bundle.
345  #[serde(default)]
346  pub appimage: AppImageConfig,
347  /// Configuration for the Debian bundle.
348  #[serde(default)]
349  pub deb: DebConfig,
350  /// Configuration for the RPM bundle.
351  #[serde(default)]
352  pub rpm: RpmConfig,
353}
354
355/// Compression algorithms used when bundling RPM packages.
356#[derive(Debug, PartialEq, Eq, Clone, Copy, Serialize, Deserialize)]
357#[cfg_attr(feature = "schema", derive(JsonSchema))]
358#[serde(rename_all = "camelCase", deny_unknown_fields, tag = "type")]
359#[non_exhaustive]
360pub enum RpmCompression {
361  /// Gzip compression
362  Gzip {
363    /// Gzip compression level
364    level: u32,
365  },
366  /// Zstd compression
367  Zstd {
368    /// Zstd compression level
369    level: i32,
370  },
371  /// Xz compression
372  Xz {
373    /// Xz compression level
374    level: u32,
375  },
376  /// Bzip2 compression
377  Bzip2 {
378    /// Bzip2 compression level
379    level: u32,
380  },
381  /// Disable compression
382  None,
383}
384
385/// Configuration for RPM bundles.
386#[skip_serializing_none]
387#[derive(Debug, PartialEq, Eq, Clone, Deserialize, Serialize)]
388#[cfg_attr(feature = "schema", derive(JsonSchema))]
389#[serde(rename_all = "camelCase", deny_unknown_fields)]
390pub struct RpmConfig {
391  /// The list of RPM dependencies your application relies on.
392  pub depends: Option<Vec<String>>,
393  /// The list of RPM dependencies your application recommends.
394  pub recommends: Option<Vec<String>>,
395  /// The list of RPM dependencies your application provides.
396  pub provides: Option<Vec<String>>,
397  /// The list of RPM dependencies your application conflicts with. They must not be present
398  /// in order for the package to be installed.
399  pub conflicts: Option<Vec<String>>,
400  /// The list of RPM dependencies your application supersedes - if this package is installed,
401  /// packages listed as "obsoletes" will be automatically removed (if they are present).
402  pub obsoletes: Option<Vec<String>>,
403  /// The RPM release tag.
404  #[serde(default = "default_release")]
405  pub release: String,
406  /// The RPM epoch.
407  #[serde(default)]
408  pub epoch: u32,
409  /// The files to include on the package.
410  #[serde(default)]
411  pub files: HashMap<PathBuf, PathBuf>,
412  /// Path to a custom desktop file Handlebars template.
413  ///
414  /// Available variables: `categories`, `comment` (optional), `exec`, `icon` and `name`.
415  #[serde(alias = "desktop-template")]
416  pub desktop_template: Option<PathBuf>,
417  /// Path to script that will be executed before the package is unpacked. See
418  /// <http://ftp.rpm.org/max-rpm/s1-rpm-inside-scripts.html>
419  #[serde(alias = "pre-install-script")]
420  pub pre_install_script: Option<PathBuf>,
421  /// Path to script that will be executed after the package is unpacked. See
422  /// <http://ftp.rpm.org/max-rpm/s1-rpm-inside-scripts.html>
423  #[serde(alias = "post-install-script")]
424  pub post_install_script: Option<PathBuf>,
425  /// Path to script that will be executed before the package is removed. See
426  /// <http://ftp.rpm.org/max-rpm/s1-rpm-inside-scripts.html>
427  #[serde(alias = "pre-remove-script")]
428  pub pre_remove_script: Option<PathBuf>,
429  /// Path to script that will be executed after the package is removed. See
430  /// <http://ftp.rpm.org/max-rpm/s1-rpm-inside-scripts.html>
431  #[serde(alias = "post-remove-script")]
432  pub post_remove_script: Option<PathBuf>,
433  /// Compression algorithm and level. Defaults to `Gzip` with level 6.
434  pub compression: Option<RpmCompression>,
435}
436
437impl Default for RpmConfig {
438  fn default() -> Self {
439    Self {
440      depends: None,
441      recommends: None,
442      provides: None,
443      conflicts: None,
444      obsoletes: None,
445      release: default_release(),
446      epoch: 0,
447      files: Default::default(),
448      desktop_template: None,
449      pre_install_script: None,
450      post_install_script: None,
451      pre_remove_script: None,
452      post_remove_script: None,
453      compression: None,
454    }
455  }
456}
457
458fn default_release() -> String {
459  "1".into()
460}
461
462/// Position coordinates struct.
463#[derive(Default, Debug, PartialEq, Eq, Clone, Deserialize, Serialize)]
464#[cfg_attr(feature = "schema", derive(JsonSchema))]
465#[serde(rename_all = "camelCase", deny_unknown_fields)]
466pub struct Position {
467  /// X coordinate.
468  pub x: u32,
469  /// Y coordinate.
470  pub y: u32,
471}
472
473/// Position coordinates struct.
474#[derive(Default, Debug, PartialEq, Clone, Deserialize, Serialize)]
475#[cfg_attr(feature = "schema", derive(JsonSchema))]
476#[serde(rename_all = "camelCase", deny_unknown_fields)]
477pub struct LogicalPosition {
478  /// X coordinate.
479  pub x: f64,
480  /// Y coordinate.
481  pub y: f64,
482}
483
484/// Size of the window.
485#[derive(Default, Debug, PartialEq, Eq, Clone, Deserialize, Serialize)]
486#[cfg_attr(feature = "schema", derive(JsonSchema))]
487#[serde(rename_all = "camelCase", deny_unknown_fields)]
488pub struct Size {
489  /// Width of the window.
490  pub width: u32,
491  /// Height of the window.
492  pub height: u32,
493}
494
495/// Configuration for Apple Disk Image (.dmg) bundles.
496///
497/// See more: <https://v2.tauri.app/reference/config/#dmgconfig>
498#[skip_serializing_none]
499#[derive(Debug, PartialEq, Eq, Clone, Deserialize, Serialize)]
500#[cfg_attr(feature = "schema", derive(JsonSchema))]
501#[serde(rename_all = "camelCase", deny_unknown_fields)]
502pub struct DmgConfig {
503  /// Image to use as the background in dmg file. Accepted formats: `png`/`jpg`/`gif`.
504  pub background: Option<PathBuf>,
505  /// Position of volume window on screen.
506  pub window_position: Option<Position>,
507  /// Size of volume window.
508  #[serde(default = "dmg_window_size", alias = "window-size")]
509  pub window_size: Size,
510  /// Position of app file on window.
511  #[serde(default = "dmg_app_position", alias = "app-position")]
512  pub app_position: Position,
513  /// Position of application folder on window.
514  #[serde(
515    default = "dmg_application_folder_position",
516    alias = "application-folder-position"
517  )]
518  pub application_folder_position: Position,
519}
520
521impl Default for DmgConfig {
522  fn default() -> Self {
523    Self {
524      background: None,
525      window_position: None,
526      window_size: dmg_window_size(),
527      app_position: dmg_app_position(),
528      application_folder_position: dmg_application_folder_position(),
529    }
530  }
531}
532
533fn dmg_window_size() -> Size {
534  Size {
535    width: 660,
536    height: 400,
537  }
538}
539
540fn dmg_app_position() -> Position {
541  Position { x: 180, y: 170 }
542}
543
544fn dmg_application_folder_position() -> Position {
545  Position { x: 480, y: 170 }
546}
547
548fn de_macos_minimum_system_version<'de, D>(deserializer: D) -> Result<Option<String>, D::Error>
549where
550  D: Deserializer<'de>,
551{
552  let version = Option::<String>::deserialize(deserializer)?;
553  match version {
554    Some(v) if v.is_empty() => Ok(macos_minimum_system_version()),
555    e => Ok(e),
556  }
557}
558
559/// Configuration for the macOS bundles.
560///
561/// See more: <https://v2.tauri.app/reference/config/#macconfig>
562#[skip_serializing_none]
563#[derive(Debug, PartialEq, Eq, Clone, Deserialize, Serialize)]
564#[cfg_attr(feature = "schema", derive(JsonSchema))]
565#[serde(rename_all = "camelCase", deny_unknown_fields)]
566pub struct MacConfig {
567  /// A list of strings indicating any macOS X frameworks that need to be bundled with the application.
568  ///
569  /// If a name is used, ".framework" must be omitted and it will look for standard install locations. You may also use a path to a specific framework.
570  pub frameworks: Option<Vec<String>>,
571  /// The files to include in the application relative to the Contents directory.
572  #[serde(default)]
573  pub files: HashMap<PathBuf, PathBuf>,
574  /// The version of the build that identifies an iteration of the bundle.
575  ///
576  /// Translates to the bundle's CFBundleVersion property.
577  #[serde(alias = "bundle-version")]
578  pub bundle_version: Option<String>,
579  /// The name of the builder that built the bundle.
580  ///
581  /// Translates to the bundle's CFBundleName property.
582  ///
583  /// If not set, defaults to the package's product name.
584  #[serde(alias = "bundle-name")]
585  pub bundle_name: Option<String>,
586  /// A version string indicating the minimum macOS X version that the bundled application supports. Defaults to `10.13`.
587  ///
588  /// Setting it to `null` completely removes the `LSMinimumSystemVersion` field on the bundle's `Info.plist`
589  /// and the `MACOSX_DEPLOYMENT_TARGET` environment variable.
590  ///
591  /// Ignored in `tauri dev`.
592  ///
593  /// An empty string is considered an invalid value so the default value is used.
594  #[serde(
595    deserialize_with = "de_macos_minimum_system_version",
596    default = "macos_minimum_system_version",
597    alias = "minimum-system-version"
598  )]
599  pub minimum_system_version: Option<String>,
600  /// Allows your application to communicate with the outside world.
601  /// It should be a lowercase, without port and protocol domain name.
602  #[serde(alias = "exception-domain")]
603  pub exception_domain: Option<String>,
604  /// Identity to use for code signing.
605  #[serde(alias = "signing-identity")]
606  pub signing_identity: Option<String>,
607  /// Whether the codesign should enable [hardened runtime](https://developer.apple.com/documentation/security/hardened_runtime) (for executables) or not.
608  #[serde(alias = "hardened-runtime", default = "default_true")]
609  pub hardened_runtime: bool,
610  /// Provider short name for notarization.
611  #[serde(alias = "provider-short-name")]
612  pub provider_short_name: Option<String>,
613  /// Path to the entitlements file.
614  pub entitlements: Option<String>,
615  /// Path to a Info.plist file to merge with the default Info.plist.
616  ///
617  /// Note that Tauri also looks for a `Info.plist` file in the same directory as the Tauri configuration file.
618  #[serde(alias = "info-plist")]
619  pub info_plist: Option<PathBuf>,
620  /// DMG-specific settings.
621  #[serde(default)]
622  pub dmg: DmgConfig,
623}
624
625impl Default for MacConfig {
626  fn default() -> Self {
627    Self {
628      frameworks: None,
629      files: HashMap::new(),
630      bundle_version: None,
631      bundle_name: None,
632      minimum_system_version: macos_minimum_system_version(),
633      exception_domain: None,
634      signing_identity: None,
635      hardened_runtime: true,
636      provider_short_name: None,
637      entitlements: None,
638      info_plist: None,
639      dmg: Default::default(),
640    }
641  }
642}
643
644fn macos_minimum_system_version() -> Option<String> {
645  Some("10.13".into())
646}
647
648fn ios_minimum_system_version() -> String {
649  "15.0".into()
650}
651
652/// Configuration for a target language for the WiX build.
653///
654/// See more: <https://v2.tauri.app/reference/config/#wixlanguageconfig>
655#[derive(Debug, PartialEq, Eq, Clone, Deserialize, Serialize)]
656#[cfg_attr(feature = "schema", derive(JsonSchema))]
657#[serde(rename_all = "camelCase", deny_unknown_fields)]
658pub struct WixLanguageConfig {
659  /// The path to a locale (`.wxl`) file. See <https://wixtoolset.org/documentation/manual/v3/howtos/ui_and_localization/build_a_localized_version.html>.
660  #[serde(alias = "locale-path")]
661  pub locale_path: Option<String>,
662}
663
664/// The languages to build using WiX.
665#[derive(Debug, PartialEq, Eq, Clone, Deserialize, Serialize)]
666#[cfg_attr(feature = "schema", derive(JsonSchema))]
667#[serde(untagged)]
668pub enum WixLanguage {
669  /// A single language to build, without configuration.
670  One(String),
671  /// A list of languages to build, without configuration.
672  List(Vec<String>),
673  /// A map of languages and its configuration.
674  Localized(HashMap<String, WixLanguageConfig>),
675}
676
677impl Default for WixLanguage {
678  fn default() -> Self {
679    Self::One("en-US".into())
680  }
681}
682
683/// Configuration for the MSI bundle using WiX.
684///
685/// See more: <https://v2.tauri.app/reference/config/#wixconfig>
686#[derive(Debug, Default, PartialEq, Eq, Clone, Deserialize, Serialize)]
687#[cfg_attr(feature = "schema", derive(JsonSchema))]
688#[serde(rename_all = "camelCase", deny_unknown_fields)]
689pub struct WixConfig {
690  /// MSI installer version in the format `major.minor.patch.build` (build is optional).
691  ///
692  /// Because a valid version is required for MSI installer, it will be derived from [`Config::version`] if this field is not set.
693  ///
694  /// The first field is the major version and has a maximum value of 255. The second field is the minor version and has a maximum value of 255.
695  /// The third and fourth fields have a maximum value of 65,535.
696  ///
697  /// See <https://learn.microsoft.com/en-us/windows/win32/msi/productversion> for more info.
698  pub version: Option<String>,
699  /// A GUID upgrade code for MSI installer. This code **_must stay the same across all of your updates_**,
700  /// otherwise, Windows will treat your update as a different app and your users will have duplicate versions of your app.
701  ///
702  /// By default, tauri generates this code by generating a Uuid v5 using the string `<productName>.exe.app.x64` in the DNS namespace.
703  /// You can use Tauri's CLI to generate and print this code for you, run `tauri inspect wix-upgrade-code`.
704  ///
705  /// It is recommended that you set this value in your tauri config file to avoid accidental changes in your upgrade code
706  /// whenever you want to change your product name.
707  #[serde(alias = "upgrade-code")]
708  pub upgrade_code: Option<uuid::Uuid>,
709  /// The installer languages to build. See <https://docs.microsoft.com/en-us/windows/win32/msi/localizing-the-error-and-actiontext-tables>.
710  #[serde(default)]
711  pub language: WixLanguage,
712  /// A custom .wxs template to use.
713  pub template: Option<PathBuf>,
714  /// A list of paths to .wxs files with WiX fragments to use.
715  #[serde(default, alias = "fragment-paths")]
716  pub fragment_paths: Vec<PathBuf>,
717  /// The ComponentGroup element ids you want to reference from the fragments.
718  #[serde(default, alias = "component-group-refs")]
719  pub component_group_refs: Vec<String>,
720  /// The Component element ids you want to reference from the fragments.
721  #[serde(default, alias = "component-refs")]
722  pub component_refs: Vec<String>,
723  /// The FeatureGroup element ids you want to reference from the fragments.
724  #[serde(default, alias = "feature-group-refs")]
725  pub feature_group_refs: Vec<String>,
726  /// The Feature element ids you want to reference from the fragments.
727  #[serde(default, alias = "feature-refs")]
728  pub feature_refs: Vec<String>,
729  /// The Merge element ids you want to reference from the fragments.
730  #[serde(default, alias = "merge-refs")]
731  pub merge_refs: Vec<String>,
732  /// Create an elevated update task within Windows Task Scheduler.
733  #[serde(default, alias = "enable-elevated-update-task")]
734  pub enable_elevated_update_task: bool,
735  /// Path to a bitmap file to use as the installation user interface banner.
736  /// This bitmap will appear at the top of all but the first page of the installer.
737  ///
738  /// The required dimensions are 493px × 58px.
739  #[serde(alias = "banner-path")]
740  pub banner_path: Option<PathBuf>,
741  /// Path to a bitmap file to use on the installation user interface dialogs.
742  /// It is used on the welcome and completion dialogs.
743  ///
744  /// The required dimensions are 493px × 312px.
745  #[serde(alias = "dialog-image-path")]
746  pub dialog_image_path: Option<PathBuf>,
747  /// Enables FIPS compliant algorithms.
748  /// Can also be enabled via the `TAURI_BUNDLER_WIX_FIPS_COMPLIANT` env var.
749  #[serde(default, alias = "fips-compliant")]
750  pub fips_compliant: bool,
751}
752
753/// Compression algorithms used in the NSIS installer.
754///
755/// See <https://nsis.sourceforge.io/Reference/SetCompressor>
756#[derive(Debug, PartialEq, Eq, Clone, Copy, Serialize, Deserialize, Default)]
757#[cfg_attr(feature = "schema", derive(JsonSchema))]
758#[serde(rename_all = "camelCase", deny_unknown_fields)]
759pub enum NsisCompression {
760  /// ZLIB uses the deflate algorithm, it is a quick and simple method. With the default compression level it uses about 300 KB of memory.
761  Zlib,
762  /// BZIP2 usually gives better compression ratios than ZLIB, but it is a bit slower and uses more memory. With the default compression level it uses about 4 MB of memory.
763  Bzip2,
764  /// LZMA (default) is a new compression method that gives very good compression ratios. The decompression speed is high (10-20 MB/s on a 2 GHz CPU), the compression speed is lower. The memory size that will be used for decompression is the dictionary size plus a few KBs, the default is 8 MB.
765  #[default]
766  Lzma,
767  /// Disable compression
768  None,
769}
770
771/// Install Modes for the NSIS installer.
772#[derive(Default, Debug, PartialEq, Eq, Clone, Copy, Serialize, Deserialize)]
773#[serde(rename_all = "camelCase", deny_unknown_fields)]
774#[cfg_attr(feature = "schema", derive(JsonSchema))]
775pub enum NSISInstallerMode {
776  /// Default mode for the installer.
777  ///
778  /// Install the app by default in a directory that doesn't require Administrator access.
779  ///
780  /// Installer metadata will be saved under the `HKCU` registry path.
781  #[default]
782  CurrentUser,
783  /// Install the app by default in the `Program Files` folder directory requires Administrator
784  /// access for the installation.
785  ///
786  /// Installer metadata will be saved under the `HKLM` registry path.
787  PerMachine,
788  /// Combines both modes and allows the user to choose at install time
789  /// whether to install for the current user or per machine. Note that this mode
790  /// will require Administrator access even if the user wants to install it for the current user only.
791  ///
792  /// Installer metadata will be saved under the `HKLM` or `HKCU` registry path based on the user's choice.
793  Both,
794}
795
796/// Configuration for the Installer bundle using NSIS.
797#[derive(Debug, Default, PartialEq, Eq, Clone, Deserialize, Serialize)]
798#[cfg_attr(feature = "schema", derive(JsonSchema))]
799#[serde(rename_all = "camelCase", deny_unknown_fields)]
800pub struct NsisConfig {
801  /// A custom .nsi template to use.
802  pub template: Option<PathBuf>,
803  /// The path to a bitmap file to display on the header of installers pages.
804  ///
805  /// The recommended dimensions are 150px x 57px.
806  #[serde(alias = "header-image")]
807  pub header_image: Option<PathBuf>,
808  /// The path to a bitmap file for the Welcome page and the Finish page.
809  ///
810  /// The recommended dimensions are 164px x 314px.
811  #[serde(alias = "sidebar-image")]
812  pub sidebar_image: Option<PathBuf>,
813  /// The path to an icon file used as the installer icon.
814  #[serde(alias = "installer-icon")]
815  pub installer_icon: Option<PathBuf>,
816  /// The path to an icon file used as the uninstaller icon.
817  #[serde(alias = "uninstaller-icon")]
818  pub uninstaller_icon: Option<PathBuf>,
819  /// The path to a bitmap file to display on the header of uninstallers pages.
820  /// Defaults to [`Self::header_image`]. If this is set but [`Self::header_image`] is not, a default image from NSIS will be applied to `header_image`
821  ///
822  /// The recommended dimensions are 150px x 57px.
823  #[serde(alias = "uninstaller-header-image")]
824  pub uninstaller_header_image: Option<PathBuf>,
825  /// Whether the installation will be for all users or just the current user.
826  #[serde(default, alias = "install-mode")]
827  pub install_mode: NSISInstallerMode,
828  /// A list of installer languages. Default to `["English"]` if not set.
829  ///
830  /// By default the OS language is used. If the OS language is not in the list of languages, the first language will be used.
831  /// To allow the user to select the language, set `display_language_selector` to `true`.
832  ///
833  /// See <https://github.com/kichik/nsis/tree/9465c08046f00ccb6eda985abbdbf52c275c6c4d/Contrib/Language%20files> for the complete list of languages.
834  pub languages: Option<Vec<String>>,
835  /// A key-value pair where the key is the language and the
836  /// value is the path to a custom `.nsh` file that holds the translated text for tauri's custom messages.
837  ///
838  /// See <https://github.com/tauri-apps/tauri/blob/dev/crates/tauri-bundler/src/bundle/windows/nsis/languages/English.nsh> for an example `.nsh` file.
839  ///
840  /// **Note**: the key must be a valid NSIS language and it must be added to the [`Self::languages`] array,
841  pub custom_language_files: Option<HashMap<String, PathBuf>>,
842  /// Whether to display a language selector dialog before the installer and uninstaller windows are rendered or not.
843  /// By default the OS language is selected, with a fallback to the first language in the `languages` array.
844  #[serde(default, alias = "display-language-selector")]
845  pub display_language_selector: bool,
846  /// Set the compression algorithm used to compress files in the installer.
847  ///
848  /// See <https://nsis.sourceforge.io/Reference/SetCompressor>
849  #[serde(default)]
850  pub compression: NsisCompression,
851  /// Set the folder name for the start menu shortcut.
852  ///
853  /// Use this option if you have multiple apps and wish to group their shortcuts under one folder
854  /// or if you generally prefer to set your shortcut inside a folder.
855  ///
856  /// Examples:
857  /// - `AwesomePublisher`, shortcut will be placed in `%AppData%\Microsoft\Windows\Start Menu\Programs\AwesomePublisher\<your-app>.lnk`
858  /// - If unset, shortcut will be placed in `%AppData%\Microsoft\Windows\Start Menu\Programs\<your-app>.lnk`
859  #[serde(alias = "start-menu-folder")]
860  pub start_menu_folder: Option<String>,
861  /// A path to a `.nsh` file that contains special NSIS macros to be hooked into the
862  /// main installer.nsi script.
863  ///
864  /// Supported hooks are:
865  ///
866  /// - `NSIS_HOOK_PREINSTALL`: This hook runs before copying files, setting registry key values and creating shortcuts.
867  /// - `NSIS_HOOK_POSTINSTALL`: This hook runs after the installer has finished copying all files, setting the registry keys and created shortcuts.
868  /// - `NSIS_HOOK_PREUNINSTALL`: This hook runs before removing any files, registry keys and shortcuts.
869  /// - `NSIS_HOOK_POSTUNINSTALL`: This hook runs after files, registry keys and shortcuts have been removed.
870  ///
871  /// ### Example
872  ///
873  /// ```nsh
874  /// !macro NSIS_HOOK_PREINSTALL
875  ///   MessageBox MB_OK "PreInstall"
876  /// !macroend
877  ///
878  /// !macro NSIS_HOOK_POSTINSTALL
879  ///   MessageBox MB_OK "PostInstall"
880  /// !macroend
881  ///
882  /// !macro NSIS_HOOK_PREUNINSTALL
883  ///   MessageBox MB_OK "PreUnInstall"
884  /// !macroend
885  ///
886  /// !macro NSIS_HOOK_POSTUNINSTALL
887  ///   MessageBox MB_OK "PostUninstall"
888  /// !macroend
889  /// ```
890  #[serde(alias = "installer-hooks")]
891  pub installer_hooks: Option<PathBuf>,
892  /// Deprecated: use [`WindowsConfig::minimum_webview2_version`] (`bundle >  windows > minimumWebview2Version`) instead.
893  ///
894  /// Try to ensure that the WebView2 version is equal to or newer than this version,
895  /// if the user's WebView2 is older than this version,
896  /// the installer will try to trigger a WebView2 update.
897  #[deprecated(
898    since = "2.10.0",
899    note = "Use `WindowsConfig::minimum_webview2_version` instead."
900  )]
901  #[serde(alias = "minimum-webview2-version")]
902  pub minimum_webview2_version: Option<String>,
903}
904
905/// Install modes for the Webview2 runtime.
906/// Note that for the updater bundle [`Self::DownloadBootstrapper`] is used.
907///
908/// For more information see <https://v2.tauri.app/distribute/windows-installer/#webview2-installation-options>.
909#[derive(Debug, PartialEq, Eq, Clone, Serialize, Deserialize)]
910#[serde(tag = "type", rename_all = "camelCase", deny_unknown_fields)]
911#[cfg_attr(feature = "schema", derive(JsonSchema))]
912pub enum WebviewInstallMode {
913  /// Do not install the Webview2 as part of the Windows Installer.
914  Skip,
915  /// Download the bootstrapper and run it.
916  /// Requires an internet connection.
917  /// Results in a smaller installer size, but is not recommended on Windows 7.
918  DownloadBootstrapper {
919    /// Instructs the installer to run the bootstrapper in silent mode. Defaults to `true`.
920    #[serde(default = "default_true")]
921    silent: bool,
922  },
923  /// Embed the bootstrapper and run it.
924  /// Requires an internet connection.
925  /// Increases the installer size by around 1.8MB, but offers better support on Windows 7.
926  EmbedBootstrapper {
927    /// Instructs the installer to run the bootstrapper in silent mode. Defaults to `true`.
928    #[serde(default = "default_true")]
929    silent: bool,
930  },
931  /// Embed the offline installer and run it.
932  /// Does not require an internet connection.
933  /// Increases the installer size by around 127MB.
934  OfflineInstaller {
935    /// Instructs the installer to run the installer in silent mode. Defaults to `true`.
936    #[serde(default = "default_true")]
937    silent: bool,
938  },
939  /// Embed a fixed webview2 version and use it at runtime.
940  /// Increases the installer size by around 180MB.
941  FixedRuntime {
942    /// The path to the fixed runtime to use.
943    ///
944    /// The fixed version can be downloaded [on the official website](https://developer.microsoft.com/en-us/microsoft-edge/webview2/#download-section).
945    /// The `.cab` file must be extracted to a folder and this folder path must be defined on this field.
946    path: PathBuf,
947  },
948}
949
950impl Default for WebviewInstallMode {
951  fn default() -> Self {
952    Self::DownloadBootstrapper { silent: true }
953  }
954}
955
956/// Custom Signing Command configuration.
957#[derive(Debug, PartialEq, Eq, Clone, Deserialize, Serialize)]
958#[cfg_attr(feature = "schema", derive(JsonSchema))]
959#[serde(rename_all = "camelCase", deny_unknown_fields, untagged)]
960pub enum CustomSignCommandConfig {
961  /// A string notation of the script to execute.
962  ///
963  /// "%1" will be replaced with the path to the binary to be signed.
964  ///
965  /// This is a simpler notation for the command.
966  /// Tauri will split the string with `' '` and use the first element as the command name and the rest as arguments.
967  ///
968  /// If you need to use whitespace in the command or arguments, use the object notation [`Self::CommandWithOptions`].
969  Command(String),
970  /// An object notation of the command.
971  ///
972  /// This is more complex notation for the command but
973  /// this allows you to use whitespace in the command and arguments.
974  CommandWithOptions {
975    /// The command to run to sign the binary.
976    cmd: String,
977    /// The arguments to pass to the command.
978    ///
979    /// "%1" will be replaced with the path to the binary to be signed.
980    args: Vec<String>,
981  },
982}
983
984/// Windows bundler configuration.
985///
986/// See more: <https://v2.tauri.app/reference/config/#windowsconfig>
987#[derive(Debug, PartialEq, Eq, Clone, Deserialize, Serialize)]
988#[cfg_attr(feature = "schema", derive(JsonSchema))]
989#[serde(rename_all = "camelCase", deny_unknown_fields)]
990pub struct WindowsConfig {
991  /// Specifies the file digest algorithm to use for creating file signatures.
992  /// Required for code signing. SHA-256 is recommended.
993  #[serde(alias = "digest-algorithm")]
994  pub digest_algorithm: Option<String>,
995  /// Specifies the SHA1 hash of the signing certificate.
996  #[serde(alias = "certificate-thumbprint")]
997  pub certificate_thumbprint: Option<String>,
998  /// Server to use during timestamping.
999  #[serde(alias = "timestamp-url")]
1000  pub timestamp_url: Option<String>,
1001  /// Whether to use Time-Stamp Protocol (TSP, a.k.a. RFC 3161) for the timestamp server. Your code signing provider may
1002  /// use a TSP timestamp server, like e.g. SSL.com does. If so, enable TSP by setting to true.
1003  #[serde(default)]
1004  pub tsp: bool,
1005  /// The installation mode for the Webview2 runtime.
1006  #[serde(default, alias = "webview-install-mode")]
1007  pub webview_install_mode: WebviewInstallMode,
1008  /// Validates a second app installation, blocking the user from installing an older version if set to `false`.
1009  ///
1010  /// For instance, if `1.2.1` is installed, the user won't be able to install app version `1.2.0` or `1.1.5`.
1011  ///
1012  /// The default value of this flag is `true`.
1013  #[serde(default = "default_true", alias = "allow-downgrades")]
1014  pub allow_downgrades: bool,
1015  /// Try to ensure that the WebView2 version is equal to or newer than this version,
1016  /// if the user's WebView2 is older than this version,
1017  /// the installer will try to trigger a WebView2 update.
1018  #[serde(alias = "minimum-webview2-version")]
1019  pub minimum_webview2_version: Option<String>,
1020  /// Configuration for the MSI generated with WiX.
1021  pub wix: Option<WixConfig>,
1022  /// Configuration for the installer generated with NSIS.
1023  pub nsis: Option<NsisConfig>,
1024  /// Specify a custom command to sign the binaries.
1025  /// This command needs to have a `%1` in args which is just a placeholder for the binary path,
1026  /// which we will detect and replace before calling the command.
1027  ///
1028  /// By Default we use `signtool.exe` which can be found only on Windows so
1029  /// if you are on another platform and want to cross-compile and sign you will
1030  /// need to use another tool like `osslsigncode`.
1031  #[serde(alias = "sign-command")]
1032  pub sign_command: Option<CustomSignCommandConfig>,
1033  /// Whether to bundle the Visual C++ runtime DLLs alongside the application.
1034  ///
1035  /// This can be particularly useful when your application includes sidecars or DLLs that do
1036  /// not statically link the Visual C++ runtime and require the runtime DLLs at runtime, and
1037  /// you do not want to require users to install the Visual C++ Redistributable. This can also
1038  /// be useful when `build > windows > staticVCRuntime` is set to `false`.
1039  #[serde(
1040    default,
1041    rename = "bundleVCRuntime",
1042    alias = "bundle-vc-runtime",
1043    alias = "bundleVcRuntime"
1044  )]
1045  pub bundle_vc_runtime: bool,
1046}
1047
1048impl Default for WindowsConfig {
1049  fn default() -> Self {
1050    Self {
1051      digest_algorithm: None,
1052      certificate_thumbprint: None,
1053      timestamp_url: None,
1054      tsp: false,
1055      webview_install_mode: Default::default(),
1056      allow_downgrades: true,
1057      minimum_webview2_version: None,
1058      wix: None,
1059      nsis: None,
1060      sign_command: None,
1061      bundle_vc_runtime: false,
1062    }
1063  }
1064}
1065
1066/// macOS-only. Corresponds to CFBundleTypeRole
1067#[derive(Debug, Default, PartialEq, Eq, Clone, Deserialize, Serialize)]
1068#[cfg_attr(feature = "schema", derive(JsonSchema))]
1069pub enum BundleTypeRole {
1070  /// CFBundleTypeRole.Editor. Files can be read and edited.
1071  #[default]
1072  Editor,
1073  /// CFBundleTypeRole.Viewer. Files can be read.
1074  Viewer,
1075  /// CFBundleTypeRole.Shell
1076  Shell,
1077  /// CFBundleTypeRole.QLGenerator
1078  QLGenerator,
1079  /// CFBundleTypeRole.None
1080  None,
1081}
1082
1083impl Display for BundleTypeRole {
1084  fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1085    match self {
1086      Self::Editor => write!(f, "Editor"),
1087      Self::Viewer => write!(f, "Viewer"),
1088      Self::Shell => write!(f, "Shell"),
1089      Self::QLGenerator => write!(f, "QLGenerator"),
1090      Self::None => write!(f, "None"),
1091    }
1092  }
1093}
1094
1095// Issue #13159 - Missing the LSHandlerRank and Apple warns after uploading to App Store Connect.
1096// https://github.com/tauri-apps/tauri/issues/13159
1097/// Corresponds to LSHandlerRank
1098#[derive(Debug, Default, PartialEq, Eq, Clone, Deserialize, Serialize)]
1099#[cfg_attr(feature = "schema", derive(JsonSchema))]
1100pub enum HandlerRank {
1101  /// LSHandlerRank.Default. This app is an opener of files of this type; this value is also used if no rank is specified.
1102  #[default]
1103  Default,
1104  /// LSHandlerRank.Owner. This app is the primary creator of files of this type.
1105  Owner,
1106  /// LSHandlerRank.Alternate. This app is a secondary viewer of files of this type.
1107  Alternate,
1108  /// LSHandlerRank.None. This app is never selected to open files of this type, but it accepts drops of files of this type.
1109  None,
1110}
1111
1112impl Display for HandlerRank {
1113  fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1114    match self {
1115      Self::Default => write!(f, "Default"),
1116      Self::Owner => write!(f, "Owner"),
1117      Self::Alternate => write!(f, "Alternate"),
1118      Self::None => write!(f, "None"),
1119    }
1120  }
1121}
1122
1123/// An extension for a [`FileAssociation`].
1124///
1125/// A leading `.` is automatically stripped.
1126#[derive(Debug, PartialEq, Eq, Clone, Serialize)]
1127#[cfg_attr(feature = "schema", derive(JsonSchema))]
1128pub struct AssociationExt(pub String);
1129
1130impl fmt::Display for AssociationExt {
1131  fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1132    write!(f, "{}", self.0)
1133  }
1134}
1135
1136impl<'d> serde::Deserialize<'d> for AssociationExt {
1137  fn deserialize<D: Deserializer<'d>>(deserializer: D) -> Result<Self, D::Error> {
1138    let ext = String::deserialize(deserializer)?;
1139    if let Some(ext) = ext.strip_prefix('.') {
1140      Ok(AssociationExt(ext.into()))
1141    } else {
1142      Ok(AssociationExt(ext))
1143    }
1144  }
1145}
1146
1147/// File association
1148#[derive(Debug, PartialEq, Eq, Clone, Deserialize, Serialize)]
1149#[cfg_attr(feature = "schema", derive(JsonSchema))]
1150#[serde(rename_all = "camelCase", deny_unknown_fields)]
1151pub struct FileAssociation {
1152  /// File extensions to associate with this app. e.g. 'png'
1153  pub ext: Vec<AssociationExt>,
1154  /// Declare support to a file with the given content type. Maps to `LSItemContentTypes` on macOS.
1155  ///
1156  /// This allows supporting any file format declared by another application that conforms to this type.
1157  /// Declaration of new types can be done with [`Self::exported_type`] and linking to certain content types are done via [`ExportedFileAssociation::conforms_to`].
1158  #[serde(alias = "content-types")]
1159  pub content_types: Option<Vec<String>>,
1160  /// The name. Maps to `CFBundleTypeName` on macOS. Default to `ext[0]`
1161  pub name: Option<String>,
1162  /// The association description. Windows-only. It is displayed on the `Type` column on Windows Explorer.
1163  pub description: Option<String>,
1164  /// The app's role with respect to the type. Maps to `CFBundleTypeRole` on macOS.
1165  #[serde(default)]
1166  pub role: BundleTypeRole,
1167  /// The mime-type of the association, e.g. `'image/png'` or `'text/plain'`.
1168  ///
1169  /// - **Linux**: written as `MimeType=` in the `.desktop` file.
1170  /// - **macOS / iOS**: added as `public.mime-type` in the `UTTypeTagSpecification` dictionary of
1171  ///   the `UTExportedTypeDeclarations` entry in `Info.plist`.
1172  /// - **Android**: used as `android:mimeType` in the `<data>` element of an `<intent-filter>`
1173  ///   in `AndroidManifest.xml`.
1174  #[serde(alias = "mime-type")]
1175  pub mime_type: Option<String>,
1176  /// The ranking of this app among apps that declare themselves as editors or viewers of the given file type.  Maps to `LSHandlerRank` on macOS.
1177  #[serde(default)]
1178  pub rank: HandlerRank,
1179  /// The exported type definition. Maps to a `UTExportedTypeDeclarations` entry on macOS.
1180  ///
1181  /// You should define this if the associated file is a custom file type defined by your application.
1182  pub exported_type: Option<ExportedFileAssociation>,
1183  /// Intent action filters for this file association.
1184  ///
1185  /// By default all filters are used.
1186  #[serde(alias = "android-intent-action-filters")]
1187  pub android_intent_action_filters: Option<Vec<AndroidIntentAction>>,
1188}
1189
1190/// Android intent action.
1191#[derive(Debug, PartialEq, Eq, Clone, Deserialize, Serialize, Hash)]
1192#[cfg_attr(feature = "schema", derive(JsonSchema))]
1193#[serde(rename_all = "camelCase")]
1194#[non_exhaustive]
1195pub enum AndroidIntentAction {
1196  /// ACTION_SEND.
1197  ///
1198  /// <https://developer.android.com/reference/android/content/Intent#ACTION_SEND>
1199  Send,
1200  /// ACTION_SEND_MULTIPLE.
1201  ///
1202  /// <https://developer.android.com/reference/android/content/Intent#ACTION_SEND_MULTIPLE>
1203  SendMultiple,
1204  /// ACTION_VIEW.
1205  ///
1206  /// <https://developer.android.com/reference/android/content/Intent#ACTION_SEND>
1207  View,
1208}
1209
1210/// The exported type definition. Maps to a `UTExportedTypeDeclarations` entry on macOS.
1211#[derive(Debug, PartialEq, Eq, Clone, Deserialize, Serialize)]
1212#[cfg_attr(feature = "schema", derive(JsonSchema))]
1213#[serde(rename_all = "camelCase", deny_unknown_fields)]
1214pub struct ExportedFileAssociation {
1215  /// The unique identifier for the exported type. Maps to `UTTypeIdentifier`.
1216  pub identifier: String,
1217  /// The types that this type conforms to. Maps to `UTTypeConformsTo`.
1218  ///
1219  /// Examples are `public.data`, `public.image`, `public.json` and `public.database`.
1220  #[serde(alias = "conforms-to")]
1221  pub conforms_to: Option<Vec<String>>,
1222}
1223
1224impl FileAssociation {
1225  /// Infers UTIs (Uniform Type Identifiers) from file extensions and mime types.
1226  /// This is useful for macOS and iOS to automatically populate `LSItemContentTypes`
1227  /// in the Info.plist for share sheet and file association support.
1228  ///
1229  /// Returns a vector of UTIs that should be included in `LSItemContentTypes`.
1230  /// Explicitly provided content types are included first, followed by inferred types.
1231  pub fn infer_content_types(&self) -> HashSet<String> {
1232    let mut content_types = HashSet::new();
1233
1234    // when we have an exported type, we only reference it
1235    if let Some(exported_type) = &self.exported_type {
1236      content_types.insert(exported_type.identifier.clone());
1237      return content_types;
1238    }
1239
1240    // Start with explicitly provided content types
1241    if let Some(explicit_types) = &self.content_types {
1242      content_types.extend(explicit_types.iter().cloned());
1243    }
1244
1245    // Infer from extensions and add to content_types (avoiding duplicates)
1246    for ext in &self.ext {
1247      if let Some(uti) = extension_to_uti(&ext.0) {
1248        content_types.insert(uti.to_string());
1249      }
1250    }
1251
1252    // Also infer from mime type if available (avoiding duplicates)
1253    if let Some(mime_type) = &self.mime_type
1254      && let Some(uti) = mime_type_to_uti(mime_type)
1255    {
1256      content_types.insert(uti.to_string());
1257    }
1258
1259    content_types
1260  }
1261}
1262
1263/// Generates plist dictionary entries for file associations.
1264/// This is used by both macOS and iOS bundlers to populate Info.plist.
1265///
1266/// Returns a plist dictionary containing `UTExportedTypeDeclarations` and `CFBundleDocumentTypes`
1267/// if there are any file associations configured.
1268pub fn file_associations_plist(associations: &[FileAssociation]) -> Option<plist::Value> {
1269  use plist::{Dictionary, Value};
1270
1271  if associations.is_empty() {
1272    return None;
1273  }
1274
1275  let exported_associations = associations
1276    .iter()
1277    .filter_map(|association| {
1278      association.exported_type.as_ref().map(|exported_type| {
1279        let mut dict = Dictionary::new();
1280
1281        dict.insert(
1282          "UTTypeIdentifier".into(),
1283          exported_type.identifier.clone().into(),
1284        );
1285        if let Some(description) = &association.description {
1286          dict.insert("UTTypeDescription".into(), description.clone().into());
1287        }
1288        if let Some(conforms_to) = &exported_type.conforms_to {
1289          dict.insert(
1290            "UTTypeConformsTo".into(),
1291            Value::Array(conforms_to.iter().map(|s| s.clone().into()).collect()),
1292          );
1293        }
1294
1295        let mut specification = Dictionary::new();
1296        specification.insert(
1297          "public.filename-extension".into(),
1298          Value::Array(
1299            association
1300              .ext
1301              .iter()
1302              .map(|s| s.to_string().into())
1303              .collect(),
1304          ),
1305        );
1306        if let Some(mime_type) = &association.mime_type {
1307          specification.insert("public.mime-type".into(), mime_type.clone().into());
1308        }
1309
1310        dict.insert("UTTypeTagSpecification".into(), specification.into());
1311
1312        Value::Dictionary(dict)
1313      })
1314    })
1315    .collect::<Vec<_>>();
1316
1317  let document_types = associations
1318    .iter()
1319    .map(|association| {
1320      let mut dict = Dictionary::new();
1321
1322      if !association.ext.is_empty() {
1323        dict.insert(
1324          "CFBundleTypeExtensions".into(),
1325          Value::Array(
1326            association
1327              .ext
1328              .iter()
1329              .map(|ext| ext.to_string().into())
1330              .collect(),
1331          ),
1332        );
1333      }
1334
1335      // For macOS/iOS share sheet, we need LSItemContentTypes with standard UTIs
1336      let content_types = association.infer_content_types();
1337
1338      // Add LSItemContentTypes if we have any content types
1339      if !content_types.is_empty() {
1340        dict.insert(
1341          "LSItemContentTypes".into(),
1342          Value::Array(content_types.iter().map(|s| s.clone().into()).collect()),
1343        );
1344      }
1345
1346      let type_name = association
1347        .name
1348        .clone()
1349        .or_else(|| association.ext.first().map(|ext| ext.0.clone()))
1350        .unwrap_or_default();
1351      dict.insert("CFBundleTypeName".into(), type_name.into());
1352      dict.insert(
1353        "CFBundleTypeRole".into(),
1354        association.role.to_string().into(),
1355      );
1356      dict.insert("LSHandlerRank".into(), association.rank.to_string().into());
1357
1358      Value::Dictionary(dict)
1359    })
1360    .collect::<Vec<_>>();
1361
1362  if exported_associations.is_empty() && document_types.is_empty() {
1363    return None;
1364  }
1365
1366  let mut plist = Dictionary::new();
1367  if !exported_associations.is_empty() {
1368    plist.insert(
1369      "UTExportedTypeDeclarations".into(),
1370      Value::Array(exported_associations),
1371    );
1372  }
1373  if !document_types.is_empty() {
1374    plist.insert("CFBundleDocumentTypes".into(), Value::Array(document_types));
1375  }
1376
1377  Some(Value::Dictionary(plist))
1378}
1379
1380/// Maps file extensions to their standard UTIs for macOS/iOS share sheet support
1381fn extension_to_uti(ext: &str) -> Option<&'static str> {
1382  match ext.to_lowercase().as_str() {
1383    // Images
1384    "png" => Some("public.png"),
1385    "jpg" | "jpeg" => Some("public.jpeg"),
1386    "gif" => Some("com.compuserve.gif"),
1387    "bmp" => Some("com.microsoft.bmp"),
1388    "tiff" | "tif" => Some("public.tiff"),
1389    "ico" => Some("com.microsoft.ico"),
1390    "heic" | "heif" => Some("public.heif-standard-image"),
1391    "webp" => Some("org.webmproject.webp"),
1392    "svg" => Some("public.svg-image"),
1393    // Videos
1394    "mp4" => Some("public.mpeg-4"),
1395    "mov" => Some("com.apple.quicktime-movie"),
1396    "avi" => Some("public.avi"),
1397    "mkv" => Some("public.mpeg-4"),
1398    // Audio
1399    "mp3" => Some("public.mp3"),
1400    "wav" => Some("com.microsoft.waveform-audio"),
1401    "aac" => Some("public.aac-audio"),
1402    "m4a" => Some("public.mpeg-4-audio"),
1403    // Documents
1404    "pdf" => Some("com.adobe.pdf"),
1405    "txt" => Some("public.plain-text"),
1406    "rtf" => Some("public.rtf"),
1407    "html" | "htm" => Some("public.html"),
1408    "json" => Some("public.json"),
1409    "xml" => Some("public.xml"),
1410    _ => None,
1411  }
1412}
1413
1414/// Infers UTIs from mime type
1415fn mime_type_to_uti(mime_type: &str) -> Option<&'static str> {
1416  match mime_type {
1417    "image/png" => Some("public.png"),
1418    "image/jpeg" | "image/jpg" => Some("public.jpeg"),
1419    "image/gif" => Some("com.compuserve.gif"),
1420    "image/bmp" => Some("com.microsoft.bmp"),
1421    "image/tiff" => Some("public.tiff"),
1422    "image/heic" | "image/heif" => Some("public.heif-standard-image"),
1423    "image/webp" => Some("org.webmproject.webp"),
1424    "image/svg+xml" => Some("public.svg-image"),
1425    mime if mime.starts_with("image/") => Some("public.image"),
1426    "video/mp4" => Some("public.mpeg-4"),
1427    "video/quicktime" => Some("com.apple.quicktime-movie"),
1428    "video/x-msvideo" => Some("public.avi"),
1429    mime if mime.starts_with("video/") => Some("public.movie"),
1430    "audio/mpeg" | "audio/mp3" => Some("public.mp3"),
1431    "audio/wav" | "audio/wave" => Some("com.microsoft.waveform-audio"),
1432    "audio/aac" => Some("public.aac-audio"),
1433    "audio/mp4" => Some("public.mpeg-4-audio"),
1434    mime if mime.starts_with("audio/") => Some("public.audio"),
1435    "application/pdf" => Some("com.adobe.pdf"),
1436    "text/plain" => Some("public.plain-text"),
1437    "text/rtf" => Some("public.rtf"),
1438    "text/html" => Some("public.html"),
1439    "application/json" => Some("public.json"),
1440    "application/xml" | "text/xml" => Some("public.xml"),
1441    _ => None,
1442  }
1443}
1444
1445/// Deep link protocol configuration.
1446#[derive(Debug, PartialEq, Eq, Clone, Deserialize, Serialize)]
1447#[cfg_attr(feature = "schema", derive(JsonSchema))]
1448#[serde(rename_all = "camelCase", deny_unknown_fields)]
1449pub struct DeepLinkProtocol {
1450  /// URL schemes to associate with this app without `://`. For example `my-app`
1451  #[serde(default)]
1452  pub schemes: Vec<String>,
1453  /// Domains to associate with this app. For example `example.com`.
1454  /// Currently only supported on macOS, translating to an [universal app link].
1455  ///
1456  /// Note that universal app links require signed apps with a provisioning profile to work.
1457  /// You can accomplish that by including the `embedded.provisionprofile` file in the `macOS > files` option.
1458  ///
1459  /// [universal app link]: https://developer.apple.com/documentation/xcode/supporting-universal-links-in-your-app
1460  #[serde(default)]
1461  pub domains: Vec<String>,
1462  /// The protocol name. **macOS-only** and maps to `CFBundleTypeName`. Defaults to `<bundle-id>.<schemes[0]>`
1463  pub name: Option<String>,
1464  /// The app's role for these schemes. **macOS-only** and maps to `CFBundleTypeRole`.
1465  #[serde(default)]
1466  pub role: BundleTypeRole,
1467}
1468
1469/// Definition for bundle resources.
1470/// Can be either a list of paths to include or a map of source to target paths.
1471#[derive(Debug, PartialEq, Eq, Clone, Deserialize, Serialize)]
1472#[cfg_attr(feature = "schema", derive(JsonSchema))]
1473#[serde(rename_all = "camelCase", deny_unknown_fields, untagged)]
1474pub enum BundleResources {
1475  /// A list of paths to include.
1476  List(Vec<String>),
1477  /// A map of source to target paths.
1478  Map(HashMap<String, String>),
1479}
1480
1481impl BundleResources {
1482  /// Adds a path to the resource collection.
1483  pub fn push(&mut self, path: impl Into<String>) {
1484    match self {
1485      Self::List(l) => l.push(path.into()),
1486      Self::Map(l) => {
1487        let path = path.into();
1488        l.insert(path.clone(), path);
1489      }
1490    }
1491  }
1492}
1493
1494/// Updater type
1495#[derive(Debug, PartialEq, Eq, Clone, Deserialize, Serialize)]
1496#[cfg_attr(feature = "schema", derive(JsonSchema))]
1497#[serde(rename_all = "camelCase", deny_unknown_fields, untagged)]
1498pub enum Updater {
1499  /// Generates legacy zipped v1 compatible updaters
1500  String(V1Compatible),
1501  /// Produce updaters and their signatures or not
1502  // Can't use untagged on enum field here: https://github.com/GREsau/schemars/issues/222
1503  Bool(bool),
1504}
1505
1506impl Default for Updater {
1507  fn default() -> Self {
1508    Self::Bool(false)
1509  }
1510}
1511
1512/// Generates legacy zipped v1 compatible updaters
1513#[derive(Debug, PartialEq, Eq, Clone, Deserialize, Serialize)]
1514#[cfg_attr(feature = "schema", derive(JsonSchema))]
1515#[serde(rename_all = "camelCase", deny_unknown_fields)]
1516pub enum V1Compatible {
1517  /// Generates legacy zipped v1 compatible updaters
1518  V1Compatible,
1519}
1520
1521/// Configuration for tauri-bundler.
1522///
1523/// See more: <https://v2.tauri.app/reference/config/#bundleconfig>
1524#[skip_serializing_none]
1525#[derive(Debug, Default, PartialEq, Eq, Clone, Deserialize, Serialize)]
1526#[cfg_attr(feature = "schema", derive(JsonSchema))]
1527#[serde(rename_all = "camelCase", deny_unknown_fields)]
1528pub struct BundleConfig {
1529  /// Whether Tauri should bundle your application or just output the executable.
1530  #[serde(default)]
1531  pub active: bool,
1532  /// The bundle targets, currently supports ["deb", "rpm", "appimage", "nsis", "msi", "app", "dmg"] or "all".
1533  #[serde(default)]
1534  pub targets: BundleTarget,
1535  #[serde(default)]
1536  /// Produce updaters and their signatures or not
1537  pub create_updater_artifacts: Updater,
1538  /// The application's publisher. Defaults to the second element in the identifier string.
1539  ///
1540  /// Currently maps to the Manufacturer property of the Windows Installer
1541  /// and the Maintainer field of debian packages if the Cargo.toml does not have the authors field.
1542  pub publisher: Option<String>,
1543  /// A url to the home page of your application. If unset, will
1544  /// fallback to `homepage` defined in `Cargo.toml`.
1545  ///
1546  /// Supported bundle targets: `deb`, `rpm`, `nsis` and `msi`.
1547  pub homepage: Option<String>,
1548  /// The app's icons
1549  #[serde(default)]
1550  pub icon: Vec<String>,
1551  /// App resources to bundle.
1552  /// Each resource is a path to a file or directory.
1553  /// Glob patterns are supported.
1554  ///
1555  /// ## Examples
1556  ///
1557  /// To include a list of files:
1558  ///
1559  /// ```json
1560  /// {
1561  ///   "bundle": {
1562  ///     "resources": [
1563  ///       "./path/to/some-file.txt",
1564  ///       "/absolute/path/to/textfile.txt",
1565  ///       "../relative/path/to/jsonfile.json",
1566  ///       "some-folder/",
1567  ///       "resources/**/*.md"
1568  ///     ]
1569  ///   }
1570  /// }
1571  /// ```
1572  ///
1573  /// The bundled files will be in `$RESOURCES/` with the original directory structure preserved,
1574  /// for example: `./path/to/some-file.txt` -> `$RESOURCE/path/to/some-file.txt`
1575  ///
1576  /// To fine control where the files will get copied to, use a map instead
1577  ///
1578  /// ```json
1579  /// {
1580  ///   "bundle": {
1581  ///     "resources": {
1582  ///       "/absolute/path/to/textfile.txt": "resources/textfile.txt",
1583  ///       "relative/path/to/jsonfile.json": "resources/jsonfile.json",
1584  ///       "resources/": "",
1585  ///       "docs/**/*md": "website-docs/"
1586  ///     }
1587  ///   }
1588  /// }
1589  /// ```
1590  ///
1591  /// Note that when using glob pattern in this case, the original directory structure is not preserved,
1592  /// everything gets copied to the target directory directly
1593  ///
1594  /// See more: <https://v2.tauri.app/develop/resources/>
1595  pub resources: Option<BundleResources>,
1596  /// A copyright string associated with your application.
1597  pub copyright: Option<String>,
1598  /// The package's license identifier to be included in the appropriate bundles.
1599  /// If not set, defaults to the license from the Cargo.toml file.
1600  pub license: Option<String>,
1601  /// The path to the license file to be included in the appropriate bundles.
1602  #[serde(alias = "license-file")]
1603  pub license_file: Option<PathBuf>,
1604  /// The application kind.
1605  ///
1606  /// Should be one of the following:
1607  /// 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.
1608  pub category: Option<String>,
1609  /// File types to associate with the application.
1610  pub file_associations: Option<Vec<FileAssociation>>,
1611  /// A short description of your application.
1612  #[serde(alias = "short-description")]
1613  pub short_description: Option<String>,
1614  /// A longer, multi-line description of the application.
1615  #[serde(alias = "long-description")]
1616  pub long_description: Option<String>,
1617  /// Whether to use the project's `target` directory, for caching build tools (e.g., Wix and NSIS) when building this application. Defaults to `false`.
1618  ///
1619  /// If true, tools will be cached in `target/.tauri/`.
1620  /// If false, tools will be cached in the current user's platform-specific cache directory.
1621  ///
1622  /// An example where it can be appropriate to set this to `true` is when building this application as a Windows System user (e.g., AWS EC2 workloads),
1623  /// because the Window system's app data directory is restricted.
1624  #[serde(default, alias = "use-local-tools-dir")]
1625  pub use_local_tools_dir: bool,
1626  /// A list of—either absolute or relative—paths to binaries to embed with your application.
1627  ///
1628  /// Note that Tauri will look for system-specific binaries following the pattern "binary-name{-target-triple}{.system-extension}".
1629  ///
1630  /// E.g. for the external binary "my-binary", Tauri looks for:
1631  ///
1632  /// - "my-binary-x86_64-pc-windows-msvc.exe" for Windows
1633  /// - "my-binary-x86_64-apple-darwin" for macOS
1634  /// - "my-binary-x86_64-unknown-linux-gnu" for Linux
1635  ///
1636  /// so don't forget to provide binaries for all targeted platforms.
1637  #[serde(alias = "external-bin")]
1638  pub external_bin: Option<Vec<String>>,
1639  /// Configuration for the Windows bundles.
1640  #[serde(default)]
1641  pub windows: WindowsConfig,
1642  /// Configuration for the Linux bundles.
1643  #[serde(default)]
1644  pub linux: LinuxConfig,
1645  /// Configuration for the macOS bundles.
1646  #[serde(rename = "macOS", alias = "macos", default)]
1647  pub macos: MacConfig,
1648  /// iOS configuration.
1649  #[serde(rename = "iOS", alias = "ios", default)]
1650  pub ios: IosConfig,
1651  /// Android configuration.
1652  #[serde(default)]
1653  pub android: AndroidConfig,
1654  /// Configuration for apps using the Chromium Embedded Framework.
1655  #[serde(default)]
1656  pub cef: CefConfig,
1657}
1658
1659/// Configuration for apps using the Chromium Embedded Framework (the `cef`
1660/// feature of the `tauri` crate).
1661///
1662/// See more: <https://v2.tauri.app/reference/config/#cefconfig>
1663#[skip_serializing_none]
1664#[derive(Debug, PartialEq, Eq, Clone, Deserialize, Serialize)]
1665#[cfg_attr(feature = "schema", derive(JsonSchema))]
1666#[serde(rename_all = "camelCase", deny_unknown_fields)]
1667pub struct CefConfig {
1668  /// Whether the CEF binary distribution is embedded in the bundle.
1669  /// Defaults to `true`.
1670  ///
1671  /// Set it to `false` for an app that loads CEF at run time from outside
1672  /// its own bundle — a shared, machine-wide runtime, through the
1673  /// `TAURI_CEF_LIBRARY_PATH` environment variable. The framework,
1674  /// `libcef` and their resources are then left out of every bundle, and
1675  /// the app must find a runtime at launch or it will not start. On macOS
1676  /// the helper apps are still produced: they belong to the app, not to
1677  /// the distribution.
1678  #[serde(default = "default_true")]
1679  pub embed: bool,
1680}
1681
1682impl Default for CefConfig {
1683  fn default() -> Self {
1684    Self { embed: true }
1685  }
1686}
1687
1688/// A tuple struct of RGBA colors. Each value has minimum of 0 and maximum of 255.
1689#[derive(Debug, PartialEq, Eq, Serialize, Default, Clone, Copy)]
1690#[cfg_attr(feature = "schema", derive(JsonSchema), schemars(with = "InnerColor"))]
1691#[serde(rename_all = "camelCase", deny_unknown_fields)]
1692pub struct Color(pub u8, pub u8, pub u8, pub u8);
1693
1694impl From<Color> for (u8, u8, u8, u8) {
1695  fn from(value: Color) -> Self {
1696    (value.0, value.1, value.2, value.3)
1697  }
1698}
1699
1700impl From<Color> for (u8, u8, u8) {
1701  fn from(value: Color) -> Self {
1702    (value.0, value.1, value.2)
1703  }
1704}
1705
1706impl From<(u8, u8, u8, u8)> for Color {
1707  fn from(value: (u8, u8, u8, u8)) -> Self {
1708    Color(value.0, value.1, value.2, value.3)
1709  }
1710}
1711
1712impl From<(u8, u8, u8)> for Color {
1713  fn from(value: (u8, u8, u8)) -> Self {
1714    Color(value.0, value.1, value.2, 255)
1715  }
1716}
1717
1718impl From<Color> for [u8; 4] {
1719  fn from(value: Color) -> Self {
1720    [value.0, value.1, value.2, value.3]
1721  }
1722}
1723
1724impl From<Color> for [u8; 3] {
1725  fn from(value: Color) -> Self {
1726    [value.0, value.1, value.2]
1727  }
1728}
1729
1730impl From<[u8; 4]> for Color {
1731  fn from(value: [u8; 4]) -> Self {
1732    Color(value[0], value[1], value[2], value[3])
1733  }
1734}
1735
1736impl From<[u8; 3]> for Color {
1737  fn from(value: [u8; 3]) -> Self {
1738    Color(value[0], value[1], value[2], 255)
1739  }
1740}
1741
1742impl FromStr for Color {
1743  type Err = String;
1744  fn from_str(mut color: &str) -> Result<Self, Self::Err> {
1745    color = color.trim().strip_prefix('#').unwrap_or(color);
1746    let color = match color.len() {
1747      3 => color.chars()
1748            .flat_map(|c| std::iter::repeat_n(c, 2))
1749            .chain(std::iter::repeat_n('f', 2))
1750            .collect(),
1751      6 => format!("{color}FF"),
1752      8 => color.to_string(),
1753      _ => return Err("Invalid hex color length, must be either 3, 6 or 8, for example: #fff, #ffffff, or #ffffffff".into()),
1754    };
1755
1756    let r = u8::from_str_radix(&color[0..2], 16).map_err(|e| e.to_string())?;
1757    let g = u8::from_str_radix(&color[2..4], 16).map_err(|e| e.to_string())?;
1758    let b = u8::from_str_radix(&color[4..6], 16).map_err(|e| e.to_string())?;
1759    let a = u8::from_str_radix(&color[6..8], 16).map_err(|e| e.to_string())?;
1760
1761    Ok(Color(r, g, b, a))
1762  }
1763}
1764
1765fn default_alpha() -> u8 {
1766  255
1767}
1768
1769#[derive(Deserialize)]
1770#[cfg_attr(feature = "schema", derive(JsonSchema))]
1771#[serde(untagged)]
1772enum InnerColor {
1773  /// Color hex string, for example: #fff, #ffffff, or #ffffffff.
1774  String(
1775    #[cfg_attr(
1776      feature = "schema",
1777      schemars(pattern("^#?([A-Fa-f0-9]{3}|[A-Fa-f0-9]{6}|[A-Fa-f0-9]{8})$"))
1778    )]
1779    String,
1780  ),
1781  /// Array of RGB colors. Each value has minimum of 0 and maximum of 255.
1782  Rgb((u8, u8, u8)),
1783  /// Array of RGBA colors. Each value has minimum of 0 and maximum of 255.
1784  Rgba((u8, u8, u8, u8)),
1785  /// Object of red, green, blue, alpha color values. Each value has minimum of 0 and maximum of 255.
1786  RgbaObject {
1787    red: u8,
1788    green: u8,
1789    blue: u8,
1790    #[serde(default = "default_alpha")]
1791    alpha: u8,
1792  },
1793}
1794
1795impl<'de> Deserialize<'de> for Color {
1796  fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
1797  where
1798    D: Deserializer<'de>,
1799  {
1800    let color = InnerColor::deserialize(deserializer)?;
1801    let color = match color {
1802      InnerColor::String(string) => string.parse().map_err(serde::de::Error::custom)?,
1803      InnerColor::Rgb(rgb) => Color(rgb.0, rgb.1, rgb.2, 255),
1804      InnerColor::Rgba(rgb) => rgb.into(),
1805      InnerColor::RgbaObject {
1806        red,
1807        green,
1808        blue,
1809        alpha,
1810      } => Color(red, green, blue, alpha),
1811    };
1812
1813    Ok(color)
1814  }
1815}
1816
1817/// Background throttling policy.
1818#[derive(Debug, PartialEq, Eq, Clone, Deserialize, Serialize)]
1819#[cfg_attr(feature = "schema", derive(JsonSchema))]
1820#[serde(rename_all = "camelCase", deny_unknown_fields)]
1821pub enum BackgroundThrottlingPolicy {
1822  /// A policy where background throttling is disabled
1823  Disabled,
1824  /// A policy where a web view that's not in a window fully suspends tasks. This is usually the default behavior in case no policy is set.
1825  Suspend,
1826  /// A policy where a web view that's not in a window limits processing, but does not fully suspend tasks.
1827  Throttle,
1828}
1829
1830/// The window effects configuration object
1831#[skip_serializing_none]
1832#[derive(Debug, PartialEq, Clone, Deserialize, Serialize, Default)]
1833#[cfg_attr(feature = "schema", derive(JsonSchema))]
1834#[serde(rename_all = "camelCase", deny_unknown_fields)]
1835pub struct WindowEffectsConfig {
1836  /// List of Window effects to apply to the Window.
1837  /// Conflicting effects will apply the first one and ignore the rest.
1838  pub effects: Vec<WindowEffect>,
1839  /// Window effect state **macOS Only**
1840  pub state: Option<WindowEffectState>,
1841  /// Window effect corner radius **macOS Only**
1842  pub radius: Option<f64>,
1843  /// Window effect color. Affects [`WindowEffect::Blur`] and [`WindowEffect::Acrylic`] only
1844  /// on Windows 10 v1903+. Doesn't have any effect on Windows 7 or Windows 11.
1845  pub color: Option<Color>,
1846}
1847
1848/// Enable prevent overflow with a margin
1849/// so that the window's size + this margin won't overflow the workarea
1850#[derive(Debug, PartialEq, Clone, Deserialize, Serialize, Default)]
1851#[cfg_attr(feature = "schema", derive(JsonSchema))]
1852#[serde(rename_all = "camelCase", deny_unknown_fields)]
1853pub struct PreventOverflowMargin {
1854  /// Horizontal margin in physical pixels
1855  pub width: u32,
1856  /// Vertical margin in physical pixels
1857  pub height: u32,
1858}
1859
1860/// Prevent overflow with a margin
1861#[derive(Debug, PartialEq, Clone, Serialize, Deserialize)]
1862#[cfg_attr(feature = "schema", derive(JsonSchema))]
1863#[serde(untagged)]
1864pub enum PreventOverflowConfig {
1865  /// Enable prevent overflow or not
1866  Enable(bool),
1867  /// Enable prevent overflow with a margin
1868  /// so that the window's size + this margin won't overflow the workarea
1869  Margin(PreventOverflowMargin),
1870}
1871
1872/// The scrollbar style to use in the webview.
1873///
1874/// ## Platform-specific
1875///
1876/// - **Windows**: This option must be given the same value for all webviews that target the same data directory.
1877#[derive(Debug, PartialEq, Clone, Serialize, Deserialize, Default)]
1878#[cfg_attr(feature = "schema", derive(JsonSchema))]
1879#[serde(rename_all = "camelCase", deny_unknown_fields)]
1880#[non_exhaustive]
1881pub enum ScrollBarStyle {
1882  #[default]
1883  /// The scrollbar style to use in the webview.
1884  Default,
1885
1886  /// Fluent UI style overlay scrollbars. **Windows Only**
1887  ///
1888  /// Requires WebView2 Runtime version 125.0.2535.41 or higher, does nothing on older versions,
1889  /// see <https://learn.microsoft.com/en-us/microsoft-edge/webview2/release-notes/?tabs=dotnetcsharp#10253541>
1890  FluentOverlay,
1891}
1892
1893/// The window configuration object.
1894///
1895/// See more: <https://v2.tauri.app/reference/config/#windowconfig>
1896#[skip_serializing_none]
1897#[derive(Debug, PartialEq, Clone, Deserialize, Serialize)]
1898#[cfg_attr(feature = "schema", derive(JsonSchema))]
1899#[serde(rename_all = "camelCase", deny_unknown_fields)]
1900pub struct WindowConfig {
1901  /// The window identifier. It must be alphanumeric.
1902  #[serde(default = "default_window_label")]
1903  pub label: String,
1904  /// Whether Tauri should create this window at app startup or not.
1905  ///
1906  /// When this is set to `false` you must manually grab the config object via `app.config().app.windows`
1907  /// and create it with [`WebviewWindowBuilder::from_config`](https://docs.rs/tauri/2/tauri/webview/struct.WebviewWindowBuilder.html#method.from_config).
1908  ///
1909  /// ## Example:
1910  ///
1911  /// ```rust
1912  /// tauri::Builder::default()
1913  ///   .setup(|app| {
1914  ///     tauri::WebviewWindowBuilder::from_config(app.handle(), &app.config().app.windows[0])?.build()?;
1915  ///     Ok(())
1916  ///   });
1917  /// ```
1918  #[serde(default = "default_true")]
1919  pub create: bool,
1920  /// The window webview URL.
1921  #[serde(default)]
1922  pub url: WebviewUrl,
1923  /// The user agent for the webview
1924  #[serde(alias = "user-agent")]
1925  pub user_agent: Option<String>,
1926  /// Whether the drag and drop handlers used internally to generate [`DragDropEvent`]s are enabled on the webview. By default it is enabled.
1927  ///
1928  /// Disabling it is required to use HTML5 drag and drop on the frontend on Windows since we replace the drag drop handler of WebView2.
1929  ///
1930  /// Note: this setting maps to [`WebviewBuilder::disable_drag_drop_handler`], not [`WindowBuilder::drag_and_drop`].
1931  ///
1932  /// [`DragDropEvent`]: https://docs.rs/tauri/latest/tauri/enum.DragDropEvent.html
1933  /// [`WebviewBuilder::disable_drag_drop_handler`]: https://docs.rs/tauri/latest/tauri/webview/struct.WebviewBuilder.html#method.disable_drag_drop_handler
1934  /// [`WindowBuilder::drag_and_drop`]: https://docs.rs/tauri/latest/x86_64-pc-windows-msvc/tauri/window/struct.WindowBuilder.html#method.drag_and_drop
1935  #[serde(default = "default_true", alias = "drag-drop-enabled")]
1936  pub drag_drop_enabled: bool,
1937  /// Whether or not the window starts centered or not.
1938  #[serde(default)]
1939  pub center: bool,
1940  /// The horizontal position of the window's top left corner in logical pixels
1941  pub x: Option<f64>,
1942  /// The vertical position of the window's top left corner in logical pixels
1943  pub y: Option<f64>,
1944  /// The window width in logical pixels.
1945  #[serde(default = "default_width")]
1946  pub width: f64,
1947  /// The window height in logical pixels.
1948  #[serde(default = "default_height")]
1949  pub height: f64,
1950  /// The min window width in logical pixels.
1951  #[serde(alias = "min-width")]
1952  pub min_width: Option<f64>,
1953  /// The min window height in logical pixels.
1954  #[serde(alias = "min-height")]
1955  pub min_height: Option<f64>,
1956  /// The max window width in logical pixels.
1957  #[serde(alias = "max-width")]
1958  pub max_width: Option<f64>,
1959  /// The max window height in logical pixels.
1960  #[serde(alias = "max-height")]
1961  pub max_height: Option<f64>,
1962  /// Whether or not to prevent the window from overflowing the workarea
1963  ///
1964  /// ## Platform-specific
1965  ///
1966  /// - **iOS / Android:** Unsupported.
1967  #[serde(alias = "prevent-overflow")]
1968  pub prevent_overflow: Option<PreventOverflowConfig>,
1969  /// Whether the window is resizable or not. When resizable is set to false, native window's maximize button is automatically disabled.
1970  #[serde(default = "default_true")]
1971  pub resizable: bool,
1972  /// Whether the window's native maximize button is enabled or not.
1973  /// If resizable is set to false, this setting is ignored.
1974  ///
1975  /// ## Platform-specific
1976  ///
1977  /// - **macOS:** Disables the "zoom" button in the window titlebar, which is also used to enter fullscreen mode.
1978  /// - **Linux / iOS / Android:** Unsupported.
1979  #[serde(default = "default_true")]
1980  pub maximizable: bool,
1981  /// Whether the window's native minimize button is enabled or not.
1982  ///
1983  /// ## Platform-specific
1984  ///
1985  /// - **Linux / iOS / Android:** Unsupported.
1986  #[serde(default = "default_true")]
1987  pub minimizable: bool,
1988  /// Whether the window's native close button is enabled or not.
1989  ///
1990  /// ## Platform-specific
1991  ///
1992  /// - **Linux:** "GTK+ will do its best to convince the window manager not to show a close button.
1993  ///   Depending on the system, this function may not have any effect when called on a window that is already visible"
1994  /// - **iOS / Android:** Unsupported.
1995  #[serde(default = "default_true")]
1996  pub closable: bool,
1997  /// The window title.
1998  #[serde(default = "default_title")]
1999  pub title: String,
2000  /// Whether the window starts as fullscreen or not.
2001  #[serde(default)]
2002  pub fullscreen: bool,
2003  /// Whether the window will be initially focused or not.
2004  #[serde(default = "default_true")]
2005  pub focus: bool,
2006  /// Whether the window will be focusable or not.
2007  #[serde(default = "default_true")]
2008  pub focusable: bool,
2009  /// Whether the window is transparent or not.
2010  ///
2011  /// Note that on `macOS` this requires the `macos-private-api` feature flag, enabled under `tauri > macOSPrivateApi`.
2012  /// WARNING: Using private APIs on `macOS` prevents your application from being accepted to the `App Store`.
2013  ///
2014  /// On Windows, using `noRedirectionBitmap` can help avoid a white flash when creating a transparent window.
2015  ///
2016  /// ## Platform-specific
2017  ///
2018  /// - **CEF runtime**: The window can be transparent but the webview cannot: a windowed Chromium browser paints an opaque background. The runtime logs a warning.
2019  #[serde(default)]
2020  pub transparent: bool,
2021  /// Whether the window is maximized or not.
2022  #[serde(default)]
2023  pub maximized: bool,
2024  /// Whether the window is visible or not.
2025  #[serde(default = "default_true")]
2026  pub visible: bool,
2027  /// Whether the window should have borders and bars.
2028  #[serde(default = "default_true")]
2029  pub decorations: bool,
2030  /// Whether the window should always be below other windows.
2031  #[serde(default, alias = "always-on-bottom")]
2032  pub always_on_bottom: bool,
2033  /// Whether the window should always be on top of other windows.
2034  #[serde(default, alias = "always-on-top")]
2035  pub always_on_top: bool,
2036  /// Whether the window should be visible on all workspaces or virtual desktops.
2037  ///
2038  /// ## Platform-specific
2039  ///
2040  /// - **Windows / iOS / Android:** Unsupported.
2041  #[serde(default, alias = "visible-on-all-workspaces")]
2042  pub visible_on_all_workspaces: bool,
2043  /// Prevents the window contents from being captured by other apps.
2044  #[serde(default, alias = "content-protected")]
2045  pub content_protected: bool,
2046  /// If `true`, hides the window icon from the taskbar on Windows and Linux.
2047  #[serde(default, alias = "skip-taskbar")]
2048  pub skip_taskbar: bool,
2049  /// The name of the window class created on Windows to create the window. **Windows only**.
2050  pub window_classname: Option<String>,
2051  /// This sets `WS_EX_NOREDIRECTIONBITMAP`.
2052  ///
2053  /// This can avoid the white flash that may appear before the webview content is rendered
2054  /// when using a transparent window. **Windows only**.
2055  #[serde(default, alias = "no-redirection-bitmap")]
2056  pub no_redirection_bitmap: bool,
2057  /// The initial window theme. Defaults to the system theme. Only implemented on Windows and macOS 10.14+.
2058  pub theme: Option<crate::Theme>,
2059  /// The style of the macOS title bar.
2060  #[serde(default, alias = "title-bar-style")]
2061  pub title_bar_style: TitleBarStyle,
2062  /// The position of the window controls on macOS.
2063  ///
2064  /// Requires titleBarStyle: Overlay and decorations: true.
2065  #[serde(default, alias = "traffic-light-position")]
2066  pub traffic_light_position: Option<LogicalPosition>,
2067  /// If `true`, sets the window title to be hidden on macOS.
2068  #[serde(default, alias = "hidden-title")]
2069  pub hidden_title: bool,
2070  /// Whether clicking an inactive window also clicks through to the webview on macOS.
2071  ///
2072  /// ## Platform-specific
2073  ///
2074  /// - **CEF runtime:** Unsupported. Chromium decides on its own whether the click that activates
2075  ///   the window reaches the page: it is swallowed on regular windows and only clicks through on
2076  ///   always-on-top windows or while a DevTools debugger is attached.
2077  #[serde(default, alias = "accept-first-mouse")]
2078  pub accept_first_mouse: bool,
2079  /// Defines the window [tabbing identifier] for macOS.
2080  ///
2081  /// Windows with matching tabbing identifiers will be grouped together.
2082  /// If the tabbing identifier is not set, automatic tabbing will be disabled.
2083  ///
2084  /// [tabbing identifier]: <https://developer.apple.com/documentation/appkit/nswindow/1644704-tabbingidentifier>
2085  #[serde(default, alias = "tabbing-identifier")]
2086  pub tabbing_identifier: Option<String>,
2087  /// Defines additional browser arguments on Windows.
2088  ///
2089  /// ## Platform-specific
2090  ///
2091  /// - **CEF runtime**: Unsupported. Chromium's command line is per process, not per webview;
2092  ///   pass switches through `Cef::command_line_arg` in Rust instead.
2093  ///
2094  /// ## Warning
2095  ///
2096  /// Webview instances with different browser arguments must also have different [data directories](Self::data_directory).
2097  ///
2098  /// By default wry passes `--disable-features=msWebOOUI,msPdfOOUI,msSmartScreenProtection`
2099  /// so if you set this, you also need to disable these components by yourself if you want.
2100  #[serde(default, alias = "additional-browser-args")]
2101  pub additional_browser_args: Option<String>,
2102  /// Whether or not the window has shadow.
2103  ///
2104  /// ## Platform-specific
2105  ///
2106  /// - **Windows:**
2107  ///   - `false` has no effect on decorated window, shadow are always ON.
2108  ///   - `true` will make undecorated window have a 1px white border,
2109  /// and on Windows 11, it will have a rounded corners.
2110  /// - **Linux:** Unsupported.
2111  #[serde(default = "default_true")]
2112  pub shadow: bool,
2113  /// Window effects.
2114  ///
2115  /// Requires the window to be transparent.
2116  ///
2117  /// ## Platform-specific:
2118  ///
2119  /// - **Windows**: If using decorations or shadows, you may want to try this workaround <https://github.com/tauri-apps/tao/issues/72#issuecomment-975607891>
2120  /// - **Linux**: Unsupported
2121  #[serde(default, alias = "window-effects")]
2122  pub window_effects: Option<WindowEffectsConfig>,
2123  /// Whether or not the webview should be launched in incognito  mode.
2124  ///
2125  /// ## Platform-specific:
2126  ///
2127  /// - **Android**: Unsupported.
2128  #[serde(default)]
2129  pub incognito: bool,
2130  /// Sets the window associated with this label to be the parent of the window to be created.
2131  ///
2132  /// ## Platform-specific
2133  ///
2134  /// - **Windows**: This sets the passed parent as an owner window to the window to be created.
2135  ///   From [MSDN owned windows docs](https://docs.microsoft.com/en-us/windows/win32/winmsg/window-features#owned-windows):
2136  ///     - An owned window is always above its owner in the z-order.
2137  ///     - The system automatically destroys an owned window when its owner is destroyed.
2138  ///     - An owned window is hidden when its owner is minimized.
2139  /// - **Linux**: This makes the new window transient for parent, see <https://docs.gtk.org/gtk3/method.Window.set_transient_for.html>
2140  /// - **macOS**: This adds the window as a child of parent, see <https://developer.apple.com/documentation/appkit/nswindow/1419152-addchildwindow?language=objc>
2141  pub parent: Option<String>,
2142  /// The proxy URL for the WebView for all network requests.
2143  ///
2144  /// Must be either a `http://` or a `socks5://` URL.
2145  ///
2146  /// ## Platform-specific
2147  ///
2148  /// - **macOS**: Requires the `macos-proxy` feature flag and only compiles for macOS 14+.
2149  #[serde(alias = "proxy-url")]
2150  pub proxy_url: Option<Url>,
2151  /// Whether page zooming by hotkeys is enabled
2152  ///
2153  /// ## Platform-specific:
2154  ///
2155  /// - **Windows**: Controls WebView2's [`IsZoomControlEnabled`](https://learn.microsoft.com/en-us/microsoft-edge/webview2/reference/winrt/microsoft_web_webview2_core/corewebview2settings?view=webview2-winrt-1.0.2420.47#iszoomcontrolenabled) setting.
2156  /// - **MacOS / Linux**: Injects a polyfill that zooms in and out with `ctrl/command` + `-/=`,
2157  /// 20% in each step, ranging from 20% to 1000%. Requires `webview:allow-set-webview-zoom` permission
2158  ///
2159  /// - **Android / iOS**: Unsupported.
2160  #[serde(default, alias = "zoom-hotkeys-enabled")]
2161  pub zoom_hotkeys_enabled: bool,
2162  /// Whether browser extensions can be installed for the webview process
2163  ///
2164  /// ## Platform-specific:
2165  ///
2166  /// - **Windows**: Enables the WebView2 environment's [`AreBrowserExtensionsEnabled`](https://learn.microsoft.com/en-us/microsoft-edge/webview2/reference/winrt/microsoft_web_webview2_core/corewebview2environmentoptions?view=webview2-winrt-1.0.2739.15#arebrowserextensionsenabled)
2167  /// - **MacOS / Linux / iOS / Android** - Unsupported.
2168  /// - **CEF runtime**: Unsupported. CEF removed its extension loading API; the runtime logs a warning.
2169  #[serde(default, alias = "browser-extensions-enabled")]
2170  pub browser_extensions_enabled: bool,
2171
2172  /// Sets whether the custom protocols should use `https://<scheme>.localhost` instead of the default `http://<scheme>.localhost` on Windows and Android. Defaults to `false`.
2173  ///
2174  /// ## Note
2175  ///
2176  /// Using a `https` scheme will NOT allow mixed content when trying to fetch `http` endpoints and therefore will not match the behavior of the `<scheme>://localhost` protocols used on macOS and Linux.
2177  ///
2178  /// ## Warning
2179  ///
2180  /// Changing this value between releases will change the IndexedDB, cookies and localstorage location and your app will not be able to access the old data.
2181  #[serde(default, alias = "use-https-scheme")]
2182  pub use_https_scheme: bool,
2183  /// Enable web inspector which is usually called browser devtools. Enabled by default.
2184  ///
2185  /// This API works in **debug** builds, but requires `devtools` feature flag to enable it in **release** builds.
2186  ///
2187  /// ## Platform-specific
2188  ///
2189  /// - macOS: This will call private functions on **macOS**.
2190  /// - Android: Open `chrome://inspect/#devices` in Chrome to get the devtools window. Wry's `WebView` devtools API isn't supported on Android.
2191  /// - iOS: Open Safari > Develop > [Your Device Name] > [Your WebView] to get the devtools window.
2192  pub devtools: Option<bool>,
2193
2194  /// Set the window and webview background color.
2195  ///
2196  /// ## Platform-specific:
2197  ///
2198  /// - **Windows**: alpha channel is ignored for the window layer.
2199  /// - **Windows**: On Windows 7, alpha channel is ignored for the webview layer.
2200  /// - **Windows**: On Windows 8 and newer, if alpha channel is not `0`, it will be ignored for the webview layer.
2201  #[serde(alias = "background-color")]
2202  pub background_color: Option<Color>,
2203
2204  /// Change the default background throttling behaviour.
2205  ///
2206  /// By default, browsers use a suspend policy that will throttle timers and even unload
2207  /// the whole tab (view) to free resources after roughly 5 minutes when a view became
2208  /// minimized or hidden. This will pause all tasks until the documents visibility state
2209  /// changes back from hidden to visible by bringing the view back to the foreground.
2210  ///
2211  /// ## Platform-specific
2212  ///
2213  /// - **Linux / Windows / Android**: Unsupported. Workarounds like a pending WebLock transaction might suffice.
2214  /// - **iOS**: Supported since version 17.0+.
2215  /// - **macOS**: Supported since version 14.0+.
2216  /// - **CEF runtime**: Unsupported per webview. Chromium throttles hidden pages process-wide; pass `--disable-background-timer-throttling` through `Cef::command_line_arg` to turn that off for every webview.
2217  ///
2218  /// see <https://github.com/tauri-apps/tauri/issues/5250#issuecomment-2569380578>
2219  #[serde(default, alias = "background-throttling")]
2220  pub background_throttling: Option<BackgroundThrottlingPolicy>,
2221  /// Whether we should disable JavaScript code execution on the webview or not.
2222  #[serde(default, alias = "javascript-disabled")]
2223  pub javascript_disabled: bool,
2224  /// on macOS and iOS there is a link preview on long pressing links, this is enabled by default.
2225  /// see https://docs.rs/objc2-web-kit/latest/objc2_web_kit/struct.WKWebView.html#method.allowsLinkPreview
2226  ///
2227  /// Not applicable on the CEF runtime, Chromium has no link previews.
2228  #[serde(default = "default_true", alias = "allow-link-preview")]
2229  pub allow_link_preview: bool,
2230  /// Allows disabling the input accessory view on iOS.
2231  ///
2232  /// The accessory view is the view that appears above the keyboard when a text input element is focused.
2233  /// It usually displays a view with "Done", "Next" buttons.
2234  #[serde(
2235    default,
2236    alias = "disable-input-accessory-view",
2237    alias = "disable_input_accessory_view"
2238  )]
2239  pub disable_input_accessory_view: bool,
2240  ///
2241  /// Set a custom path for the webview's data directory (localStorage, cache, etc.) **relative to [`appDataDir()`]/${label}**.
2242  ///
2243  /// To set absolute paths, use [`WebviewWindowBuilder::data_directory`](https://docs.rs/tauri/2/tauri/webview/struct.WebviewWindowBuilder.html#method.data_directory)
2244  ///
2245  /// #### Platform-specific:
2246  ///
2247  /// - **Windows**: WebViews with different values for settings like `additionalBrowserArgs`, `browserExtensionsEnabled` or `scrollBarStyle` must have different data directories.
2248  /// - **macOS / iOS**: Unsupported, use `dataStoreIdentifier` instead.
2249  /// - **Android**: Unsupported.
2250  #[serde(default, alias = "data-directory")]
2251  pub data_directory: Option<PathBuf>,
2252  ///
2253  /// Initialize the WebView with a custom data store identifier. This can be seen as a replacement for `dataDirectory` which is unavailable in WKWebView.
2254  /// See https://developer.apple.com/documentation/webkit/wkwebsitedatastore/init(foridentifier:)?language=objc
2255  ///
2256  /// The array must contain 16 u8 numbers.
2257  ///
2258  /// #### Platform-specific:
2259  ///
2260  /// - **iOS**: Supported since version 17.0+.
2261  /// - **macOS**: Supported since version 14.0+.
2262  /// - **Windows / Linux / Android**: Unsupported.
2263  /// - **CEF runtime**: Supported. The identifier names a profile directory under the runtime's cache path, the same isolation `dataDirectory` gives; `dataDirectory` wins when both are set.
2264  #[serde(default, alias = "data-store-identifier")]
2265  pub data_store_identifier: Option<[u8; 16]>,
2266
2267  /// Specifies the native scrollbar style to use with the webview.
2268  /// CSS styles that modify the scrollbar are applied on top of the native appearance configured here.
2269  ///
2270  /// Defaults to `default`, which is the browser default.
2271  ///
2272  /// ## Platform-specific
2273  ///
2274  /// - **Windows**:
2275  ///   - `fluentOverlay` requires WebView2 Runtime version 125.0.2535.41 or higher,
2276  ///     and does nothing on older versions.
2277  ///   - This option must be given the same value for all webviews that target the same data directory.
2278  /// - **Linux / Android / iOS / macOS**: Unsupported. Only supports `Default` and performs no operation.
2279  /// - **CEF runtime**: Unsupported per webview. Overlay scrollbars are a process-wide Chromium feature; enable them for every webview with `Cef::enable_features(["OverlayScrollbar"])`.
2280  #[serde(default, alias = "scroll-bar-style")]
2281  pub scroll_bar_style: ScrollBarStyle,
2282
2283  /// Whether to limit navigations to App-Bound Domains. This is necessary to
2284  /// enable Service Workers on iOS according to
2285  /// [StackOverflow](https://stackoverflow.com/questions/49673399/service-workers-unavailable-in-wkwebview-in-ios-11-3/64155509#64155509).
2286  ///
2287  /// Default is false.
2288  ///
2289  /// Note: If you set this to `true` make sure to add localhost and any [`registrable
2290  /// domains`](https://developer.mozilla.org/en-US/docs/Glossary/Registrable_domain)
2291  /// used in this webview to tauri-src/Info.ios.plist:
2292  ///
2293  /// ```xml
2294  /// <plist>
2295  /// <dict>
2296  ///     <key>WKAppBoundDomains</key>
2297  ///     <array>
2298  ///         <string>localhost</string>
2299  ///         <string>aregistrabledomain.example</string>
2300  ///     </array>
2301  /// </dict>
2302  /// </plist>
2303  /// ```
2304  ///
2305  /// You must add `localhost` if any webview with this set to true opens a
2306  /// local webpage, makes any localhost calls, or uses the isolation pattern
2307  /// because Tauri uses the `localhost` domain for hosting the application
2308  /// webpage, the IPC protocol, and the isolation pattern's iframe.
2309  ///
2310  /// Requests served through custom uri schemes are allowed so long as they use
2311  /// a registrable domain specified in the `WKAppBoundDomains` array for all the
2312  /// requests from the app, including requests for the `localhost` domain.
2313  ///
2314  /// In theory, you can whitelist an entire uri scheme by including the
2315  /// protocol name followed by a colon. For example, to allow all requests
2316  /// using a custom "stream" uri scheme (see [this tauri
2317  /// example](https://github.com/tauri-apps/tauri/blob/dev/examples/streaming/main.rs)),
2318  /// you could add `stream:` to the AppBoundDomains array. That said, I'm not
2319  /// sure whether Apple would let your app through app review if you do
2320  /// whitelist an entire protocol because this feature is not mentioned in
2321  /// [their blog post on App-Bound
2322  /// Domains](https://webkit.org/blog/10882/app-bound-domains/).
2323  ///
2324  /// See https://webkit.org/blog/10882/app-bound-domains/ and
2325  /// https://developer.apple.com/documentation/webkit/wkwebviewconfiguration/limitsnavigationstoappbounddomains
2326  /// for the official documentation on App-Bound Domains.
2327  ///
2328  /// ## Platform-specific
2329  ///
2330  /// - **iOS**: Supported since version 14.0+.
2331  /// - **Linux / Windows / Android / MacOS:** Unsupported.
2332  #[serde(default, alias = "limit-navigations-to-app-bound-domains")]
2333  pub limit_navigations_to_app_bound_domains: bool,
2334  /// The name of the Android activity to create for this window.
2335  #[serde(default, alias = "activity-name")]
2336  pub activity_name: Option<String>,
2337  /// The name of the Android activity that is creating this webview window.
2338  ///
2339  /// This is important to determine which stack the activity will belong to.
2340  #[serde(default, alias = "created-by-activity-name")]
2341  pub created_by_activity_name: Option<String>,
2342
2343  /// Sets the identifier of the scene that is requesting the new scene,
2344  /// establishing a relationship between the two scenes.
2345  ///
2346  /// By default the system uses the foreground scene.
2347  #[serde(default, alias = "requested-by-scene-identifier")]
2348  pub requested_by_scene_identifier: Option<String>,
2349  /// Controls the WebView's browser-level general autofill behavior.
2350  ///
2351  /// **This option does not disable password or credit card autofill.**
2352  ///
2353  /// When set to `false`, the WebView will not automatically populate
2354  /// general form fields using previously stored data such as addresses
2355  /// or contact information.
2356  ///
2357  /// If not specified, this is `true` by default.
2358  ///
2359  /// ## Platform-specific
2360  ///
2361  /// - **Windows**: Supported. WebView2's autofill feature (called
2362  ///   "Suggestions") may not honor `autocomplete="off"` on input
2363  ///   elements in some cases.
2364  /// - **Linux / Android / iOS / macOS**: Unsupported and performs no
2365  ///   operation.
2366  /// - **CEF runtime**: Autofill is already off on this runtime (it disables `autofill.profile_enabled` on every profile), so `false` is the state you get; turn it on with `Cef::profile_preference("autofill.profile_enabled", true)`.
2367  #[serde(default = "default_true", alias = "general-autofill-enabled")]
2368  pub general_autofill_enabled: bool,
2369}
2370
2371impl Default for WindowConfig {
2372  fn default() -> Self {
2373    Self {
2374      label: default_window_label(),
2375      url: WebviewUrl::default(),
2376      create: true,
2377      user_agent: None,
2378      drag_drop_enabled: true,
2379      center: false,
2380      x: None,
2381      y: None,
2382      width: default_width(),
2383      height: default_height(),
2384      min_width: None,
2385      min_height: None,
2386      max_width: None,
2387      max_height: None,
2388      prevent_overflow: None,
2389      resizable: true,
2390      maximizable: true,
2391      minimizable: true,
2392      closable: true,
2393      title: default_title(),
2394      fullscreen: false,
2395      focus: true,
2396      focusable: true,
2397      transparent: false,
2398      maximized: false,
2399      visible: true,
2400      decorations: true,
2401      always_on_bottom: false,
2402      always_on_top: false,
2403      visible_on_all_workspaces: false,
2404      content_protected: false,
2405      skip_taskbar: false,
2406      window_classname: None,
2407      no_redirection_bitmap: false,
2408      theme: None,
2409      title_bar_style: Default::default(),
2410      traffic_light_position: None,
2411      hidden_title: false,
2412      accept_first_mouse: false,
2413      tabbing_identifier: None,
2414      additional_browser_args: None,
2415      shadow: true,
2416      window_effects: None,
2417      incognito: false,
2418      parent: None,
2419      proxy_url: None,
2420      zoom_hotkeys_enabled: false,
2421      browser_extensions_enabled: false,
2422      use_https_scheme: false,
2423      devtools: None,
2424      background_color: None,
2425      background_throttling: None,
2426      javascript_disabled: false,
2427      allow_link_preview: true,
2428      disable_input_accessory_view: false,
2429      data_directory: None,
2430      data_store_identifier: None,
2431      scroll_bar_style: ScrollBarStyle::Default,
2432      limit_navigations_to_app_bound_domains: false,
2433      activity_name: None,
2434      created_by_activity_name: None,
2435      requested_by_scene_identifier: None,
2436      general_autofill_enabled: true,
2437    }
2438  }
2439}
2440
2441fn default_window_label() -> String {
2442  "main".to_string()
2443}
2444
2445fn default_width() -> f64 {
2446  800.
2447}
2448
2449fn default_height() -> f64 {
2450  600.
2451}
2452
2453fn default_title() -> String {
2454  "Tauri App".to_string()
2455}
2456
2457/// A Content-Security-Policy directive source list.
2458/// See <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/Sources#sources>.
2459#[derive(Debug, PartialEq, Eq, Clone, Deserialize, Serialize)]
2460#[cfg_attr(feature = "schema", derive(JsonSchema))]
2461#[serde(rename_all = "camelCase", untagged)]
2462pub enum CspDirectiveSources {
2463  /// An inline list of CSP sources. Same as [`Self::List`], but concatenated with a space separator.
2464  Inline(String),
2465  /// A list of CSP sources. The collection will be concatenated with a space separator for the CSP string.
2466  List(Vec<String>),
2467}
2468
2469impl Default for CspDirectiveSources {
2470  fn default() -> Self {
2471    Self::List(Vec::new())
2472  }
2473}
2474
2475impl From<CspDirectiveSources> for Vec<String> {
2476  fn from(sources: CspDirectiveSources) -> Self {
2477    match sources {
2478      CspDirectiveSources::Inline(source) => source.split(' ').map(|s| s.to_string()).collect(),
2479      CspDirectiveSources::List(l) => l,
2480    }
2481  }
2482}
2483
2484impl CspDirectiveSources {
2485  /// Whether the given source is configured on this directive or not.
2486  pub fn contains(&self, source: &str) -> bool {
2487    match self {
2488      Self::Inline(s) => s.contains(&format!("{source} ")) || s.contains(&format!(" {source}")),
2489      Self::List(l) => l.contains(&source.into()),
2490    }
2491  }
2492
2493  /// Appends the given source to this directive.
2494  pub fn push<S: AsRef<str>>(&mut self, source: S) {
2495    match self {
2496      Self::Inline(s) => {
2497        s.push(' ');
2498        s.push_str(source.as_ref());
2499      }
2500      Self::List(l) => {
2501        l.push(source.as_ref().to_string());
2502      }
2503    }
2504  }
2505
2506  /// Extends this CSP directive source list with the given array of sources.
2507  pub fn extend(&mut self, sources: Vec<String>) {
2508    for s in sources {
2509      self.push(s);
2510    }
2511  }
2512}
2513
2514/// A Content-Security-Policy definition.
2515/// See <https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP>.
2516#[derive(Debug, PartialEq, Eq, Clone, Deserialize)]
2517#[cfg_attr(feature = "schema", derive(JsonSchema))]
2518#[serde(rename_all = "camelCase", untagged)]
2519pub enum Csp {
2520  /// The entire CSP policy in a single text string.
2521  Policy(String),
2522  /// An object mapping a directive with its sources values as a list of strings.
2523  DirectiveMap(HashMap<String, CspDirectiveSources>),
2524}
2525
2526impl Serialize for Csp {
2527  fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
2528  where
2529    S: Serializer,
2530  {
2531    match self {
2532      Self::Policy(policy) => serializer.serialize_str(policy),
2533      Self::DirectiveMap(map) => {
2534        // Serialize through `BTreeMap` so the output is deterministic
2535        // see: https://github.com/tauri-apps/tauri/issues/14978
2536        // TODO: Remove this in v3, use a BTreeMap instead of a HashMap
2537        let btree_map: BTreeMap<_, _> = map.iter().collect();
2538        btree_map.serialize(serializer)
2539      }
2540    }
2541  }
2542}
2543
2544impl From<HashMap<String, CspDirectiveSources>> for Csp {
2545  fn from(map: HashMap<String, CspDirectiveSources>) -> Self {
2546    Self::DirectiveMap(map)
2547  }
2548}
2549
2550impl From<Csp> for HashMap<String, CspDirectiveSources> {
2551  fn from(csp: Csp) -> Self {
2552    match csp {
2553      Csp::Policy(policy) => {
2554        let mut map = HashMap::new();
2555        for directive in policy.split(';') {
2556          let mut tokens = directive.trim().split(' ');
2557          if let Some(directive) = tokens.next() {
2558            let sources = tokens.map(|s| s.to_string()).collect::<Vec<String>>();
2559            map.insert(directive.to_string(), CspDirectiveSources::List(sources));
2560          }
2561        }
2562        map
2563      }
2564      Csp::DirectiveMap(m) => m,
2565    }
2566  }
2567}
2568
2569impl Display for Csp {
2570  fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
2571    match self {
2572      Self::Policy(s) => write!(f, "{s}"),
2573      Self::DirectiveMap(m) => {
2574        let len = m.len();
2575        let mut i = 0;
2576        for (directive, sources) in m {
2577          let sources: Vec<String> = sources.clone().into();
2578          write!(f, "{} {}", directive, sources.join(" "))?;
2579          i += 1;
2580          if i != len {
2581            write!(f, "; ")?;
2582          }
2583        }
2584        Ok(())
2585      }
2586    }
2587  }
2588}
2589
2590/// The possible values for the `dangerous_disable_asset_csp_modification` config option.
2591#[derive(Debug, PartialEq, Eq, Clone, Deserialize, Serialize)]
2592#[serde(untagged)]
2593#[cfg_attr(feature = "schema", derive(JsonSchema))]
2594pub enum DisabledCspModificationKind {
2595  /// If `true`, disables all CSP modification.
2596  /// `false` is the default value and it configures Tauri to control the CSP.
2597  Flag(bool),
2598  /// Disables the given list of CSP directives modifications.
2599  List(Vec<String>),
2600}
2601
2602impl DisabledCspModificationKind {
2603  /// Determines whether the given CSP directive can be modified or not.
2604  pub fn can_modify(&self, directive: &str) -> bool {
2605    match self {
2606      Self::Flag(f) => !f,
2607      Self::List(l) => !l.contains(&directive.into()),
2608    }
2609  }
2610}
2611
2612impl Default for DisabledCspModificationKind {
2613  fn default() -> Self {
2614    Self::Flag(false)
2615  }
2616}
2617
2618/// Protocol scope definition.
2619/// It is a list of glob patterns that restrict the API access from the webview.
2620///
2621/// Each pattern can start with a variable that resolves to a system base directory.
2622/// The variables are: `$AUDIO`, `$CACHE`, `$CONFIG`, `$DATA`, `$LOCALDATA`, `$DESKTOP`,
2623/// `$DOCUMENT`, `$DOWNLOAD`, `$EXE`, `$FONT`, `$HOME`, `$PICTURE`, `$PUBLIC`, `$RUNTIME`,
2624/// `$TEMPLATE`, `$VIDEO`, `$RESOURCE`, `$TEMP`,
2625/// `$APPCONFIG`, `$APPDATA`, `$APPLOCALDATA`, `$APPCACHE`, `$APPLOG`.
2626#[derive(Debug, PartialEq, Eq, Clone, Deserialize, Serialize)]
2627#[serde(untagged)]
2628#[cfg_attr(feature = "schema", derive(JsonSchema))]
2629pub enum FsScope {
2630  /// A list of paths that are allowed by this scope.
2631  AllowedPaths(Vec<PathBuf>),
2632  /// A complete scope configuration.
2633  #[serde(rename_all = "camelCase")]
2634  Scope {
2635    /// A list of paths that are allowed by this scope.
2636    #[serde(default)]
2637    allow: Vec<PathBuf>,
2638    /// A list of paths that are not allowed by this scope.
2639    /// This gets precedence over the [`Self::Scope::allow`] list.
2640    #[serde(default)]
2641    deny: Vec<PathBuf>,
2642    /// Whether or not paths that contain components that start with a `.`
2643    /// will require that `.` appears literally in the pattern; `*`, `?`, `**`,
2644    /// or `[...]` will not match. This is useful because such files are
2645    /// conventionally considered hidden on Unix systems and it might be
2646    /// desirable to skip them when listing files.
2647    ///
2648    /// Defaults to `true` on Unix systems and `false` on Windows
2649    // dotfiles are not supposed to be exposed by default on unix
2650    #[serde(alias = "require-literal-leading-dot")]
2651    require_literal_leading_dot: Option<bool>,
2652  },
2653}
2654
2655impl Default for FsScope {
2656  fn default() -> Self {
2657    Self::AllowedPaths(Vec::new())
2658  }
2659}
2660
2661impl FsScope {
2662  /// The list of allowed paths.
2663  pub fn allowed_paths(&self) -> &Vec<PathBuf> {
2664    match self {
2665      Self::AllowedPaths(p) => p,
2666      Self::Scope { allow, .. } => allow,
2667    }
2668  }
2669
2670  /// The list of forbidden paths.
2671  pub fn forbidden_paths(&self) -> Option<&Vec<PathBuf>> {
2672    match self {
2673      Self::AllowedPaths(_) => None,
2674      Self::Scope { deny, .. } => Some(deny),
2675    }
2676  }
2677}
2678
2679/// Config for the asset custom protocol.
2680///
2681/// See more: <https://v2.tauri.app/reference/config/#assetprotocolconfig>
2682#[derive(Debug, Default, PartialEq, Eq, Clone, Deserialize, Serialize)]
2683#[cfg_attr(feature = "schema", derive(JsonSchema))]
2684#[serde(rename_all = "camelCase", deny_unknown_fields)]
2685pub struct AssetProtocolConfig {
2686  /// The access scope for the asset protocol.
2687  #[serde(default)]
2688  pub scope: FsScope,
2689  /// Enables the asset protocol.
2690  #[serde(default)]
2691  pub enable: bool,
2692}
2693
2694/// definition of a header source
2695///
2696/// The header value to a header name
2697#[derive(Debug, PartialEq, Eq, Clone, Deserialize)]
2698#[cfg_attr(feature = "schema", derive(JsonSchema))]
2699#[serde(rename_all = "camelCase", untagged)]
2700pub enum HeaderSource {
2701  /// string version of the header Value
2702  Inline(String),
2703  /// list version of the header value. Item are joined by "," for the real header value
2704  List(Vec<String>),
2705  /// (Rust struct | Json | JavaScript Object) equivalent of the header value. Items are composed from: key + space + value. Item are then joined by ";" for the real header value
2706  Map(HashMap<String, String>),
2707}
2708
2709impl Serialize for HeaderSource {
2710  fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
2711  where
2712    S: Serializer,
2713  {
2714    match self {
2715      Self::Inline(s) => serializer.serialize_str(s),
2716      Self::List(l) => l.serialize(serializer),
2717      Self::Map(m) => {
2718        // Serialize through `BTreeMap` so the output is deterministic
2719        // see: https://github.com/tauri-apps/tauri/issues/14978
2720        // TODO: Remove this in v3, use a BTreeMap instead of a HashMap
2721        let btree_map: BTreeMap<_, _> = m.iter().collect();
2722        btree_map.serialize(serializer)
2723      }
2724    }
2725  }
2726}
2727
2728impl Display for HeaderSource {
2729  fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
2730    match self {
2731      Self::Inline(s) => write!(f, "{s}"),
2732      Self::List(l) => write!(f, "{}", l.join(", ")),
2733      Self::Map(m) => {
2734        // Format through `BTreeMap` so the resulting header value is deterministic
2735        // see: https://github.com/tauri-apps/tauri/issues/14978
2736        // TODO: Remove this in v3, use a BTreeMap instead of a HashMap
2737        let map: BTreeMap<_, _> = m.iter().collect();
2738        let len = map.len();
2739        for (i, (key, value)) in map.into_iter().enumerate() {
2740          write!(f, "{key} {value}")?;
2741          if i + 1 != len {
2742            write!(f, "; ")?;
2743          }
2744        }
2745        Ok(())
2746      }
2747    }
2748  }
2749}
2750
2751/// A trait which implements on the [`Builder`] of the http create
2752///
2753/// Must add headers defined in the tauri configuration file to http responses
2754pub trait HeaderAddition {
2755  /// adds all headers defined on the config file, given the current HeaderConfig
2756  fn add_configured_headers(self, headers: Option<&HeaderConfig>) -> http::response::Builder;
2757}
2758
2759impl HeaderAddition for http::response::Builder {
2760  /// Add the headers defined in the tauri configuration file to http responses
2761  ///
2762  /// this is a utility function, which is used in the same way as the `.header(..)` of the rust http library
2763  fn add_configured_headers(mut self, headers: Option<&HeaderConfig>) -> http::response::Builder {
2764    if let Some(headers) = headers {
2765      // Add the header Access-Control-Allow-Credentials, if we find a value for it
2766      if let Some(value) = &headers.access_control_allow_credentials {
2767        self = self.header("Access-Control-Allow-Credentials", value.to_string());
2768      };
2769
2770      // Add the header Access-Control-Allow-Headers, if we find a value for it
2771      if let Some(value) = &headers.access_control_allow_headers {
2772        self = self.header("Access-Control-Allow-Headers", value.to_string());
2773      };
2774
2775      // Add the header Access-Control-Allow-Methods, if we find a value for it
2776      if let Some(value) = &headers.access_control_allow_methods {
2777        self = self.header("Access-Control-Allow-Methods", value.to_string());
2778      };
2779
2780      // Add the header Access-Control-Expose-Headers, if we find a value for it
2781      if let Some(value) = &headers.access_control_expose_headers {
2782        self = self.header("Access-Control-Expose-Headers", value.to_string());
2783      };
2784
2785      // Add the header Access-Control-Max-Age, if we find a value for it
2786      if let Some(value) = &headers.access_control_max_age {
2787        self = self.header("Access-Control-Max-Age", value.to_string());
2788      };
2789
2790      // Add the header Cross-Origin-Embedder-Policy, if we find a value for it
2791      if let Some(value) = &headers.cross_origin_embedder_policy {
2792        self = self.header("Cross-Origin-Embedder-Policy", value.to_string());
2793      };
2794
2795      // Add the header Cross-Origin-Opener-Policy, if we find a value for it
2796      if let Some(value) = &headers.cross_origin_opener_policy {
2797        self = self.header("Cross-Origin-Opener-Policy", value.to_string());
2798      };
2799
2800      // Add the header Cross-Origin-Resource-Policy, if we find a value for it
2801      if let Some(value) = &headers.cross_origin_resource_policy {
2802        self = self.header("Cross-Origin-Resource-Policy", value.to_string());
2803      };
2804
2805      // Add the header Permissions-Policy, if we find a value for it
2806      if let Some(value) = &headers.permissions_policy {
2807        self = self.header("Permissions-Policy", value.to_string());
2808      };
2809
2810      if let Some(value) = &headers.service_worker_allowed {
2811        self = self.header("Service-Worker-Allowed", value.to_string());
2812      }
2813
2814      // Add the header Timing-Allow-Origin, if we find a value for it
2815      if let Some(value) = &headers.timing_allow_origin {
2816        self = self.header("Timing-Allow-Origin", value.to_string());
2817      };
2818
2819      // Add the header X-Content-Type-Options, if we find a value for it
2820      if let Some(value) = &headers.x_content_type_options {
2821        self = self.header("X-Content-Type-Options", value.to_string());
2822      };
2823
2824      // Add the header Tauri-Custom-Header, if we find a value for it
2825      if let Some(value) = &headers.tauri_custom_header {
2826        // Keep in mind to correctly set the Access-Control-Expose-Headers
2827        self = self.header("Tauri-Custom-Header", value.to_string());
2828      };
2829    }
2830    self
2831  }
2832}
2833
2834/// A struct, where the keys are some specific http header names.
2835///
2836/// If the values to those keys are defined, then they will be send as part of a response message.
2837/// This does not include error messages and ipc messages
2838///
2839/// ## Example configuration
2840/// ```javascript
2841/// {
2842///  //..
2843///   app:{
2844///     //..
2845///     security: {
2846///       headers: {
2847///         "Cross-Origin-Opener-Policy": "same-origin",
2848///         "Cross-Origin-Embedder-Policy": "require-corp",
2849///         "Timing-Allow-Origin": [
2850///           "https://developer.mozilla.org",
2851///           "https://example.com",
2852///         ],
2853///         "Access-Control-Expose-Headers": "Tauri-Custom-Header",
2854///         "Tauri-Custom-Header": {
2855///           "key1": "'value1' 'value2'",
2856///           "key2": "'value3'"
2857///         }
2858///       },
2859///       csp: "default-src 'self'; connect-src ipc: http://ipc.localhost",
2860///     }
2861///     //..
2862///   }
2863///  //..
2864/// }
2865/// ```
2866/// In this example `Cross-Origin-Opener-Policy` and `Cross-Origin-Embedder-Policy` are set to allow for the use of [`SharedArrayBuffer`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer).
2867/// The result is, that those headers are then set on every response sent via the `get_response` function in crates/tauri/src/protocol/tauri.rs.
2868/// The Content-Security-Policy header is defined separately, because it is also handled separately.
2869///
2870/// For the helloworld example, this config translates into those response headers:
2871/// ```http
2872/// access-control-allow-origin:  http://tauri.localhost
2873/// access-control-expose-headers: Tauri-Custom-Header
2874/// content-security-policy: default-src 'self'; connect-src ipc: http://ipc.localhost; script-src 'self' 'sha256-Wjjrs6qinmnr+tOry8x8PPwI77eGpUFR3EEGZktjJNs='
2875/// content-type: text/html
2876/// cross-origin-embedder-policy: require-corp
2877/// cross-origin-opener-policy: same-origin
2878/// tauri-custom-header: key1 'value1' 'value2'; key2 'value3'
2879/// timing-allow-origin: https://developer.mozilla.org, https://example.com
2880/// ```
2881/// Since the resulting header values are always 'string-like'. So depending on the what data type the HeaderSource is, they need to be converted.
2882///  - `String`(JS/Rust): stay the same for the resulting header value
2883///  - `Array`(JS)/`Vec\<String\>`(Rust): Item are joined by ", " for the resulting header value
2884///  - `Object`(JS)/ `Hashmap\<String,String\>`(Rust): Items are composed from: key + space + value. Item are then joined by "; " for the resulting header value
2885#[derive(Debug, Default, PartialEq, Eq, Clone, Deserialize, Serialize)]
2886#[cfg_attr(feature = "schema", derive(JsonSchema))]
2887#[serde(deny_unknown_fields)]
2888pub struct HeaderConfig {
2889  /// The Access-Control-Allow-Credentials response header tells browsers whether the
2890  /// server allows cross-origin HTTP requests to include credentials.
2891  ///
2892  /// See <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Allow-Credentials>
2893  #[serde(rename = "Access-Control-Allow-Credentials")]
2894  pub access_control_allow_credentials: Option<HeaderSource>,
2895  /// The Access-Control-Allow-Headers response header is used in response
2896  /// to a preflight request which includes the Access-Control-Request-Headers
2897  /// to indicate which HTTP headers can be used during the actual request.
2898  ///
2899  /// This header is required if the request has an Access-Control-Request-Headers header.
2900  ///
2901  /// See <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Allow-Headers>
2902  #[serde(rename = "Access-Control-Allow-Headers")]
2903  pub access_control_allow_headers: Option<HeaderSource>,
2904  /// The Access-Control-Allow-Methods response header specifies one or more methods
2905  /// allowed when accessing a resource in response to a preflight request.
2906  ///
2907  /// See <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Allow-Methods>
2908  #[serde(rename = "Access-Control-Allow-Methods")]
2909  pub access_control_allow_methods: Option<HeaderSource>,
2910  /// The Access-Control-Expose-Headers response header allows a server to indicate
2911  /// which response headers should be made available to scripts running in the browser,
2912  /// in response to a cross-origin request.
2913  ///
2914  /// See <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Expose-Headers>
2915  #[serde(rename = "Access-Control-Expose-Headers")]
2916  pub access_control_expose_headers: Option<HeaderSource>,
2917  /// The Access-Control-Max-Age response header indicates how long the results of a
2918  /// preflight request (that is the information contained in the
2919  /// Access-Control-Allow-Methods and Access-Control-Allow-Headers headers) can
2920  /// be cached.
2921  ///
2922  /// See <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Max-Age>
2923  #[serde(rename = "Access-Control-Max-Age")]
2924  pub access_control_max_age: Option<HeaderSource>,
2925  /// The HTTP Cross-Origin-Embedder-Policy (COEP) response header configures embedding
2926  /// cross-origin resources into the document.
2927  ///
2928  /// See <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cross-Origin-Embedder-Policy>
2929  #[serde(rename = "Cross-Origin-Embedder-Policy")]
2930  pub cross_origin_embedder_policy: Option<HeaderSource>,
2931  /// The HTTP Cross-Origin-Opener-Policy (COOP) response header allows you to ensure a
2932  /// top-level document does not share a browsing context group with cross-origin documents.
2933  /// COOP will process-isolate your document and potential attackers can't access your global
2934  /// object if they were to open it in a popup, preventing a set of cross-origin attacks dubbed XS-Leaks.
2935  ///
2936  /// See <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cross-Origin-Opener-Policy>
2937  #[serde(rename = "Cross-Origin-Opener-Policy")]
2938  pub cross_origin_opener_policy: Option<HeaderSource>,
2939  /// The HTTP Cross-Origin-Resource-Policy response header conveys a desire that the
2940  /// browser blocks no-cors cross-origin/cross-site requests to the given resource.
2941  ///
2942  /// See <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cross-Origin-Resource-Policy>
2943  #[serde(rename = "Cross-Origin-Resource-Policy")]
2944  pub cross_origin_resource_policy: Option<HeaderSource>,
2945  /// The HTTP Permissions-Policy header provides a mechanism to allow and deny the
2946  /// use of browser features in a document or within any \<iframe\> elements in the document.
2947  ///
2948  /// See <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Permissions-Policy>
2949  #[serde(rename = "Permissions-Policy")]
2950  pub permissions_policy: Option<HeaderSource>,
2951  /// The HTTP Service-Worker-Allowed response header is used to broaden the path restriction for a
2952  /// service worker's default scope.
2953  ///
2954  /// By default, the scope for a service worker registration is the directory where the service
2955  /// worker script is located. For example, if the script `sw.js` is located in `/js/sw.js`,
2956  /// it can only control URLs under `/js/` by default. Servers can use the `Service-Worker-Allowed`
2957  /// header to allow a service worker to control URLs outside of its own directory.
2958  ///
2959  /// See <https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Service-Worker-Allowed>
2960  #[serde(rename = "Service-Worker-Allowed")]
2961  pub service_worker_allowed: Option<HeaderSource>,
2962  /// The Timing-Allow-Origin response header specifies origins that are allowed to see values
2963  /// of attributes retrieved via features of the Resource Timing API, which would otherwise be
2964  /// reported as zero due to cross-origin restrictions.
2965  ///
2966  /// See <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Timing-Allow-Origin>
2967  #[serde(rename = "Timing-Allow-Origin")]
2968  pub timing_allow_origin: Option<HeaderSource>,
2969  /// The X-Content-Type-Options response HTTP header is a marker used by the server to indicate
2970  /// that the MIME types advertised in the Content-Type headers should be followed and not be
2971  /// changed. The header allows you to avoid MIME type sniffing by saying that the MIME types
2972  /// are deliberately configured.
2973  ///
2974  /// See <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Content-Type-Options>
2975  #[serde(rename = "X-Content-Type-Options")]
2976  pub x_content_type_options: Option<HeaderSource>,
2977  /// A custom header field Tauri-Custom-Header, don't use it.
2978  /// Remember to set Access-Control-Expose-Headers accordingly
2979  ///
2980  /// **NOT INTENDED FOR PRODUCTION USE**
2981  #[serde(rename = "Tauri-Custom-Header")]
2982  pub tauri_custom_header: Option<HeaderSource>,
2983}
2984
2985impl HeaderConfig {
2986  /// creates a new header config
2987  pub fn new() -> Self {
2988    HeaderConfig {
2989      access_control_allow_credentials: None,
2990      access_control_allow_methods: None,
2991      access_control_allow_headers: None,
2992      access_control_expose_headers: None,
2993      access_control_max_age: None,
2994      cross_origin_embedder_policy: None,
2995      cross_origin_opener_policy: None,
2996      cross_origin_resource_policy: None,
2997      permissions_policy: None,
2998      service_worker_allowed: None,
2999      timing_allow_origin: None,
3000      x_content_type_options: None,
3001      tauri_custom_header: None,
3002    }
3003  }
3004}
3005
3006/// Security configuration.
3007///
3008/// See more: <https://v2.tauri.app/reference/config/#securityconfig>
3009#[skip_serializing_none]
3010#[derive(Debug, Default, PartialEq, Clone, Deserialize, Serialize)]
3011#[cfg_attr(feature = "schema", derive(JsonSchema))]
3012#[serde(rename_all = "camelCase", deny_unknown_fields)]
3013pub struct SecurityConfig {
3014  /// The Content Security Policy that will be injected on all HTML files on the built application.
3015  /// If [`dev_csp`](#SecurityConfig.devCsp) is not specified, this value is also injected on dev.
3016  ///
3017  /// This is a really important part of the configuration since it helps you ensure your WebView is secured.
3018  /// See <https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP>.
3019  pub csp: Option<Csp>,
3020  /// The Content Security Policy that will be injected on all HTML files on development.
3021  ///
3022  /// This is a really important part of the configuration since it helps you ensure your WebView is secured.
3023  /// See <https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP>.
3024  #[serde(alias = "dev-csp")]
3025  pub dev_csp: Option<Csp>,
3026  /// Freeze the `Object.prototype` when using the custom protocol.
3027  #[serde(default, alias = "freeze-prototype")]
3028  pub freeze_prototype: bool,
3029  /// Disables the Tauri-injected CSP sources.
3030  ///
3031  /// At compile time, Tauri parses all the frontend assets and changes the Content-Security-Policy
3032  /// to only allow loading of your own scripts and styles by injecting nonce and hash sources.
3033  /// This stricts your CSP, which may introduce issues when using along with other flexing sources.
3034  ///
3035  /// This configuration option allows both a boolean and a list of strings as value.
3036  /// A boolean instructs Tauri to disable the injection for all CSP injections,
3037  /// and a list of strings indicates the CSP directives that Tauri cannot inject.
3038  ///
3039  /// **WARNING:** Only disable this if you know what you are doing and have properly configured the CSP.
3040  /// Your application might be vulnerable to XSS attacks without this Tauri protection.
3041  #[serde(default, alias = "dangerous-disable-asset-csp-modification")]
3042  pub dangerous_disable_asset_csp_modification: DisabledCspModificationKind,
3043  /// Custom protocol config.
3044  #[serde(default, alias = "asset-protocol")]
3045  pub asset_protocol: AssetProtocolConfig,
3046  /// The pattern to use.
3047  #[serde(default)]
3048  pub pattern: PatternKind,
3049  /// List of capabilities that are enabled on the application.
3050  ///
3051  /// By default (not set or empty list), all capability files from `./capabilities/` are included,
3052  /// by setting values in this entry, you have fine grained control over which capabilities are included
3053  ///
3054  /// You can either reference a capability file defined in `./capabilities/` with its identifier or inline a [`Capability`]
3055  ///
3056  /// ### Example
3057  ///
3058  /// ```json
3059  /// {
3060  ///   "app": {
3061  ///     "capabilities": [
3062  ///       "main-window",
3063  ///       {
3064  ///         "identifier": "drag-window",
3065  ///         "permissions": ["core:window:allow-start-dragging"]
3066  ///       }
3067  ///     ]
3068  ///   }
3069  /// }
3070  /// ```
3071  #[serde(default)]
3072  pub capabilities: Vec<CapabilityEntry>,
3073  /// The headers, which are added to every http response from tauri to the web view
3074  /// This doesn't include IPC Messages and error responses
3075  #[serde(default)]
3076  pub headers: Option<HeaderConfig>,
3077}
3078
3079/// A capability entry which can be either an inlined capability or a reference to a capability defined on its own file.
3080#[derive(Debug, Clone, PartialEq, Serialize)]
3081#[cfg_attr(feature = "schema", derive(JsonSchema))]
3082#[serde(untagged)]
3083pub enum CapabilityEntry {
3084  /// An inlined capability.
3085  Inlined(Capability),
3086  /// Reference to a capability identifier.
3087  Reference(String),
3088}
3089
3090impl<'de> Deserialize<'de> for CapabilityEntry {
3091  fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
3092  where
3093    D: Deserializer<'de>,
3094  {
3095    UntaggedEnumVisitor::new()
3096      .string(|string| Ok(Self::Reference(string.to_owned())))
3097      .map(|map| map.deserialize::<Capability>().map(Self::Inlined))
3098      .deserialize(deserializer)
3099  }
3100}
3101
3102/// The application pattern.
3103#[skip_serializing_none]
3104#[derive(Debug, PartialEq, Eq, Clone, Serialize, Deserialize, Default)]
3105#[serde(rename_all = "lowercase", tag = "use", content = "options")]
3106#[cfg_attr(feature = "schema", derive(JsonSchema))]
3107pub enum PatternKind {
3108  /// Brownfield pattern.
3109  #[default]
3110  Brownfield,
3111  /// Isolation pattern. Recommended for security purposes.
3112  Isolation {
3113    /// The dir containing the index.html file that contains the secure isolation application.
3114    dir: PathBuf,
3115  },
3116}
3117
3118/// The App configuration object.
3119///
3120/// See more: <https://v2.tauri.app/reference/config/#appconfig>
3121#[skip_serializing_none]
3122#[derive(Debug, Default, PartialEq, Clone, Deserialize, Serialize)]
3123#[cfg_attr(feature = "schema", derive(JsonSchema))]
3124#[serde(rename_all = "camelCase", deny_unknown_fields)]
3125pub struct AppConfig {
3126  /// The app windows configuration.
3127  ///
3128  /// ## Example:
3129  ///
3130  /// To create a window at app startup
3131  ///
3132  /// ```json
3133  /// {
3134  ///   "app": {
3135  ///     "windows": [
3136  ///       { "width": 800, "height": 600 }
3137  ///     ]
3138  ///   }
3139  /// }
3140  /// ```
3141  ///
3142  /// If not specified, the window's label (its identifier) defaults to "main",
3143  /// you can use this label to get the window through
3144  /// `app.get_webview_window` in Rust or `WebviewWindow.getByLabel` in JavaScript
3145  ///
3146  /// When working with multiple windows, each window will need an unique label
3147  ///
3148  /// ```json
3149  /// {
3150  ///   "app": {
3151  ///     "windows": [
3152  ///       { "label": "main", "width": 800, "height": 600 },
3153  ///       { "label": "secondary", "width": 800, "height": 600 }
3154  ///     ]
3155  ///   }
3156  /// }
3157  /// ```
3158  ///
3159  /// You can also set `create` to false and use this config through the Rust APIs
3160  ///
3161  /// ```json
3162  /// {
3163  ///   "app": {
3164  ///     "windows": [
3165  ///       { "create": false, "width": 800, "height": 600 }
3166  ///     ]
3167  ///   }
3168  /// }
3169  /// ```
3170  ///
3171  /// and use it like this
3172  ///
3173  /// ```rust
3174  /// tauri::Builder::default()
3175  ///   .setup(|app| {
3176  ///     tauri::WebviewWindowBuilder::from_config(app.handle(), &app.config().app.windows[0])?.build()?;
3177  ///     Ok(())
3178  ///   });
3179  /// ```
3180  #[serde(default)]
3181  pub windows: Vec<WindowConfig>,
3182  /// Security configuration.
3183  #[serde(default)]
3184  pub security: SecurityConfig,
3185  /// Configuration for app tray icon.
3186  #[serde(alias = "tray-icon")]
3187  pub tray_icon: Option<TrayIconConfig>,
3188  /// MacOS private API configuration. Enables the transparent background API and sets the `fullScreenEnabled` preference to `true`.
3189  #[serde(rename = "macOSPrivateApi", alias = "macos-private-api", default)]
3190  pub macos_private_api: bool,
3191  /// Whether we should inject the Tauri API on `window.__TAURI__` or not.
3192  #[serde(default, alias = "with-global-tauri")]
3193  pub with_global_tauri: bool,
3194  /// If set to true "identifier" will be set as GTK app ID (on systems that use GTK).
3195  #[serde(rename = "enableGTKAppId", alias = "enable-gtk-app-id", default)]
3196  pub enable_gtk_app_id: bool,
3197}
3198
3199impl AppConfig {
3200  /// Returns all Cargo features.
3201  pub fn all_features() -> Vec<&'static str> {
3202    vec![
3203      "tray-icon",
3204      "macos-private-api",
3205      "protocol-asset",
3206      "isolation",
3207    ]
3208  }
3209
3210  /// Returns the enabled Cargo features.
3211  pub fn features(&self) -> Vec<&str> {
3212    let mut features = Vec::new();
3213    if self.tray_icon.is_some() {
3214      features.push("tray-icon");
3215    }
3216    if self.macos_private_api {
3217      features.push("macos-private-api");
3218    }
3219    if self.security.asset_protocol.enable {
3220      features.push("protocol-asset");
3221    }
3222
3223    if let PatternKind::Isolation { .. } = self.security.pattern {
3224      features.push("isolation");
3225    }
3226
3227    features.sort_unstable();
3228    features
3229  }
3230}
3231
3232/// Configuration for application tray icon.
3233///
3234/// See more: <https://v2.tauri.app/reference/config/#trayiconconfig>
3235#[skip_serializing_none]
3236#[derive(Debug, Default, PartialEq, Eq, Clone, Deserialize, Serialize)]
3237#[cfg_attr(feature = "schema", derive(JsonSchema))]
3238#[serde(rename_all = "camelCase", deny_unknown_fields)]
3239pub struct TrayIconConfig {
3240  /// Set an id for this tray icon so you can reference it later, defaults to `main`.
3241  pub id: Option<String>,
3242  /// Path to the default icon to use for the tray icon.
3243  ///
3244  /// Note: this stores the image in raw pixels to the final binary,
3245  /// so keep the icon size (width and height) small
3246  /// or else it's going to bloat your final executable
3247  #[serde(alias = "icon-path")]
3248  pub icon_path: PathBuf,
3249  /// A Boolean value that determines whether the image represents a [template](https://developer.apple.com/documentation/appkit/nsimage/1520017-template?language=objc) image on macOS.
3250  #[serde(default, alias = "icon-as-template")]
3251  pub icon_as_template: bool,
3252  /// **No longer works since v2.2, use [`Self::show_menu_on_left_click`] instead**
3253  ///
3254  /// A Boolean value that determines whether the menu should appear when the tray icon receives a left click.
3255  ///
3256  /// ## Platform-specific:
3257  ///
3258  /// - **Linux**: Unsupported.
3259  #[serde(default = "default_true", alias = "menu-on-left-click")]
3260  #[deprecated(
3261    since = "2.2.0",
3262    note = "No longer works, use `show_menu_on_left_click` instead."
3263  )]
3264  pub menu_on_left_click: bool,
3265  /// A Boolean value that determines whether the menu should appear when the tray icon receives a left click.
3266  ///
3267  /// ## Platform-specific:
3268  ///
3269  /// - **Linux**: Unsupported.
3270  #[serde(default = "default_true", alias = "show-menu-on-left-click")]
3271  pub show_menu_on_left_click: bool,
3272  /// Title for MacOS tray
3273  pub title: Option<String>,
3274  /// Tray icon tooltip on Windows and macOS
3275  pub tooltip: Option<String>,
3276}
3277
3278/// General configuration for the iOS target.
3279#[skip_serializing_none]
3280#[derive(Debug, PartialEq, Eq, Clone, Deserialize, Serialize)]
3281#[cfg_attr(feature = "schema", derive(JsonSchema))]
3282#[serde(rename_all = "camelCase", deny_unknown_fields)]
3283pub struct IosConfig {
3284  /// A custom [XcodeGen] project.yml template to use.
3285  ///
3286  /// [XcodeGen]: <https://github.com/yonaskolb/XcodeGen>
3287  pub template: Option<PathBuf>,
3288  /// A list of strings indicating any iOS frameworks that need to be bundled with the application.
3289  ///
3290  /// Note that you need to recreate the iOS project for the changes to be applied.
3291  pub frameworks: Option<Vec<String>>,
3292  /// The development team. This value is required for iOS development because code signing is enforced.
3293  /// The `APPLE_DEVELOPMENT_TEAM` environment variable can be set to overwrite it.
3294  #[serde(alias = "development-team")]
3295  pub development_team: Option<String>,
3296  /// The version of the build that identifies an iteration of the bundle.
3297  ///
3298  /// Translates to the bundle's CFBundleVersion property.
3299  #[serde(alias = "bundle-version")]
3300  pub bundle_version: Option<String>,
3301  /// A version string indicating the minimum iOS version that the bundled application supports. Defaults to `15.0`.
3302  ///
3303  /// Maps to the IPHONEOS_DEPLOYMENT_TARGET value.
3304  #[serde(
3305    alias = "minimum-system-version",
3306    default = "ios_minimum_system_version"
3307  )]
3308  pub minimum_system_version: String,
3309  /// Path to a Info.plist file to merge with the default Info.plist.
3310  ///
3311  /// Note that Tauri also looks for a `Info.plist` and `Info.ios.plist` file in the same directory as the Tauri configuration file.
3312  #[serde(alias = "info-plist")]
3313  pub info_plist: Option<PathBuf>,
3314}
3315
3316impl Default for IosConfig {
3317  fn default() -> Self {
3318    Self {
3319      template: None,
3320      frameworks: None,
3321      development_team: None,
3322      bundle_version: None,
3323      minimum_system_version: ios_minimum_system_version(),
3324      info_plist: None,
3325    }
3326  }
3327}
3328
3329/// General configuration for the Android target.
3330#[skip_serializing_none]
3331#[derive(Debug, PartialEq, Eq, Clone, Deserialize, Serialize)]
3332#[cfg_attr(feature = "schema", derive(JsonSchema))]
3333#[serde(rename_all = "camelCase", deny_unknown_fields)]
3334pub struct AndroidConfig {
3335  /// The minimum API level required for the application to run.
3336  /// The Android system will prevent the user from installing the application if the system's API level is lower than the value specified.
3337  #[serde(alias = "min-sdk-version", default = "default_min_sdk_version")]
3338  pub min_sdk_version: u32,
3339
3340  /// The version code of the application.
3341  /// It is limited to 2,100,000,000 as per Google Play Store requirements.
3342  ///
3343  /// By default we use your configured version and perform the following math:
3344  /// versionCode = version.major * 1000000 + version.minor * 1000 + version.patch
3345  #[serde(alias = "version-code")]
3346  #[cfg_attr(feature = "schema", validate(range(min = 1, max = 2_100_000_000)))]
3347  pub version_code: Option<u32>,
3348
3349  /// Whether to automatically increment the `versionCode` on each build.
3350  ///
3351  /// - If `true`, the generator will try to read the last `versionCode` from
3352  ///   `tauri.properties` and increment it by 1 for every build.
3353  /// - If `false` or not set, it falls back to `version_code` or semver-derived logic.
3354  ///
3355  /// Note that to use this feature, you should remove `/tauri.properties` from `src-tauri/gen/android/app/.gitignore` so the current versionCode is committed to the repository.
3356  #[serde(alias = "auto-increment-version-code", default)]
3357  pub auto_increment_version_code: bool,
3358
3359  /// Application ID suffix to append for debug builds.
3360  /// This allows installing debug and release versions side-by-side on the same device.
3361  /// Example: ".debug" will make debug builds use "com.example.app.debug" as the application ID.
3362  #[serde(alias = "debug-application-id-suffix")]
3363  pub debug_application_id_suffix: Option<String>,
3364}
3365
3366impl Default for AndroidConfig {
3367  fn default() -> Self {
3368    Self {
3369      min_sdk_version: default_min_sdk_version(),
3370      version_code: None,
3371      auto_increment_version_code: false,
3372      debug_application_id_suffix: None,
3373    }
3374  }
3375}
3376
3377fn default_min_sdk_version() -> u32 {
3378  24
3379}
3380
3381/// Defines the URL or assets to embed in the application.
3382#[derive(Debug, PartialEq, Eq, Clone, Deserialize, Serialize)]
3383#[cfg_attr(feature = "schema", derive(JsonSchema))]
3384#[serde(untagged, deny_unknown_fields)]
3385#[non_exhaustive]
3386pub enum FrontendDist {
3387  /// An external URL that should be used as the default application URL. No assets are embedded in the app in this case.
3388  Url(Url),
3389  /// Path to a directory containing the frontend dist assets.
3390  Directory(PathBuf),
3391  /// An array of files to embed in the app.
3392  Files(Vec<PathBuf>),
3393}
3394
3395impl std::fmt::Display for FrontendDist {
3396  fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
3397    match self {
3398      Self::Url(url) => write!(f, "{url}"),
3399      Self::Directory(p) => write!(f, "{}", p.display()),
3400      Self::Files(files) => write!(f, "{}", serde_json::to_string(files).unwrap()),
3401    }
3402  }
3403}
3404
3405/// Describes the shell command to run before `tauri dev`.
3406#[derive(Debug, PartialEq, Eq, Clone, Deserialize, Serialize)]
3407#[cfg_attr(feature = "schema", derive(JsonSchema))]
3408#[serde(rename_all = "camelCase", untagged)]
3409pub enum BeforeDevCommand {
3410  /// Run the given script with the default options.
3411  Script(String),
3412  /// Run the given script with custom options.
3413  ScriptWithOptions {
3414    /// The script to execute.
3415    script: String,
3416    /// The current working directory.
3417    cwd: Option<String>,
3418    /// Whether `tauri dev` should wait for the command to finish or not. Defaults to `false`.
3419    #[serde(default)]
3420    wait: bool,
3421  },
3422}
3423
3424/// Describes a shell command to be executed when a CLI hook is triggered.
3425#[derive(Debug, PartialEq, Eq, Clone, Deserialize, Serialize)]
3426#[cfg_attr(feature = "schema", derive(JsonSchema))]
3427#[serde(rename_all = "camelCase", untagged)]
3428pub enum HookCommand {
3429  /// Run the given script with the default options.
3430  Script(String),
3431  /// Run the given script with custom options.
3432  ScriptWithOptions {
3433    /// The script to execute.
3434    script: String,
3435    /// The current working directory.
3436    cwd: Option<String>,
3437  },
3438}
3439
3440/// The runner configuration.
3441#[skip_serializing_none]
3442#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
3443#[cfg_attr(feature = "schema", derive(JsonSchema))]
3444#[serde(untagged)]
3445pub enum RunnerConfig {
3446  /// A string specifying the binary to run.
3447  String(String),
3448  /// An object with advanced configuration options.
3449  Object {
3450    /// The binary to run.
3451    cmd: String,
3452    /// The current working directory to run the command from.
3453    cwd: Option<String>,
3454    /// Arguments to pass to the command.
3455    args: Option<Vec<String>>,
3456  },
3457}
3458
3459impl Default for RunnerConfig {
3460  fn default() -> Self {
3461    RunnerConfig::String("cargo".to_string())
3462  }
3463}
3464
3465impl RunnerConfig {
3466  /// Returns the command to run.
3467  pub fn cmd(&self) -> &str {
3468    match self {
3469      RunnerConfig::String(cmd) => cmd,
3470      RunnerConfig::Object { cmd, .. } => cmd,
3471    }
3472  }
3473
3474  /// Returns the working directory.
3475  pub fn cwd(&self) -> Option<&str> {
3476    match self {
3477      RunnerConfig::String(_) => None,
3478      RunnerConfig::Object { cwd, .. } => cwd.as_deref(),
3479    }
3480  }
3481
3482  /// Returns the arguments.
3483  pub fn args(&self) -> Option<&[String]> {
3484    match self {
3485      RunnerConfig::String(_) => None,
3486      RunnerConfig::Object { args, .. } => args.as_deref(),
3487    }
3488  }
3489}
3490
3491impl std::str::FromStr for RunnerConfig {
3492  type Err = std::convert::Infallible;
3493
3494  fn from_str(s: &str) -> Result<Self, Self::Err> {
3495    Ok(RunnerConfig::String(s.to_string()))
3496  }
3497}
3498
3499impl From<&str> for RunnerConfig {
3500  fn from(s: &str) -> Self {
3501    RunnerConfig::String(s.to_string())
3502  }
3503}
3504
3505impl From<String> for RunnerConfig {
3506  fn from(s: String) -> Self {
3507    RunnerConfig::String(s)
3508  }
3509}
3510
3511/// The Build configuration object.
3512///
3513/// See more: <https://v2.tauri.app/reference/config/#buildconfig>
3514#[skip_serializing_none]
3515#[derive(Debug, PartialEq, Eq, Clone, Deserialize, Serialize, Default)]
3516#[cfg_attr(feature = "schema", derive(JsonSchema))]
3517#[serde(rename_all = "camelCase", deny_unknown_fields)]
3518pub struct BuildConfig {
3519  /// The binary used to build and run the application.
3520  pub runner: Option<RunnerConfig>,
3521  /// The URL to load in development.
3522  ///
3523  /// This is usually an URL to a dev server, which serves your application assets with hot-reload and HMR.
3524  /// Most modern JavaScript bundlers like [Vite](https://vite.dev/guide/) provides a way to start a dev server by default.
3525  ///
3526  /// If you don't have a dev server or don't want to use one, ignore this option and use [`frontendDist`](BuildConfig::frontend_dist)
3527  /// and point to a web assets directory, and Tauri CLI will run its built-in dev server and provide a simple hot-reload experience.
3528  #[serde(alias = "dev-url")]
3529  pub dev_url: Option<Url>,
3530  /// The path to the application assets (usually the `dist` folder of your javascript bundler)
3531  /// or a URL that could be either a custom protocol registered in the tauri app (for example: `myprotocol://`)
3532  /// or a remote URL (for example: `https://site.com/app`).
3533  ///
3534  /// When a path relative to the configuration file is provided,
3535  /// it is read recursively and all files are embedded in the application binary.
3536  /// Tauri then looks for an `index.html` and serves it as the default entry point for your application.
3537  ///
3538  /// You can also provide a list of paths to be embedded, which allows granular control over what files are added to the binary.
3539  /// In this case, all files are added to the root and you must reference it that way in your HTML files.
3540  ///
3541  /// When a URL is provided, the application won't have bundled assets
3542  /// and the application will load that URL by default.
3543  #[serde(alias = "frontend-dist")]
3544  pub frontend_dist: Option<FrontendDist>,
3545  /// A shell command to run before `tauri dev` kicks in.
3546  ///
3547  /// The TAURI_ENV_PLATFORM, TAURI_ENV_ARCH, TAURI_ENV_FAMILY, TAURI_ENV_PLATFORM_VERSION, TAURI_ENV_PLATFORM_TYPE and TAURI_ENV_DEBUG environment variables are set if you perform conditional compilation.
3548  #[serde(alias = "before-dev-command")]
3549  pub before_dev_command: Option<BeforeDevCommand>,
3550  /// A shell command to run before `tauri build` kicks in.
3551  ///
3552  /// The TAURI_ENV_PLATFORM, TAURI_ENV_ARCH, TAURI_ENV_FAMILY, TAURI_ENV_PLATFORM_VERSION, TAURI_ENV_PLATFORM_TYPE and TAURI_ENV_DEBUG environment variables are set if you perform conditional compilation.
3553  #[serde(alias = "before-build-command")]
3554  pub before_build_command: Option<HookCommand>,
3555  /// A shell command to run before the bundling phase in `tauri build` kicks in.
3556  ///
3557  /// The TAURI_ENV_PLATFORM, TAURI_ENV_ARCH, TAURI_ENV_FAMILY, TAURI_ENV_PLATFORM_VERSION, TAURI_ENV_PLATFORM_TYPE and TAURI_ENV_DEBUG environment variables are set if you perform conditional compilation.
3558  #[serde(alias = "before-bundle-command")]
3559  pub before_bundle_command: Option<HookCommand>,
3560  /// Features passed to `cargo` commands.
3561  pub features: Option<Vec<String>>,
3562  /// Try to remove unused commands registered from plugins base on the ACL list during `tauri build`,
3563  /// the way it works is that tauri-cli will read this and set the environment variables for the build script and macros,
3564  /// and they'll try to get all the allowed commands and remove the rest
3565  ///
3566  /// Note:
3567  ///   - This won't be accounting for dynamically added ACLs when you use features from the `dynamic-acl` (currently enabled by default) feature flag, so make sure to check it when using this
3568  ///   - This feature requires tauri-plugin 2.1 and tauri 2.4
3569  #[serde(alias = "remove-unused-commands", default)]
3570  pub remove_unused_commands: bool,
3571  /// Additional paths to watch for changes when running `tauri dev`.
3572  #[serde(
3573    alias = "additional-watch-folders",
3574    alias = "additional-watch-directories",
3575    default
3576  )]
3577  pub additional_watch_folders: Vec<PathBuf>,
3578  /// Windows-specific build configuration.
3579  #[serde(default)]
3580  pub windows: WindowsBuildConfig,
3581}
3582
3583/// Windows-specific build configuration.
3584#[derive(Debug, PartialEq, Eq, Clone, Deserialize, Serialize)]
3585#[cfg_attr(feature = "schema", derive(JsonSchema))]
3586#[serde(rename_all = "camelCase", deny_unknown_fields)]
3587pub struct WindowsBuildConfig {
3588  /// Whether to statically link the Visual C++ runtime into the application binary on Windows MSVC targets.
3589  #[serde(
3590    default = "default_true",
3591    rename = "staticVCRuntime",
3592    alias = "static-vc-runtime",
3593    alias = "staticVcRuntime"
3594  )]
3595  pub static_vc_runtime: bool,
3596}
3597
3598impl Default for WindowsBuildConfig {
3599  fn default() -> Self {
3600    Self {
3601      static_vc_runtime: true,
3602    }
3603  }
3604}
3605
3606#[derive(Debug, PartialEq, Eq)]
3607struct PackageVersion(String);
3608
3609impl<'d> serde::Deserialize<'d> for PackageVersion {
3610  fn deserialize<D: Deserializer<'d>>(deserializer: D) -> Result<Self, D::Error> {
3611    struct PackageVersionVisitor;
3612
3613    impl Visitor<'_> for PackageVersionVisitor {
3614      type Value = PackageVersion;
3615
3616      fn expecting(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
3617        write!(
3618          formatter,
3619          "a semver string or a path to a package.json file"
3620        )
3621      }
3622
3623      fn visit_str<E: DeError>(self, value: &str) -> Result<PackageVersion, E> {
3624        let path = PathBuf::from(value);
3625        if path.exists() {
3626          let json_str = read_to_string(&path)
3627            .map_err(|e| DeError::custom(format!("failed to read version JSON file: {e}")))?;
3628          let package_json: serde_json::Value = serde_json::from_str(&json_str)
3629            .map_err(|e| DeError::custom(format!("failed to read version JSON file: {e}")))?;
3630          if let Some(obj) = package_json.as_object() {
3631            let version = obj
3632              .get("version")
3633              .ok_or_else(|| DeError::custom("JSON must contain a `version` field"))?
3634              .as_str()
3635              .ok_or_else(|| {
3636                DeError::custom(format!("`{} > version` must be a string", path.display()))
3637              })?;
3638            Ok(PackageVersion(
3639              Version::from_str(version)
3640                .map_err(|_| {
3641                  DeError::custom("`tauri.conf.json > version` must be a semver string")
3642                })?
3643                .to_string(),
3644            ))
3645          } else {
3646            Err(DeError::custom(
3647              "`tauri.conf.json > version` value is not a path to a JSON object",
3648            ))
3649          }
3650        } else {
3651          Ok(PackageVersion(
3652            Version::from_str(value)
3653              .map_err(|_| DeError::custom("`tauri.conf.json > version` must be a semver string"))?
3654              .to_string(),
3655          ))
3656        }
3657      }
3658    }
3659
3660    deserializer.deserialize_string(PackageVersionVisitor {})
3661  }
3662}
3663
3664fn version_deserializer<'de, D>(deserializer: D) -> Result<Option<String>, D::Error>
3665where
3666  D: Deserializer<'de>,
3667{
3668  Option::<PackageVersion>::deserialize(deserializer).map(|v| v.map(|v| v.0))
3669}
3670
3671/// The Tauri configuration object.
3672/// It is read from a file where you can define your frontend assets,
3673/// configure the bundler and define a tray icon.
3674///
3675/// The configuration file is generated by the
3676/// [`tauri init`](https://v2.tauri.app/reference/cli/#init) command that lives in
3677/// your Tauri application source directory (src-tauri).
3678///
3679/// Once generated, you may modify it at will to customize your Tauri application.
3680///
3681/// ## File Formats
3682///
3683/// By default, the configuration is defined as a JSON file named `tauri.conf.json`.
3684///
3685/// Tauri also supports JSON5 and TOML files via the `config-json5` and `config-toml` Cargo features, respectively.
3686/// The JSON5 file name must be either `tauri.conf.json` or `tauri.conf.json5`.
3687/// The TOML file name is `Tauri.toml`.
3688///
3689/// ## Platform-Specific Configuration
3690///
3691/// In addition to the default configuration file, Tauri can
3692/// read a platform-specific configuration from `tauri.linux.conf.json`,
3693/// `tauri.windows.conf.json`, `tauri.macos.conf.json`, `tauri.android.conf.json` and `tauri.ios.conf.json`
3694/// (or `Tauri.linux.toml`, `Tauri.windows.toml`, `Tauri.macos.toml`, `Tauri.android.toml` and `Tauri.ios.toml` if the `Tauri.toml` format is used),
3695/// which gets merged with the main configuration object.
3696///
3697/// ## Configuration Structure
3698///
3699/// The configuration is composed of the following objects:
3700///
3701/// - [`app`](#appconfig): The Tauri configuration
3702/// - [`build`](#buildconfig): The build configuration
3703/// - [`bundle`](#bundleconfig): The bundle configurations
3704/// - [`plugins`](#pluginconfig): The plugins configuration
3705///
3706/// Example tauri.config.json file:
3707///
3708/// ```json
3709/// {
3710///   "productName": "tauri-app",
3711///   "version": "0.1.0",
3712///   "build": {
3713///     "beforeBuildCommand": "",
3714///     "beforeDevCommand": "",
3715///     "devUrl": "http://localhost:3000",
3716///     "frontendDist": "../dist"
3717///   },
3718///   "app": {
3719///     "security": {
3720///       "csp": null
3721///     },
3722///     "windows": [
3723///       {
3724///         "fullscreen": false,
3725///         "height": 600,
3726///         "resizable": true,
3727///         "title": "Tauri App",
3728///         "width": 800
3729///       }
3730///     ]
3731///   },
3732///   "bundle": {},
3733///   "plugins": {}
3734/// }
3735/// ```
3736#[skip_serializing_none]
3737#[derive(Debug, Default, PartialEq, Clone, Deserialize, Serialize)]
3738#[cfg_attr(feature = "schema", derive(JsonSchema))]
3739#[serde(rename_all = "camelCase", deny_unknown_fields)]
3740pub struct Config {
3741  /// The JSON schema for the Tauri config.
3742  #[serde(rename = "$schema")]
3743  pub schema: Option<String>,
3744  /// App name.
3745  ///
3746  /// This is the name your app is known by on the user's system, so it must be changed from the
3747  /// default before publishing. Besides naming the generated bundles, it is written into platform
3748  /// metadata and install paths that are expected to be unique to your application.
3749  ///
3750  /// ## Platform-specific
3751  ///
3752  /// - **macOS**: Names the `.app` bundle and the `.dmg`, and sets the bundle's
3753  ///    `CFBundleDisplayName` and `CFBundleName` properties. `CFBundleName` can be overridden with
3754  ///    [`bundle > macOS > bundleName`](MacConfig::bundle_name).
3755  /// - **Linux**: Kebab-cased for the Debian and RPM package names, used as the `Name` entry of
3756  ///    the desktop file and as the resource directory name under `/usr/lib`.
3757  /// - **Windows**: Names the installers, the installation directory, the Start Menu folder and
3758  ///    the `HKCU\Software\<publisher>\<product name>` registry key. It also derives the default
3759  ///    WiX upgrade code, which must be unique across applications and can be set explicitly with
3760  ///    [`bundle > windows > wix > upgradeCode`](WixConfig::upgrade_code).
3761  #[serde(alias = "product-name")]
3762  #[cfg_attr(feature = "schema", schemars(regex(pattern = "^[^/\\:*?\"<>|]+$")))]
3763  pub product_name: Option<String>,
3764  /// Overrides app's main binary filename.
3765  ///
3766  /// By default, Tauri uses the output binary from `cargo`, by setting this, we will rename that binary in `tauri-cli`'s
3767  /// `tauri build` command, and target `tauri bundle` to it
3768  ///
3769  /// If possible, change the [`package name`] or set the [`name field`] instead,
3770  /// and if that's not enough and you're using nightly, consider using the [`different-binary-name`] feature instead
3771  ///
3772  /// Note: this config should not include the binary extension (e.g. `.exe`), we'll add that for you
3773  ///
3774  /// [`package name`]: https://doc.rust-lang.org/cargo/reference/manifest.html#the-name-field
3775  /// [`name field`]: https://doc.rust-lang.org/cargo/reference/cargo-targets.html#the-name-field
3776  /// [`different-binary-name`]: https://doc.rust-lang.org/nightly/cargo/reference/unstable.html#different-binary-name
3777  #[serde(alias = "main-binary-name")]
3778  pub main_binary_name: Option<String>,
3779  /// App version. It is a semver version number or a path to a `package.json` file containing the `version` field.
3780  ///
3781  /// If removed the version number from `Cargo.toml` is used.
3782  /// It's recommended to manage the app versioning in the Tauri config.
3783  ///
3784  /// ## Platform-specific
3785  ///
3786  /// - **macOS**: Translates to the bundle's CFBundleShortVersionString property and is used as the default CFBundleVersion.
3787  ///    You can set an specific bundle version using [`bundle > macOS > bundleVersion`](MacConfig::bundle_version).
3788  /// - **iOS**: Translates to the bundle's CFBundleShortVersionString property and is used as the default CFBundleVersion.
3789  ///    You can set an specific bundle version using [`bundle > iOS > bundleVersion`](IosConfig::bundle_version).
3790  ///    The `tauri ios build` CLI command has a `--build-number <number>` option that lets you append a build number to the app version.
3791  /// - **Android**: By default version 1.0 is used. You can set a version code using [`bundle > android > versionCode`](AndroidConfig::version_code).
3792  ///
3793  /// By default version 1.0 is used on Android.
3794  #[serde(deserialize_with = "version_deserializer", default)]
3795  pub version: Option<String>,
3796  /// The application identifier in reverse domain name notation (e.g. `com.tauri.example`).
3797  /// This string must be unique across applications since it is used in system configurations like
3798  /// the bundle ID and path to the webview data directory.
3799  /// This string must contain only alphanumeric characters (A-Z, a-z, and 0-9), hyphens (-),
3800  /// and periods (.).
3801  /// The default value `com.tauri.dev` is rejected by `tauri build` and must be changed before
3802  /// building your application.
3803  pub identifier: String,
3804  /// The App configuration.
3805  #[serde(default)]
3806  pub app: AppConfig,
3807  /// The build configuration.
3808  #[serde(default)]
3809  pub build: BuildConfig,
3810  /// The bundler configuration.
3811  #[serde(default)]
3812  pub bundle: BundleConfig,
3813  /// The plugins config.
3814  #[serde(default)]
3815  pub plugins: PluginConfig,
3816}
3817
3818/// The plugin configs holds a HashMap mapping a plugin name to its configuration object.
3819///
3820/// See more: <https://v2.tauri.app/reference/config/#pluginconfig>
3821#[derive(Debug, Clone, Default, PartialEq, Eq, Deserialize)]
3822#[cfg_attr(feature = "schema", derive(JsonSchema))]
3823pub struct PluginConfig(pub HashMap<String, JsonValue>);
3824
3825impl Serialize for PluginConfig {
3826  fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
3827  where
3828    S: Serializer,
3829  {
3830    // Serialize through `BTreeMap` so the output is deterministic
3831    // see: https://github.com/tauri-apps/tauri/issues/14978
3832    // TODO: Remove this in v3, use a BTreeMap instead of a HashMap
3833    let btree_map: BTreeMap<_, _> = self.0.iter().collect();
3834    btree_map.serialize(serializer)
3835  }
3836}
3837
3838/// Implement `ToTokens` for all config structs, allowing a literal `Config` to be built.
3839///
3840/// This allows for a build script to output the values in a `Config` to a `TokenStream`, which can
3841/// then be consumed by another crate. Useful for passing a config to both the build script and the
3842/// application using tauri while only parsing it once (in the build script).
3843#[cfg(any(feature = "build", feature = "build-2"))]
3844mod build {
3845  use super::*;
3846  use crate::{literal_struct, tokens::*};
3847  use proc_macro2::TokenStream;
3848  use quote::{ToTokens, TokenStreamExt, quote};
3849  use std::convert::identity;
3850
3851  impl ToTokens for WebviewUrl {
3852    fn to_tokens(&self, tokens: &mut TokenStream) {
3853      let prefix = quote! { ::tauri::utils::config::WebviewUrl };
3854
3855      tokens.append_all(match self {
3856        Self::App(path) => {
3857          let path = path_buf_lit(path);
3858          quote! { #prefix::App(#path) }
3859        }
3860        Self::External(url) => {
3861          let url = url_lit(url);
3862          quote! { #prefix::External(#url) }
3863        }
3864        Self::CustomProtocol(url) => {
3865          let url = url_lit(url);
3866          quote! { #prefix::CustomProtocol(#url) }
3867        }
3868      })
3869    }
3870  }
3871
3872  impl ToTokens for BackgroundThrottlingPolicy {
3873    fn to_tokens(&self, tokens: &mut TokenStream) {
3874      let prefix = quote! { ::tauri::utils::config::BackgroundThrottlingPolicy };
3875      tokens.append_all(match self {
3876        Self::Disabled => quote! { #prefix::Disabled },
3877        Self::Throttle => quote! { #prefix::Throttle },
3878        Self::Suspend => quote! { #prefix::Suspend },
3879      })
3880    }
3881  }
3882
3883  impl ToTokens for crate::Theme {
3884    fn to_tokens(&self, tokens: &mut TokenStream) {
3885      let prefix = quote! { ::tauri::utils::Theme };
3886
3887      tokens.append_all(match self {
3888        Self::Light => quote! { #prefix::Light },
3889        Self::Dark => quote! { #prefix::Dark },
3890      })
3891    }
3892  }
3893
3894  impl ToTokens for Color {
3895    fn to_tokens(&self, tokens: &mut TokenStream) {
3896      let Color(r, g, b, a) = self;
3897      tokens.append_all(quote! {::tauri::utils::config::Color(#r,#g,#b,#a)});
3898    }
3899  }
3900  impl ToTokens for WindowEffectsConfig {
3901    fn to_tokens(&self, tokens: &mut TokenStream) {
3902      let effects = vec_lit(self.effects.clone(), |d| d);
3903      let state = opt_lit(self.state.as_ref());
3904      let radius = opt_lit(self.radius.as_ref());
3905      let color = opt_lit(self.color.as_ref());
3906
3907      literal_struct!(
3908        tokens,
3909        ::tauri::utils::config::WindowEffectsConfig,
3910        effects,
3911        state,
3912        radius,
3913        color
3914      )
3915    }
3916  }
3917
3918  impl ToTokens for crate::TitleBarStyle {
3919    fn to_tokens(&self, tokens: &mut TokenStream) {
3920      let prefix = quote! { ::tauri::utils::TitleBarStyle };
3921
3922      tokens.append_all(match self {
3923        Self::Visible => quote! { #prefix::Visible },
3924        Self::Transparent => quote! { #prefix::Transparent },
3925        Self::Overlay => quote! { #prefix::Overlay },
3926      })
3927    }
3928  }
3929
3930  impl ToTokens for LogicalPosition {
3931    fn to_tokens(&self, tokens: &mut TokenStream) {
3932      let LogicalPosition { x, y } = self;
3933      literal_struct!(tokens, ::tauri::utils::config::LogicalPosition, x, y)
3934    }
3935  }
3936
3937  impl ToTokens for crate::WindowEffect {
3938    fn to_tokens(&self, tokens: &mut TokenStream) {
3939      let prefix = quote! { ::tauri::utils::WindowEffect };
3940
3941      #[allow(deprecated)]
3942      tokens.append_all(match self {
3943        WindowEffect::AppearanceBased => quote! { #prefix::AppearanceBased},
3944        WindowEffect::Light => quote! { #prefix::Light},
3945        WindowEffect::Dark => quote! { #prefix::Dark},
3946        WindowEffect::MediumLight => quote! { #prefix::MediumLight},
3947        WindowEffect::UltraDark => quote! { #prefix::UltraDark},
3948        WindowEffect::Titlebar => quote! { #prefix::Titlebar},
3949        WindowEffect::Selection => quote! { #prefix::Selection},
3950        WindowEffect::Menu => quote! { #prefix::Menu},
3951        WindowEffect::Popover => quote! { #prefix::Popover},
3952        WindowEffect::Sidebar => quote! { #prefix::Sidebar},
3953        WindowEffect::HeaderView => quote! { #prefix::HeaderView},
3954        WindowEffect::Sheet => quote! { #prefix::Sheet},
3955        WindowEffect::WindowBackground => quote! { #prefix::WindowBackground},
3956        WindowEffect::HudWindow => quote! { #prefix::HudWindow},
3957        WindowEffect::FullScreenUI => quote! { #prefix::FullScreenUI},
3958        WindowEffect::Tooltip => quote! { #prefix::Tooltip},
3959        WindowEffect::ContentBackground => quote! { #prefix::ContentBackground},
3960        WindowEffect::UnderWindowBackground => quote! { #prefix::UnderWindowBackground},
3961        WindowEffect::UnderPageBackground => quote! { #prefix::UnderPageBackground},
3962        WindowEffect::Mica => quote! { #prefix::Mica},
3963        WindowEffect::MicaDark => quote! { #prefix::MicaDark},
3964        WindowEffect::MicaLight => quote! { #prefix::MicaLight},
3965        WindowEffect::Blur => quote! { #prefix::Blur},
3966        WindowEffect::Acrylic => quote! { #prefix::Acrylic},
3967        WindowEffect::Tabbed => quote! { #prefix::Tabbed },
3968        WindowEffect::TabbedDark => quote! { #prefix::TabbedDark },
3969        WindowEffect::TabbedLight => quote! { #prefix::TabbedLight },
3970      })
3971    }
3972  }
3973
3974  impl ToTokens for crate::WindowEffectState {
3975    fn to_tokens(&self, tokens: &mut TokenStream) {
3976      let prefix = quote! { ::tauri::utils::WindowEffectState };
3977
3978      #[allow(deprecated)]
3979      tokens.append_all(match self {
3980        WindowEffectState::Active => quote! { #prefix::Active},
3981        WindowEffectState::FollowsWindowActiveState => quote! { #prefix::FollowsWindowActiveState},
3982        WindowEffectState::Inactive => quote! { #prefix::Inactive},
3983      })
3984    }
3985  }
3986
3987  impl ToTokens for PreventOverflowMargin {
3988    fn to_tokens(&self, tokens: &mut TokenStream) {
3989      let width = self.width;
3990      let height = self.height;
3991
3992      literal_struct!(
3993        tokens,
3994        ::tauri::utils::config::PreventOverflowMargin,
3995        width,
3996        height
3997      )
3998    }
3999  }
4000
4001  impl ToTokens for PreventOverflowConfig {
4002    fn to_tokens(&self, tokens: &mut TokenStream) {
4003      let prefix = quote! { ::tauri::utils::config::PreventOverflowConfig };
4004
4005      #[allow(deprecated)]
4006      tokens.append_all(match self {
4007        Self::Enable(enable) => quote! { #prefix::Enable(#enable) },
4008        Self::Margin(margin) => quote! { #prefix::Margin(#margin) },
4009      })
4010    }
4011  }
4012
4013  impl ToTokens for ScrollBarStyle {
4014    fn to_tokens(&self, tokens: &mut TokenStream) {
4015      let prefix = quote! { ::tauri::utils::config::ScrollBarStyle };
4016
4017      tokens.append_all(match self {
4018        Self::Default => quote! { #prefix::Default },
4019        Self::FluentOverlay => quote! { #prefix::FluentOverlay },
4020      })
4021    }
4022  }
4023
4024  impl ToTokens for WindowConfig {
4025    fn to_tokens(&self, tokens: &mut TokenStream) {
4026      let label = str_lit(&self.label);
4027      let create = &self.create;
4028      let url = &self.url;
4029      let user_agent = opt_str_lit(self.user_agent.as_ref());
4030      let drag_drop_enabled = self.drag_drop_enabled;
4031      let center = self.center;
4032      let x = opt_lit(self.x.as_ref());
4033      let y = opt_lit(self.y.as_ref());
4034      let width = self.width;
4035      let height = self.height;
4036      let min_width = opt_lit(self.min_width.as_ref());
4037      let min_height = opt_lit(self.min_height.as_ref());
4038      let max_width = opt_lit(self.max_width.as_ref());
4039      let max_height = opt_lit(self.max_height.as_ref());
4040      let prevent_overflow = opt_lit(self.prevent_overflow.as_ref());
4041      let resizable = self.resizable;
4042      let maximizable = self.maximizable;
4043      let minimizable = self.minimizable;
4044      let closable = self.closable;
4045      let title = str_lit(&self.title);
4046      let proxy_url = opt_lit(self.proxy_url.as_ref().map(url_lit).as_ref());
4047      let fullscreen = self.fullscreen;
4048      let focus = self.focus;
4049      let focusable = self.focusable;
4050      let transparent = self.transparent;
4051      let maximized = self.maximized;
4052      let visible = self.visible;
4053      let decorations = self.decorations;
4054      let always_on_bottom = self.always_on_bottom;
4055      let always_on_top = self.always_on_top;
4056      let visible_on_all_workspaces = self.visible_on_all_workspaces;
4057      let content_protected = self.content_protected;
4058      let skip_taskbar = self.skip_taskbar;
4059      let window_classname = opt_str_lit(self.window_classname.as_ref());
4060      let no_redirection_bitmap = self.no_redirection_bitmap;
4061      let theme = opt_lit(self.theme.as_ref());
4062      let title_bar_style = &self.title_bar_style;
4063      let traffic_light_position = opt_lit(self.traffic_light_position.as_ref());
4064      let hidden_title = self.hidden_title;
4065      let accept_first_mouse = self.accept_first_mouse;
4066      let tabbing_identifier = opt_str_lit(self.tabbing_identifier.as_ref());
4067      let additional_browser_args = opt_str_lit(self.additional_browser_args.as_ref());
4068      let shadow = self.shadow;
4069      let window_effects = opt_lit(self.window_effects.as_ref());
4070      let incognito = self.incognito;
4071      let parent = opt_str_lit(self.parent.as_ref());
4072      let zoom_hotkeys_enabled = self.zoom_hotkeys_enabled;
4073      let browser_extensions_enabled = self.browser_extensions_enabled;
4074      let use_https_scheme = self.use_https_scheme;
4075      let devtools = opt_lit(self.devtools.as_ref());
4076      let background_color = opt_lit(self.background_color.as_ref());
4077      let background_throttling = opt_lit(self.background_throttling.as_ref());
4078      let javascript_disabled = self.javascript_disabled;
4079      let allow_link_preview = self.allow_link_preview;
4080      let disable_input_accessory_view = self.disable_input_accessory_view;
4081      let data_directory = opt_lit(self.data_directory.as_ref().map(path_buf_lit).as_ref());
4082      let data_store_identifier = opt_vec_lit(self.data_store_identifier, identity);
4083      let scroll_bar_style = &self.scroll_bar_style;
4084      let limit_navigations_to_app_bound_domains = self.limit_navigations_to_app_bound_domains;
4085      let activity_name = opt_lit(self.activity_name.as_ref());
4086      let created_by_activity_name = opt_lit(self.created_by_activity_name.as_ref());
4087      let requested_by_scene_identifier = opt_lit(self.requested_by_scene_identifier.as_ref());
4088      let general_autofill_enabled = self.general_autofill_enabled;
4089
4090      literal_struct!(
4091        tokens,
4092        ::tauri::utils::config::WindowConfig,
4093        label,
4094        url,
4095        create,
4096        user_agent,
4097        drag_drop_enabled,
4098        center,
4099        x,
4100        y,
4101        width,
4102        height,
4103        min_width,
4104        min_height,
4105        max_width,
4106        max_height,
4107        prevent_overflow,
4108        resizable,
4109        maximizable,
4110        minimizable,
4111        closable,
4112        title,
4113        proxy_url,
4114        fullscreen,
4115        focus,
4116        focusable,
4117        transparent,
4118        maximized,
4119        visible,
4120        decorations,
4121        always_on_bottom,
4122        always_on_top,
4123        visible_on_all_workspaces,
4124        content_protected,
4125        skip_taskbar,
4126        window_classname,
4127        no_redirection_bitmap,
4128        theme,
4129        title_bar_style,
4130        traffic_light_position,
4131        hidden_title,
4132        accept_first_mouse,
4133        tabbing_identifier,
4134        additional_browser_args,
4135        shadow,
4136        window_effects,
4137        incognito,
4138        parent,
4139        zoom_hotkeys_enabled,
4140        browser_extensions_enabled,
4141        use_https_scheme,
4142        devtools,
4143        background_color,
4144        background_throttling,
4145        javascript_disabled,
4146        allow_link_preview,
4147        disable_input_accessory_view,
4148        data_directory,
4149        data_store_identifier,
4150        scroll_bar_style,
4151        limit_navigations_to_app_bound_domains,
4152        activity_name,
4153        created_by_activity_name,
4154        requested_by_scene_identifier,
4155        general_autofill_enabled
4156      );
4157    }
4158  }
4159
4160  impl ToTokens for PatternKind {
4161    fn to_tokens(&self, tokens: &mut TokenStream) {
4162      let prefix = quote! { ::tauri::utils::config::PatternKind };
4163
4164      tokens.append_all(match self {
4165        Self::Brownfield => quote! { #prefix::Brownfield },
4166        #[cfg(not(feature = "isolation"))]
4167        Self::Isolation { dir: _ } => quote! { #prefix::Brownfield },
4168        #[cfg(feature = "isolation")]
4169        Self::Isolation { dir } => {
4170          let dir = path_buf_lit(dir);
4171          quote! { #prefix::Isolation { dir: #dir } }
4172        }
4173      })
4174    }
4175  }
4176
4177  impl ToTokens for WebviewInstallMode {
4178    fn to_tokens(&self, tokens: &mut TokenStream) {
4179      let prefix = quote! { ::tauri::utils::config::WebviewInstallMode };
4180
4181      tokens.append_all(match self {
4182        Self::Skip => quote! { #prefix::Skip },
4183        Self::DownloadBootstrapper { silent } => {
4184          quote! { #prefix::DownloadBootstrapper { silent: #silent } }
4185        }
4186        Self::EmbedBootstrapper { silent } => {
4187          quote! { #prefix::EmbedBootstrapper { silent: #silent } }
4188        }
4189        Self::OfflineInstaller { silent } => {
4190          quote! { #prefix::OfflineInstaller { silent: #silent } }
4191        }
4192        Self::FixedRuntime { path } => {
4193          let path = path_buf_lit(path);
4194          quote! { #prefix::FixedRuntime { path: #path } }
4195        }
4196      })
4197    }
4198  }
4199
4200  impl ToTokens for WindowsConfig {
4201    fn to_tokens(&self, tokens: &mut TokenStream) {
4202      let webview_install_mode = &self.webview_install_mode;
4203      tokens.append_all(quote! { ::tauri::utils::config::WindowsConfig {
4204        webview_install_mode: #webview_install_mode,
4205        ..Default::default()
4206      }})
4207    }
4208  }
4209
4210  impl ToTokens for BundleResources {
4211    fn to_tokens(&self, tokens: &mut TokenStream) {
4212      let prefix = quote! { ::tauri::utils::config::BundleResources };
4213
4214      tokens.append_all(match self {
4215        Self::List(paths) => {
4216          let paths = vec_lit(paths, str_lit);
4217          quote! { #prefix::List(#paths) }
4218        }
4219        Self::Map(map) => {
4220          let map = map_lit(
4221            quote! { ::std::collections::HashMap },
4222            map,
4223            str_lit,
4224            str_lit,
4225          );
4226          quote! { #prefix::Map(#map) }
4227        }
4228      })
4229    }
4230  }
4231
4232  impl ToTokens for BundleConfig {
4233    fn to_tokens(&self, tokens: &mut TokenStream) {
4234      let publisher = quote!(None);
4235      let homepage = quote!(None);
4236      let icon = vec_lit(&self.icon, str_lit);
4237      let active = self.active;
4238      let targets = quote!(Default::default());
4239      let create_updater_artifacts = quote!(Default::default());
4240      let resources = opt_lit(self.resources.as_ref());
4241      let copyright = quote!(None);
4242      let category = quote!(None);
4243      let file_associations = quote!(None);
4244      let short_description = quote!(None);
4245      let long_description = quote!(None);
4246      let use_local_tools_dir = self.use_local_tools_dir;
4247      let external_bin = opt_vec_lit(self.external_bin.as_ref(), str_lit);
4248      let windows = &self.windows;
4249      let license = opt_str_lit(self.license.as_ref());
4250      let license_file = opt_lit(self.license_file.as_ref().map(path_buf_lit).as_ref());
4251      let linux = quote!(Default::default());
4252      let macos = quote!(Default::default());
4253      let ios = quote!(Default::default());
4254      let android = quote!(Default::default());
4255      let cef = quote!(Default::default());
4256
4257      literal_struct!(
4258        tokens,
4259        ::tauri::utils::config::BundleConfig,
4260        active,
4261        publisher,
4262        homepage,
4263        icon,
4264        targets,
4265        create_updater_artifacts,
4266        resources,
4267        copyright,
4268        category,
4269        license,
4270        license_file,
4271        file_associations,
4272        short_description,
4273        long_description,
4274        use_local_tools_dir,
4275        external_bin,
4276        windows,
4277        linux,
4278        macos,
4279        ios,
4280        android,
4281        cef
4282      );
4283    }
4284  }
4285
4286  impl ToTokens for FrontendDist {
4287    fn to_tokens(&self, tokens: &mut TokenStream) {
4288      let prefix = quote! { ::tauri::utils::config::FrontendDist };
4289
4290      tokens.append_all(match self {
4291        Self::Url(url) => {
4292          let url = url_lit(url);
4293          quote! { #prefix::Url(#url) }
4294        }
4295        Self::Directory(path) => {
4296          let path = path_buf_lit(path);
4297          quote! { #prefix::Directory(#path) }
4298        }
4299        Self::Files(files) => {
4300          let files = vec_lit(files, path_buf_lit);
4301          quote! { #prefix::Files(#files) }
4302        }
4303      })
4304    }
4305  }
4306
4307  impl ToTokens for RunnerConfig {
4308    fn to_tokens(&self, tokens: &mut TokenStream) {
4309      let prefix = quote! { ::tauri::utils::config::RunnerConfig };
4310
4311      tokens.append_all(match self {
4312        Self::String(cmd) => {
4313          let cmd = cmd.as_str();
4314          quote!(#prefix::String(#cmd.into()))
4315        }
4316        Self::Object { cmd, cwd, args } => {
4317          let cmd = cmd.as_str();
4318          let cwd = opt_str_lit(cwd.as_ref());
4319          let args = opt_lit(args.as_ref().map(|v| vec_lit(v, str_lit)).as_ref());
4320          quote!(#prefix::Object {
4321            cmd: #cmd.into(),
4322            cwd: #cwd,
4323            args: #args,
4324          })
4325        }
4326      })
4327    }
4328  }
4329
4330  impl ToTokens for BuildConfig {
4331    fn to_tokens(&self, tokens: &mut TokenStream) {
4332      let dev_url = opt_lit(self.dev_url.as_ref().map(url_lit).as_ref());
4333      let frontend_dist = opt_lit(self.frontend_dist.as_ref());
4334      let runner = opt_lit(self.runner.as_ref());
4335      let before_dev_command = quote!(None);
4336      let before_build_command = quote!(None);
4337      let before_bundle_command = quote!(None);
4338      let features = quote!(None);
4339      let remove_unused_commands = quote!(false);
4340      let additional_watch_folders = quote!(Vec::new());
4341      let windows = &self.windows;
4342
4343      literal_struct!(
4344        tokens,
4345        ::tauri::utils::config::BuildConfig,
4346        runner,
4347        dev_url,
4348        frontend_dist,
4349        before_dev_command,
4350        before_build_command,
4351        before_bundle_command,
4352        features,
4353        remove_unused_commands,
4354        additional_watch_folders,
4355        windows
4356      );
4357    }
4358  }
4359
4360  impl ToTokens for WindowsBuildConfig {
4361    fn to_tokens(&self, tokens: &mut TokenStream) {
4362      let static_vc_runtime = self.static_vc_runtime;
4363
4364      literal_struct!(
4365        tokens,
4366        ::tauri::utils::config::WindowsBuildConfig,
4367        static_vc_runtime
4368      );
4369    }
4370  }
4371
4372  impl ToTokens for CspDirectiveSources {
4373    fn to_tokens(&self, tokens: &mut TokenStream) {
4374      let prefix = quote! { ::tauri::utils::config::CspDirectiveSources };
4375
4376      tokens.append_all(match self {
4377        Self::Inline(sources) => {
4378          let sources = sources.as_str();
4379          quote!(#prefix::Inline(#sources.into()))
4380        }
4381        Self::List(list) => {
4382          let list = vec_lit(list, str_lit);
4383          quote!(#prefix::List(#list))
4384        }
4385      })
4386    }
4387  }
4388
4389  impl ToTokens for Csp {
4390    fn to_tokens(&self, tokens: &mut TokenStream) {
4391      let prefix = quote! { ::tauri::utils::config::Csp };
4392
4393      tokens.append_all(match self {
4394        Self::Policy(policy) => {
4395          let policy = policy.as_str();
4396          quote!(#prefix::Policy(#policy.into()))
4397        }
4398        Self::DirectiveMap(list) => {
4399          // Pass a sorted vec so the HashMap constructor is deterministic
4400          // see: https://github.com/tauri-apps/tauri/issues/14978
4401          // TODO: Remove this in v3, use a BTreeMap instead of a HashMap
4402          let mut sorted: Vec<_> = list.iter().collect();
4403          sorted.sort_by_key(|(k, _)| *k);
4404          let map = map_lit(
4405            quote! { ::std::collections::HashMap },
4406            sorted,
4407            str_lit,
4408            identity,
4409          );
4410          quote!(#prefix::DirectiveMap(#map))
4411        }
4412      })
4413    }
4414  }
4415
4416  impl ToTokens for DisabledCspModificationKind {
4417    fn to_tokens(&self, tokens: &mut TokenStream) {
4418      let prefix = quote! { ::tauri::utils::config::DisabledCspModificationKind };
4419
4420      tokens.append_all(match self {
4421        Self::Flag(flag) => {
4422          quote! { #prefix::Flag(#flag) }
4423        }
4424        Self::List(directives) => {
4425          let directives = vec_lit(directives, str_lit);
4426          quote! { #prefix::List(#directives) }
4427        }
4428      });
4429    }
4430  }
4431
4432  impl ToTokens for CapabilityEntry {
4433    fn to_tokens(&self, tokens: &mut TokenStream) {
4434      let prefix = quote! { ::tauri::utils::config::CapabilityEntry };
4435
4436      tokens.append_all(match self {
4437        Self::Inlined(capability) => {
4438          quote! { #prefix::Inlined(#capability) }
4439        }
4440        Self::Reference(id) => {
4441          let id = str_lit(id);
4442          quote! { #prefix::Reference(#id) }
4443        }
4444      });
4445    }
4446  }
4447
4448  impl ToTokens for HeaderSource {
4449    fn to_tokens(&self, tokens: &mut TokenStream) {
4450      let prefix = quote! { ::tauri::utils::config::HeaderSource };
4451
4452      tokens.append_all(match self {
4453        Self::Inline(s) => {
4454          let line = s.as_str();
4455          quote!(#prefix::Inline(#line.into()))
4456        }
4457        Self::List(l) => {
4458          let list = vec_lit(l, str_lit);
4459          quote!(#prefix::List(#list))
4460        }
4461        Self::Map(m) => {
4462          // Pass a sorted vec so the HashMap constructor is deterministic
4463          // see: https://github.com/tauri-apps/tauri/issues/14978
4464          // TODO: Remove this in v3, use a BTreeMap instead of a HashMap
4465          let mut sorted: Vec<_> = m.iter().collect();
4466          sorted.sort_by_key(|(k, _)| *k);
4467          let map = map_lit(
4468            quote! { ::std::collections::HashMap },
4469            sorted,
4470            str_lit,
4471            str_lit,
4472          );
4473          quote!(#prefix::Map(#map))
4474        }
4475      })
4476    }
4477  }
4478
4479  impl ToTokens for HeaderConfig {
4480    fn to_tokens(&self, tokens: &mut TokenStream) {
4481      let access_control_allow_credentials =
4482        opt_lit(self.access_control_allow_credentials.as_ref());
4483      let access_control_allow_headers = opt_lit(self.access_control_allow_headers.as_ref());
4484      let access_control_allow_methods = opt_lit(self.access_control_allow_methods.as_ref());
4485      let access_control_expose_headers = opt_lit(self.access_control_expose_headers.as_ref());
4486      let access_control_max_age = opt_lit(self.access_control_max_age.as_ref());
4487      let cross_origin_embedder_policy = opt_lit(self.cross_origin_embedder_policy.as_ref());
4488      let cross_origin_opener_policy = opt_lit(self.cross_origin_opener_policy.as_ref());
4489      let cross_origin_resource_policy = opt_lit(self.cross_origin_resource_policy.as_ref());
4490      let permissions_policy = opt_lit(self.permissions_policy.as_ref());
4491      let service_worker_allowed = opt_lit(self.service_worker_allowed.as_ref());
4492      let timing_allow_origin = opt_lit(self.timing_allow_origin.as_ref());
4493      let x_content_type_options = opt_lit(self.x_content_type_options.as_ref());
4494      let tauri_custom_header = opt_lit(self.tauri_custom_header.as_ref());
4495
4496      literal_struct!(
4497        tokens,
4498        ::tauri::utils::config::HeaderConfig,
4499        access_control_allow_credentials,
4500        access_control_allow_headers,
4501        access_control_allow_methods,
4502        access_control_expose_headers,
4503        access_control_max_age,
4504        cross_origin_embedder_policy,
4505        cross_origin_opener_policy,
4506        cross_origin_resource_policy,
4507        permissions_policy,
4508        service_worker_allowed,
4509        timing_allow_origin,
4510        x_content_type_options,
4511        tauri_custom_header
4512      );
4513    }
4514  }
4515
4516  impl ToTokens for SecurityConfig {
4517    fn to_tokens(&self, tokens: &mut TokenStream) {
4518      let csp = opt_lit(self.csp.as_ref());
4519      let dev_csp = opt_lit(self.dev_csp.as_ref());
4520      let freeze_prototype = self.freeze_prototype;
4521      let dangerous_disable_asset_csp_modification = &self.dangerous_disable_asset_csp_modification;
4522      let asset_protocol = &self.asset_protocol;
4523      let pattern = &self.pattern;
4524      let capabilities = vec_lit(&self.capabilities, identity);
4525      let headers = opt_lit(self.headers.as_ref());
4526
4527      literal_struct!(
4528        tokens,
4529        ::tauri::utils::config::SecurityConfig,
4530        csp,
4531        dev_csp,
4532        freeze_prototype,
4533        dangerous_disable_asset_csp_modification,
4534        asset_protocol,
4535        pattern,
4536        capabilities,
4537        headers
4538      );
4539    }
4540  }
4541
4542  impl ToTokens for TrayIconConfig {
4543    fn to_tokens(&self, tokens: &mut TokenStream) {
4544      // For [`Self::menu_on_left_click`]
4545      tokens.append_all(quote!(#[allow(deprecated)]));
4546
4547      let id = opt_str_lit(self.id.as_ref());
4548      let icon_as_template = self.icon_as_template;
4549      #[allow(deprecated)]
4550      let menu_on_left_click = self.menu_on_left_click;
4551      let show_menu_on_left_click = self.show_menu_on_left_click;
4552      let icon_path = path_buf_lit(&self.icon_path);
4553      let title = opt_str_lit(self.title.as_ref());
4554      let tooltip = opt_str_lit(self.tooltip.as_ref());
4555      literal_struct!(
4556        tokens,
4557        ::tauri::utils::config::TrayIconConfig,
4558        id,
4559        icon_path,
4560        icon_as_template,
4561        menu_on_left_click,
4562        show_menu_on_left_click,
4563        title,
4564        tooltip
4565      );
4566    }
4567  }
4568
4569  impl ToTokens for FsScope {
4570    fn to_tokens(&self, tokens: &mut TokenStream) {
4571      let prefix = quote! { ::tauri::utils::config::FsScope };
4572
4573      tokens.append_all(match self {
4574        Self::AllowedPaths(allow) => {
4575          let allowed_paths = vec_lit(allow, path_buf_lit);
4576          quote! { #prefix::AllowedPaths(#allowed_paths) }
4577        }
4578        Self::Scope { allow, deny , require_literal_leading_dot} => {
4579          let allow = vec_lit(allow, path_buf_lit);
4580          let deny = vec_lit(deny, path_buf_lit);
4581          let  require_literal_leading_dot = opt_lit(require_literal_leading_dot.as_ref());
4582          quote! { #prefix::Scope { allow: #allow, deny: #deny, require_literal_leading_dot: #require_literal_leading_dot } }
4583        }
4584      });
4585    }
4586  }
4587
4588  impl ToTokens for AssetProtocolConfig {
4589    fn to_tokens(&self, tokens: &mut TokenStream) {
4590      let scope = &self.scope;
4591      tokens.append_all(quote! { ::tauri::utils::config::AssetProtocolConfig { scope: #scope, ..Default::default() } })
4592    }
4593  }
4594
4595  impl ToTokens for AppConfig {
4596    fn to_tokens(&self, tokens: &mut TokenStream) {
4597      let windows = vec_lit(&self.windows, identity);
4598      let security = &self.security;
4599      let tray_icon = opt_lit(self.tray_icon.as_ref());
4600      let macos_private_api = self.macos_private_api;
4601      let with_global_tauri = self.with_global_tauri;
4602      let enable_gtk_app_id = self.enable_gtk_app_id;
4603
4604      literal_struct!(
4605        tokens,
4606        ::tauri::utils::config::AppConfig,
4607        windows,
4608        security,
4609        tray_icon,
4610        macos_private_api,
4611        with_global_tauri,
4612        enable_gtk_app_id
4613      );
4614    }
4615  }
4616
4617  impl ToTokens for PluginConfig {
4618    fn to_tokens(&self, tokens: &mut TokenStream) {
4619      // Pass a sorted vec so the HashMap constructor is deterministic
4620      // see: https://github.com/tauri-apps/tauri/issues/14978
4621      // TODO: Remove this in v3, use a BTreeMap instead of a HashMap
4622      let mut sorted: Vec<_> = self.0.iter().collect();
4623      sorted.sort_by_key(|(k, _)| *k);
4624      let config = map_lit(
4625        quote! { ::std::collections::HashMap },
4626        sorted,
4627        str_lit,
4628        json_value_lit,
4629      );
4630      tokens.append_all(quote! { ::tauri::utils::config::PluginConfig(#config) })
4631    }
4632  }
4633
4634  impl ToTokens for Config {
4635    fn to_tokens(&self, tokens: &mut TokenStream) {
4636      let schema = quote!(None);
4637      let product_name = opt_str_lit(self.product_name.as_ref());
4638      let main_binary_name = opt_str_lit(self.main_binary_name.as_ref());
4639      let version = opt_str_lit(self.version.as_ref());
4640      let identifier = str_lit(&self.identifier);
4641      let app = &self.app;
4642      let build = &self.build;
4643      let bundle = &self.bundle;
4644      let plugins = &self.plugins;
4645
4646      literal_struct!(
4647        tokens,
4648        ::tauri::utils::config::Config,
4649        schema,
4650        product_name,
4651        main_binary_name,
4652        version,
4653        identifier,
4654        app,
4655        build,
4656        bundle,
4657        plugins
4658      );
4659    }
4660  }
4661}
4662
4663#[cfg(test)]
4664mod test {
4665  use super::*;
4666
4667  // TODO: create a test that compares a config to a json config
4668
4669  #[test]
4670  // test all of the default functions
4671  fn test_defaults() {
4672    // get default app config
4673    let a_config = AppConfig::default();
4674    // get default build config
4675    let b_config = BuildConfig::default();
4676    // get default window
4677    let d_windows: Vec<WindowConfig> = vec![];
4678    // get default bundle
4679    let d_bundle = BundleConfig::default();
4680
4681    // create a tauri config.
4682    let app = AppConfig {
4683      windows: vec![],
4684      security: SecurityConfig {
4685        csp: None,
4686        dev_csp: None,
4687        freeze_prototype: false,
4688        dangerous_disable_asset_csp_modification: DisabledCspModificationKind::Flag(false),
4689        asset_protocol: AssetProtocolConfig::default(),
4690        pattern: Default::default(),
4691        capabilities: Vec::new(),
4692        headers: None,
4693      },
4694      tray_icon: None,
4695      macos_private_api: false,
4696      with_global_tauri: false,
4697      enable_gtk_app_id: false,
4698    };
4699
4700    // create a build config
4701    let build = BuildConfig {
4702      runner: None,
4703      dev_url: None,
4704      frontend_dist: None,
4705      before_dev_command: None,
4706      before_build_command: None,
4707      before_bundle_command: None,
4708      features: None,
4709      remove_unused_commands: false,
4710      additional_watch_folders: Vec::new(),
4711      windows: WindowsBuildConfig::default(),
4712    };
4713
4714    // create a bundle config
4715    let bundle = BundleConfig {
4716      active: false,
4717      targets: Default::default(),
4718      create_updater_artifacts: Default::default(),
4719      publisher: None,
4720      homepage: None,
4721      icon: Vec::new(),
4722      resources: None,
4723      copyright: None,
4724      category: None,
4725      file_associations: None,
4726      short_description: None,
4727      long_description: None,
4728      use_local_tools_dir: false,
4729      license: None,
4730      license_file: None,
4731      linux: Default::default(),
4732      macos: Default::default(),
4733      external_bin: None,
4734      windows: Default::default(),
4735      ios: Default::default(),
4736      android: Default::default(),
4737      cef: Default::default(),
4738    };
4739
4740    // test the configs
4741    assert_eq!(a_config, app);
4742    assert_eq!(b_config, build);
4743    assert_eq!(d_bundle, bundle);
4744    assert_eq!(d_windows, app.windows);
4745  }
4746
4747  #[test]
4748  fn parse_hex_color() {
4749    use super::Color;
4750
4751    assert_eq!(Color(255, 255, 255, 255), "fff".parse().unwrap());
4752    assert_eq!(Color(255, 255, 255, 255), "#fff".parse().unwrap());
4753    assert_eq!(Color(0, 0, 0, 255), "#000000".parse().unwrap());
4754    assert_eq!(Color(0, 0, 0, 255), "#000000ff".parse().unwrap());
4755    assert_eq!(Color(0, 255, 0, 255), "#00ff00ff".parse().unwrap());
4756  }
4757
4758  #[test]
4759  fn test_runner_config_string_format() {
4760    use super::RunnerConfig;
4761
4762    // Test string format deserialization
4763    let json = r#""cargo""#;
4764    let runner: RunnerConfig = serde_json::from_str(json).unwrap();
4765
4766    assert_eq!(runner.cmd(), "cargo");
4767    assert_eq!(runner.cwd(), None);
4768    assert_eq!(runner.args(), None);
4769
4770    // Test string format serialization
4771    let serialized = serde_json::to_string(&runner).unwrap();
4772    assert_eq!(serialized, r#""cargo""#);
4773  }
4774
4775  #[test]
4776  fn test_runner_config_object_format_full() {
4777    use super::RunnerConfig;
4778
4779    // Test object format with all fields
4780    let json = r#"{"cmd": "my_runner", "cwd": "/tmp/build", "args": ["--quiet", "--verbose"]}"#;
4781    let runner: RunnerConfig = serde_json::from_str(json).unwrap();
4782
4783    assert_eq!(runner.cmd(), "my_runner");
4784    assert_eq!(runner.cwd(), Some("/tmp/build"));
4785    assert_eq!(
4786      runner.args(),
4787      Some(&["--quiet".to_string(), "--verbose".to_string()][..])
4788    );
4789
4790    // Test object format serialization
4791    let serialized = serde_json::to_string(&runner).unwrap();
4792    let deserialized: RunnerConfig = serde_json::from_str(&serialized).unwrap();
4793    assert_eq!(runner, deserialized);
4794  }
4795
4796  #[test]
4797  fn test_runner_config_object_format_minimal() {
4798    use super::RunnerConfig;
4799
4800    // Test object format with only cmd field
4801    let json = r#"{"cmd": "cross"}"#;
4802    let runner: RunnerConfig = serde_json::from_str(json).unwrap();
4803
4804    assert_eq!(runner.cmd(), "cross");
4805    assert_eq!(runner.cwd(), None);
4806    assert_eq!(runner.args(), None);
4807  }
4808
4809  #[test]
4810  fn test_runner_config_default() {
4811    use super::RunnerConfig;
4812
4813    let default_runner = RunnerConfig::default();
4814    assert_eq!(default_runner.cmd(), "cargo");
4815    assert_eq!(default_runner.cwd(), None);
4816    assert_eq!(default_runner.args(), None);
4817  }
4818
4819  #[test]
4820  fn test_runner_config_from_str() {
4821    use super::RunnerConfig;
4822
4823    // Test From<&str> trait
4824    let runner: RunnerConfig = "my_runner".into();
4825    assert_eq!(runner.cmd(), "my_runner");
4826    assert_eq!(runner.cwd(), None);
4827    assert_eq!(runner.args(), None);
4828  }
4829
4830  #[test]
4831  fn test_runner_config_from_string() {
4832    use super::RunnerConfig;
4833
4834    // Test From<String> trait
4835    let runner: RunnerConfig = "another_runner".to_string().into();
4836    assert_eq!(runner.cmd(), "another_runner");
4837    assert_eq!(runner.cwd(), None);
4838    assert_eq!(runner.args(), None);
4839  }
4840
4841  #[test]
4842  fn test_runner_config_from_str_parse() {
4843    use super::RunnerConfig;
4844    use std::str::FromStr;
4845
4846    // Test FromStr trait
4847    let runner = RunnerConfig::from_str("parsed_runner").unwrap();
4848    assert_eq!(runner.cmd(), "parsed_runner");
4849    assert_eq!(runner.cwd(), None);
4850    assert_eq!(runner.args(), None);
4851  }
4852
4853  #[test]
4854  fn test_runner_config_in_build_config() {
4855    use super::BuildConfig;
4856
4857    // Test string format in BuildConfig
4858    let json = r#"{"runner": "cargo"}"#;
4859    let build_config: BuildConfig = serde_json::from_str(json).unwrap();
4860
4861    let runner = build_config.runner.unwrap();
4862    assert_eq!(runner.cmd(), "cargo");
4863    assert_eq!(runner.cwd(), None);
4864    assert_eq!(runner.args(), None);
4865  }
4866
4867  #[test]
4868  fn test_runner_config_in_build_config_object() {
4869    use super::BuildConfig;
4870
4871    // Test object format in BuildConfig
4872    let json = r#"{"runner": {"cmd": "cross", "cwd": "/workspace", "args": ["--target", "x86_64-unknown-linux-gnu"]}}"#;
4873    let build_config: BuildConfig = serde_json::from_str(json).unwrap();
4874
4875    let runner = build_config.runner.unwrap();
4876    assert_eq!(runner.cmd(), "cross");
4877    assert_eq!(runner.cwd(), Some("/workspace"));
4878    assert_eq!(
4879      runner.args(),
4880      Some(
4881        &[
4882          "--target".to_string(),
4883          "x86_64-unknown-linux-gnu".to_string()
4884        ][..]
4885      )
4886    );
4887  }
4888
4889  #[test]
4890  fn test_runner_config_in_full_config() {
4891    use super::Config;
4892
4893    // Test runner config in full Tauri config
4894    let json = r#"{
4895      "productName": "Test App",
4896      "version": "1.0.0",
4897      "identifier": "com.test.app",
4898      "build": {
4899        "runner": {
4900          "cmd": "my_custom_cargo",
4901          "cwd": "/tmp/build",
4902          "args": ["--quiet", "--verbose"]
4903        }
4904      }
4905    }"#;
4906
4907    let config: Config = serde_json::from_str(json).unwrap();
4908    let runner = config.build.runner.unwrap();
4909
4910    assert_eq!(runner.cmd(), "my_custom_cargo");
4911    assert_eq!(runner.cwd(), Some("/tmp/build"));
4912    assert_eq!(
4913      runner.args(),
4914      Some(&["--quiet".to_string(), "--verbose".to_string()][..])
4915    );
4916  }
4917
4918  #[test]
4919  fn test_runner_config_equality() {
4920    use super::RunnerConfig;
4921
4922    let runner1 = RunnerConfig::String("cargo".to_string());
4923    let runner2 = RunnerConfig::String("cargo".to_string());
4924    let runner3 = RunnerConfig::String("cross".to_string());
4925
4926    assert_eq!(runner1, runner2);
4927    assert_ne!(runner1, runner3);
4928
4929    let runner4 = RunnerConfig::Object {
4930      cmd: "cargo".to_string(),
4931      cwd: Some("/tmp".to_string()),
4932      args: Some(vec!["--quiet".to_string()]),
4933    };
4934    let runner5 = RunnerConfig::Object {
4935      cmd: "cargo".to_string(),
4936      cwd: Some("/tmp".to_string()),
4937      args: Some(vec!["--quiet".to_string()]),
4938    };
4939
4940    assert_eq!(runner4, runner5);
4941    assert_ne!(runner1, runner4);
4942  }
4943
4944  #[test]
4945  fn test_runner_config_untagged_serialization() {
4946    use super::RunnerConfig;
4947
4948    // Test that serde untagged works correctly - string should serialize as string, not object
4949    let string_runner = RunnerConfig::String("cargo".to_string());
4950    let string_json = serde_json::to_string(&string_runner).unwrap();
4951    assert_eq!(string_json, r#""cargo""#);
4952
4953    // Test that object serializes as object
4954    let object_runner = RunnerConfig::Object {
4955      cmd: "cross".to_string(),
4956      cwd: None,
4957      args: None,
4958    };
4959    let object_json = serde_json::to_string(&object_runner).unwrap();
4960    assert!(object_json.contains("\"cmd\":\"cross\""));
4961    // With skip_serializing_none, null values should not be included
4962    assert!(object_json.contains("\"cwd\":null") || !object_json.contains("cwd"));
4963    assert!(object_json.contains("\"args\":null") || !object_json.contains("args"));
4964  }
4965
4966  #[test]
4967  fn header_source_map_display_is_deterministic() {
4968    let map = HashMap::from([
4969      ("key3".to_string(), "'value3'".to_string()),
4970      ("key1".to_string(), "'value1' 'value2'".to_string()),
4971      ("key2".to_string(), "'value4'".to_string()),
4972    ]);
4973
4974    // the value must be sorted by key and stable across runs and across `HashMap` orderings
4975    assert_eq!(
4976      HeaderSource::Map(map.clone()).to_string(),
4977      "key1 'value1' 'value2'; key2 'value4'; key3 'value3'"
4978    );
4979
4980    let expected = HeaderSource::Map(map).to_string();
4981    for _ in 0..10 {
4982      let map = HashMap::from([
4983        ("key2".to_string(), "'value4'".to_string()),
4984        ("key3".to_string(), "'value3'".to_string()),
4985        ("key1".to_string(), "'value1' 'value2'".to_string()),
4986      ]);
4987      assert_eq!(HeaderSource::Map(map).to_string(), expected);
4988    }
4989
4990    // `Serialize` must keep matching `Display`'s ordering
4991    let map = HashMap::from([
4992      ("b".to_string(), "2".to_string()),
4993      ("a".to_string(), "1".to_string()),
4994    ]);
4995    assert_eq!(
4996      serde_json::to_string(&HeaderSource::Map(map)).unwrap(),
4997      r#"{"a":"1","b":"2"}"#
4998    );
4999  }
5000
5001  #[test]
5002  fn header_source_display() {
5003    assert_eq!(
5004      HeaderSource::Inline("same-origin".into()).to_string(),
5005      "same-origin"
5006    );
5007    assert_eq!(
5008      HeaderSource::List(vec!["https://a.example".into(), "https://b.example".into()]).to_string(),
5009      "https://a.example, https://b.example"
5010    );
5011  }
5012
5013  #[test]
5014  fn window_config_default_same_as_deserialize() {
5015    let config_from_deserialization: WindowConfig = serde_json::from_str("{}").unwrap();
5016    let config_from_default: WindowConfig = WindowConfig::default();
5017
5018    assert_eq!(config_from_deserialization, config_from_default);
5019  }
5020}