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