config.rs 107 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989
  1. // Copyright 2019-2024 Tauri Programme within The Commons Conservancy
  2. // SPDX-License-Identifier: Apache-2.0
  3. // SPDX-License-Identifier: MIT
  4. //! The Tauri configuration used at runtime.
  5. //!
  6. //! It is pulled from a `tauri.conf.json` file and the [`Config`] struct is generated at compile time.
  7. //!
  8. //! # Stability
  9. //!
  10. //! This is a core functionality that is not considered part of the stable API.
  11. //! If you use it, note that it may include breaking changes in the future.
  12. //!
  13. //! These items are intended to be non-breaking from a de/serialization standpoint only.
  14. //! Using and modifying existing config values will try to avoid breaking changes, but they are
  15. //! free to add fields in the future - causing breaking changes for creating and full destructuring.
  16. //!
  17. //! To avoid this, [ignore unknown fields when destructuring] with the `{my, config, ..}` pattern.
  18. //! If you need to create the Rust config directly without deserializing, then create the struct
  19. //! the [Struct Update Syntax] with `..Default::default()`, which may need a
  20. //! `#[allow(clippy::needless_update)]` attribute if you are declaring all fields.
  21. //!
  22. //! [ignore unknown fields when destructuring]: https://doc.rust-lang.org/book/ch18-03-pattern-syntax.html#ignoring-remaining-parts-of-a-value-with-
  23. //! [Struct Update Syntax]: https://doc.rust-lang.org/book/ch05-01-defining-structs.html#creating-instances-from-other-instances-with-struct-update-syntax
  24. #[cfg(feature = "schema")]
  25. use schemars::JsonSchema;
  26. use semver::Version;
  27. use serde::{
  28. de::{Deserializer, Error as DeError, Visitor},
  29. Deserialize, Serialize, Serializer,
  30. };
  31. use serde_json::Value as JsonValue;
  32. use serde_untagged::UntaggedEnumVisitor;
  33. use serde_with::skip_serializing_none;
  34. use url::Url;
  35. use std::{
  36. collections::HashMap,
  37. fmt::{self, Display},
  38. fs::read_to_string,
  39. path::PathBuf,
  40. str::FromStr,
  41. };
  42. /// Items to help with parsing content into a [`Config`].
  43. pub mod parse;
  44. use crate::{acl::capability::Capability, TitleBarStyle, WindowEffect, WindowEffectState};
  45. pub use self::parse::parse;
  46. fn default_true() -> bool {
  47. true
  48. }
  49. /// An URL to open on a Tauri webview window.
  50. #[derive(PartialEq, Eq, Debug, Clone, Serialize)]
  51. #[cfg_attr(feature = "schema", derive(JsonSchema))]
  52. #[serde(untagged)]
  53. #[non_exhaustive]
  54. pub enum WebviewUrl {
  55. /// An external URL. Must use either the `http` or `https` schemes.
  56. External(Url),
  57. /// The path portion of an app URL.
  58. /// For instance, to load `tauri://localhost/users/john`,
  59. /// you can simply provide `users/john` in this configuration.
  60. App(PathBuf),
  61. /// A custom protocol url, for example, `doom://index.html`
  62. CustomProtocol(Url),
  63. }
  64. impl<'de> Deserialize<'de> for WebviewUrl {
  65. fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
  66. where
  67. D: Deserializer<'de>,
  68. {
  69. #[derive(Deserialize)]
  70. #[serde(untagged)]
  71. enum WebviewUrlDeserializer {
  72. Url(Url),
  73. Path(PathBuf),
  74. }
  75. match WebviewUrlDeserializer::deserialize(deserializer)? {
  76. WebviewUrlDeserializer::Url(u) => {
  77. if u.scheme() == "https" || u.scheme() == "http" {
  78. Ok(Self::External(u))
  79. } else {
  80. Ok(Self::CustomProtocol(u))
  81. }
  82. }
  83. WebviewUrlDeserializer::Path(p) => Ok(Self::App(p)),
  84. }
  85. }
  86. }
  87. impl fmt::Display for WebviewUrl {
  88. fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
  89. match self {
  90. Self::External(url) | Self::CustomProtocol(url) => write!(f, "{url}"),
  91. Self::App(path) => write!(f, "{}", path.display()),
  92. }
  93. }
  94. }
  95. impl Default for WebviewUrl {
  96. fn default() -> Self {
  97. Self::App("index.html".into())
  98. }
  99. }
  100. /// A bundle referenced by tauri-bundler.
  101. #[derive(Debug, PartialEq, Eq, Clone)]
  102. #[cfg_attr(feature = "schema", derive(JsonSchema))]
  103. #[cfg_attr(feature = "schema", schemars(rename_all = "lowercase"))]
  104. pub enum BundleType {
  105. /// The debian bundle (.deb).
  106. Deb,
  107. /// The RPM bundle (.rpm).
  108. Rpm,
  109. /// The AppImage bundle (.appimage).
  110. AppImage,
  111. /// The Microsoft Installer bundle (.msi).
  112. Msi,
  113. /// The NSIS bundle (.exe).
  114. Nsis,
  115. /// The macOS application bundle (.app).
  116. App,
  117. /// The Apple Disk Image bundle (.dmg).
  118. Dmg,
  119. }
  120. impl BundleType {
  121. /// All bundle types.
  122. fn all() -> &'static [Self] {
  123. &[
  124. BundleType::Deb,
  125. BundleType::Rpm,
  126. BundleType::AppImage,
  127. BundleType::Msi,
  128. BundleType::Nsis,
  129. BundleType::App,
  130. BundleType::Dmg,
  131. ]
  132. }
  133. }
  134. impl Display for BundleType {
  135. fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
  136. write!(
  137. f,
  138. "{}",
  139. match self {
  140. Self::Deb => "deb",
  141. Self::Rpm => "rpm",
  142. Self::AppImage => "appimage",
  143. Self::Msi => "msi",
  144. Self::Nsis => "nsis",
  145. Self::App => "app",
  146. Self::Dmg => "dmg",
  147. }
  148. )
  149. }
  150. }
  151. impl Serialize for BundleType {
  152. fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
  153. where
  154. S: Serializer,
  155. {
  156. serializer.serialize_str(self.to_string().as_ref())
  157. }
  158. }
  159. impl<'de> Deserialize<'de> for BundleType {
  160. fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
  161. where
  162. D: Deserializer<'de>,
  163. {
  164. let s = String::deserialize(deserializer)?;
  165. match s.to_lowercase().as_str() {
  166. "deb" => Ok(Self::Deb),
  167. "rpm" => Ok(Self::Rpm),
  168. "appimage" => Ok(Self::AppImage),
  169. "msi" => Ok(Self::Msi),
  170. "nsis" => Ok(Self::Nsis),
  171. "app" => Ok(Self::App),
  172. "dmg" => Ok(Self::Dmg),
  173. _ => Err(DeError::custom(format!("unknown bundle target '{s}'"))),
  174. }
  175. }
  176. }
  177. /// Targets to bundle. Each value is case insensitive.
  178. #[derive(Debug, PartialEq, Eq, Clone)]
  179. pub enum BundleTarget {
  180. /// Bundle all targets.
  181. All,
  182. /// A list of bundle targets.
  183. List(Vec<BundleType>),
  184. /// A single bundle target.
  185. One(BundleType),
  186. }
  187. #[cfg(feature = "schema")]
  188. impl schemars::JsonSchema for BundleTarget {
  189. fn schema_name() -> std::string::String {
  190. "BundleTarget".to_owned()
  191. }
  192. fn json_schema(gen: &mut schemars::gen::SchemaGenerator) -> schemars::schema::Schema {
  193. let any_of = vec![
  194. schemars::schema::SchemaObject {
  195. const_value: Some("all".into()),
  196. metadata: Some(Box::new(schemars::schema::Metadata {
  197. description: Some("Bundle all targets.".to_owned()),
  198. ..Default::default()
  199. })),
  200. ..Default::default()
  201. }
  202. .into(),
  203. schemars::_private::metadata::add_description(
  204. gen.subschema_for::<Vec<BundleType>>(),
  205. "A list of bundle targets.",
  206. ),
  207. schemars::_private::metadata::add_description(
  208. gen.subschema_for::<BundleType>(),
  209. "A single bundle target.",
  210. ),
  211. ];
  212. schemars::schema::SchemaObject {
  213. subschemas: Some(Box::new(schemars::schema::SubschemaValidation {
  214. any_of: Some(any_of),
  215. ..Default::default()
  216. })),
  217. metadata: Some(Box::new(schemars::schema::Metadata {
  218. description: Some("Targets to bundle. Each value is case insensitive.".to_owned()),
  219. ..Default::default()
  220. })),
  221. ..Default::default()
  222. }
  223. .into()
  224. }
  225. }
  226. impl Default for BundleTarget {
  227. fn default() -> Self {
  228. Self::All
  229. }
  230. }
  231. impl Serialize for BundleTarget {
  232. fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
  233. where
  234. S: Serializer,
  235. {
  236. match self {
  237. Self::All => serializer.serialize_str("all"),
  238. Self::List(l) => l.serialize(serializer),
  239. Self::One(t) => serializer.serialize_str(t.to_string().as_ref()),
  240. }
  241. }
  242. }
  243. impl<'de> Deserialize<'de> for BundleTarget {
  244. fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
  245. where
  246. D: Deserializer<'de>,
  247. {
  248. #[derive(Deserialize, Serialize)]
  249. #[serde(untagged)]
  250. pub enum BundleTargetInner {
  251. List(Vec<BundleType>),
  252. One(BundleType),
  253. All(String),
  254. }
  255. match BundleTargetInner::deserialize(deserializer)? {
  256. BundleTargetInner::All(s) if s.to_lowercase() == "all" => Ok(Self::All),
  257. BundleTargetInner::All(t) => Err(DeError::custom(format!(
  258. "invalid bundle type {t}, expected one of `all`, {}",
  259. BundleType::all()
  260. .iter()
  261. .map(|b| format!("`{b}`"))
  262. .collect::<Vec<_>>()
  263. .join(", ")
  264. ))),
  265. BundleTargetInner::List(l) => Ok(Self::List(l)),
  266. BundleTargetInner::One(t) => Ok(Self::One(t)),
  267. }
  268. }
  269. }
  270. impl BundleTarget {
  271. /// Gets the bundle targets as a [`Vec`]. The vector is empty when set to [`BundleTarget::All`].
  272. #[allow(dead_code)]
  273. pub fn to_vec(&self) -> Vec<BundleType> {
  274. match self {
  275. Self::All => BundleType::all().to_vec(),
  276. Self::List(list) => list.clone(),
  277. Self::One(i) => vec![i.clone()],
  278. }
  279. }
  280. }
  281. /// Configuration for AppImage bundles.
  282. ///
  283. /// See more: <https://v2.tauri.app/reference/config/#appimageconfig>
  284. #[derive(Debug, Default, PartialEq, Eq, Clone, Deserialize, Serialize)]
  285. #[cfg_attr(feature = "schema", derive(JsonSchema))]
  286. #[serde(rename_all = "camelCase", deny_unknown_fields)]
  287. pub struct AppImageConfig {
  288. /// Include additional gstreamer dependencies needed for audio and video playback.
  289. /// This increases the bundle size by ~15-35MB depending on your build system.
  290. #[serde(default, alias = "bundle-media-framework")]
  291. pub bundle_media_framework: bool,
  292. /// The files to include in the Appimage Binary.
  293. #[serde(default)]
  294. pub files: HashMap<PathBuf, PathBuf>,
  295. }
  296. /// Configuration for Debian (.deb) bundles.
  297. ///
  298. /// See more: <https://v2.tauri.app/reference/config/#debconfig>
  299. #[skip_serializing_none]
  300. #[derive(Debug, Default, PartialEq, Eq, Clone, Deserialize, Serialize)]
  301. #[cfg_attr(feature = "schema", derive(JsonSchema))]
  302. #[serde(rename_all = "camelCase", deny_unknown_fields)]
  303. pub struct DebConfig {
  304. /// The list of deb dependencies your application relies on.
  305. pub depends: Option<Vec<String>>,
  306. /// The list of deb dependencies your application recommends.
  307. pub recommends: Option<Vec<String>>,
  308. /// The list of dependencies the package provides.
  309. pub provides: Option<Vec<String>>,
  310. /// The list of package conflicts.
  311. pub conflicts: Option<Vec<String>>,
  312. /// The list of package replaces.
  313. pub replaces: Option<Vec<String>>,
  314. /// The files to include on the package.
  315. #[serde(default)]
  316. pub files: HashMap<PathBuf, PathBuf>,
  317. /// Define the section in Debian Control file. See : https://www.debian.org/doc/debian-policy/ch-archive.html#s-subsections
  318. pub section: Option<String>,
  319. /// Change the priority of the Debian Package. By default, it is set to `optional`.
  320. /// Recognized Priorities as of now are : `required`, `important`, `standard`, `optional`, `extra`
  321. pub priority: Option<String>,
  322. /// Path of the uncompressed Changelog file, to be stored at /usr/share/doc/package-name/changelog.gz. See
  323. /// <https://www.debian.org/doc/debian-policy/ch-docs.html#changelog-files-and-release-notes>
  324. pub changelog: Option<PathBuf>,
  325. /// Path to a custom desktop file Handlebars template.
  326. ///
  327. /// Available variables: `categories`, `comment` (optional), `exec`, `icon` and `name`.
  328. #[serde(alias = "desktop-template")]
  329. pub desktop_template: Option<PathBuf>,
  330. /// Path to script that will be executed before the package is unpacked. See
  331. /// <https://www.debian.org/doc/debian-policy/ch-maintainerscripts.html>
  332. #[serde(alias = "pre-install-script")]
  333. pub pre_install_script: Option<PathBuf>,
  334. /// Path to script that will be executed after the package is unpacked. See
  335. /// <https://www.debian.org/doc/debian-policy/ch-maintainerscripts.html>
  336. #[serde(alias = "post-install-script")]
  337. pub post_install_script: Option<PathBuf>,
  338. /// Path to script that will be executed before the package is removed. See
  339. /// <https://www.debian.org/doc/debian-policy/ch-maintainerscripts.html>
  340. #[serde(alias = "pre-remove-script")]
  341. pub pre_remove_script: Option<PathBuf>,
  342. /// Path to script that will be executed after the package is removed. See
  343. /// <https://www.debian.org/doc/debian-policy/ch-maintainerscripts.html>
  344. #[serde(alias = "post-remove-script")]
  345. pub post_remove_script: Option<PathBuf>,
  346. }
  347. /// Configuration for Linux bundles.
  348. ///
  349. /// See more: <https://v2.tauri.app/reference/config/#linuxconfig>
  350. #[skip_serializing_none]
  351. #[derive(Debug, Default, PartialEq, Eq, Clone, Deserialize, Serialize)]
  352. #[cfg_attr(feature = "schema", derive(JsonSchema))]
  353. #[serde(rename_all = "camelCase", deny_unknown_fields)]
  354. pub struct LinuxConfig {
  355. /// Configuration for the AppImage bundle.
  356. #[serde(default)]
  357. pub appimage: AppImageConfig,
  358. /// Configuration for the Debian bundle.
  359. #[serde(default)]
  360. pub deb: DebConfig,
  361. /// Configuration for the RPM bundle.
  362. #[serde(default)]
  363. pub rpm: RpmConfig,
  364. }
  365. /// Configuration for RPM bundles.
  366. #[skip_serializing_none]
  367. #[derive(Debug, PartialEq, Eq, Clone, Deserialize, Serialize)]
  368. #[cfg_attr(feature = "schema", derive(JsonSchema))]
  369. #[serde(rename_all = "camelCase", deny_unknown_fields)]
  370. pub struct RpmConfig {
  371. /// The list of RPM dependencies your application relies on.
  372. pub depends: Option<Vec<String>>,
  373. /// The list of RPM dependencies your application recommends.
  374. pub recommends: Option<Vec<String>>,
  375. /// The list of RPM dependencies your application provides.
  376. pub provides: Option<Vec<String>>,
  377. /// The list of RPM dependencies your application conflicts with. They must not be present
  378. /// in order for the package to be installed.
  379. pub conflicts: Option<Vec<String>>,
  380. /// The list of RPM dependencies your application supersedes - if this package is installed,
  381. /// packages listed as "obsoletes" will be automatically removed (if they are present).
  382. pub obsoletes: Option<Vec<String>>,
  383. /// The RPM release tag.
  384. #[serde(default = "default_release")]
  385. pub release: String,
  386. /// The RPM epoch.
  387. #[serde(default)]
  388. pub epoch: u32,
  389. /// The files to include on the package.
  390. #[serde(default)]
  391. pub files: HashMap<PathBuf, PathBuf>,
  392. /// Path to a custom desktop file Handlebars template.
  393. ///
  394. /// Available variables: `categories`, `comment` (optional), `exec`, `icon` and `name`.
  395. #[serde(alias = "desktop-template")]
  396. pub desktop_template: Option<PathBuf>,
  397. /// Path to script that will be executed before the package is unpacked. See
  398. /// <http://ftp.rpm.org/max-rpm/s1-rpm-inside-scripts.html>
  399. #[serde(alias = "pre-install-script")]
  400. pub pre_install_script: Option<PathBuf>,
  401. /// Path to script that will be executed after the package is unpacked. See
  402. /// <http://ftp.rpm.org/max-rpm/s1-rpm-inside-scripts.html>
  403. #[serde(alias = "post-install-script")]
  404. pub post_install_script: Option<PathBuf>,
  405. /// Path to script that will be executed before the package is removed. See
  406. /// <http://ftp.rpm.org/max-rpm/s1-rpm-inside-scripts.html>
  407. #[serde(alias = "pre-remove-script")]
  408. pub pre_remove_script: Option<PathBuf>,
  409. /// Path to script that will be executed after the package is removed. See
  410. /// <http://ftp.rpm.org/max-rpm/s1-rpm-inside-scripts.html>
  411. #[serde(alias = "post-remove-script")]
  412. pub post_remove_script: Option<PathBuf>,
  413. }
  414. impl Default for RpmConfig {
  415. fn default() -> Self {
  416. Self {
  417. depends: None,
  418. recommends: None,
  419. provides: None,
  420. conflicts: None,
  421. obsoletes: None,
  422. release: default_release(),
  423. epoch: 0,
  424. files: Default::default(),
  425. desktop_template: None,
  426. pre_install_script: None,
  427. post_install_script: None,
  428. pre_remove_script: None,
  429. post_remove_script: None,
  430. }
  431. }
  432. }
  433. fn default_release() -> String {
  434. "1".into()
  435. }
  436. /// Position coordinates struct.
  437. #[derive(Default, Debug, PartialEq, Eq, Clone, Deserialize, Serialize)]
  438. #[cfg_attr(feature = "schema", derive(JsonSchema))]
  439. #[serde(rename_all = "camelCase", deny_unknown_fields)]
  440. pub struct Position {
  441. /// X coordinate.
  442. pub x: u32,
  443. /// Y coordinate.
  444. pub y: u32,
  445. }
  446. /// Size of the window.
  447. #[derive(Default, Debug, PartialEq, Eq, Clone, Deserialize, Serialize)]
  448. #[cfg_attr(feature = "schema", derive(JsonSchema))]
  449. #[serde(rename_all = "camelCase", deny_unknown_fields)]
  450. pub struct Size {
  451. /// Width of the window.
  452. pub width: u32,
  453. /// Height of the window.
  454. pub height: u32,
  455. }
  456. /// Configuration for Apple Disk Image (.dmg) bundles.
  457. ///
  458. /// See more: <https://v2.tauri.app/reference/config/#dmgconfig>
  459. #[skip_serializing_none]
  460. #[derive(Debug, PartialEq, Eq, Clone, Deserialize, Serialize)]
  461. #[cfg_attr(feature = "schema", derive(JsonSchema))]
  462. #[serde(rename_all = "camelCase", deny_unknown_fields)]
  463. pub struct DmgConfig {
  464. /// Image to use as the background in dmg file. Accepted formats: `png`/`jpg`/`gif`.
  465. pub background: Option<PathBuf>,
  466. /// Position of volume window on screen.
  467. pub window_position: Option<Position>,
  468. /// Size of volume window.
  469. #[serde(default = "dmg_window_size", alias = "window-size")]
  470. pub window_size: Size,
  471. /// Position of app file on window.
  472. #[serde(default = "dmg_app_position", alias = "app-position")]
  473. pub app_position: Position,
  474. /// Position of application folder on window.
  475. #[serde(
  476. default = "dmg_application_folder_position",
  477. alias = "application-folder-position"
  478. )]
  479. pub application_folder_position: Position,
  480. }
  481. impl Default for DmgConfig {
  482. fn default() -> Self {
  483. Self {
  484. background: None,
  485. window_position: None,
  486. window_size: dmg_window_size(),
  487. app_position: dmg_app_position(),
  488. application_folder_position: dmg_application_folder_position(),
  489. }
  490. }
  491. }
  492. fn dmg_window_size() -> Size {
  493. Size {
  494. width: 660,
  495. height: 400,
  496. }
  497. }
  498. fn dmg_app_position() -> Position {
  499. Position { x: 180, y: 170 }
  500. }
  501. fn dmg_application_folder_position() -> Position {
  502. Position { x: 480, y: 170 }
  503. }
  504. fn de_macos_minimum_system_version<'de, D>(deserializer: D) -> Result<Option<String>, D::Error>
  505. where
  506. D: Deserializer<'de>,
  507. {
  508. let version = Option::<String>::deserialize(deserializer)?;
  509. match version {
  510. Some(v) if v.is_empty() => Ok(macos_minimum_system_version()),
  511. e => Ok(e),
  512. }
  513. }
  514. /// Configuration for the macOS bundles.
  515. ///
  516. /// See more: <https://v2.tauri.app/reference/config/#macconfig>
  517. #[skip_serializing_none]
  518. #[derive(Debug, PartialEq, Eq, Clone, Deserialize, Serialize)]
  519. #[cfg_attr(feature = "schema", derive(JsonSchema))]
  520. #[serde(rename_all = "camelCase", deny_unknown_fields)]
  521. pub struct MacConfig {
  522. /// A list of strings indicating any macOS X frameworks that need to be bundled with the application.
  523. ///
  524. /// 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.
  525. pub frameworks: Option<Vec<String>>,
  526. /// The files to include in the application relative to the Contents directory.
  527. #[serde(default)]
  528. pub files: HashMap<PathBuf, PathBuf>,
  529. /// A version string indicating the minimum macOS X version that the bundled application supports. Defaults to `10.13`.
  530. ///
  531. /// Setting it to `null` completely removes the `LSMinimumSystemVersion` field on the bundle's `Info.plist`
  532. /// and the `MACOSX_DEPLOYMENT_TARGET` environment variable.
  533. ///
  534. /// An empty string is considered an invalid value so the default value is used.
  535. #[serde(
  536. deserialize_with = "de_macos_minimum_system_version",
  537. default = "macos_minimum_system_version",
  538. alias = "minimum-system-version"
  539. )]
  540. pub minimum_system_version: Option<String>,
  541. /// Allows your application to communicate with the outside world.
  542. /// It should be a lowercase, without port and protocol domain name.
  543. #[serde(alias = "exception-domain")]
  544. pub exception_domain: Option<String>,
  545. /// Identity to use for code signing.
  546. #[serde(alias = "signing-identity")]
  547. pub signing_identity: Option<String>,
  548. /// Whether the codesign should enable [hardened runtime] (for executables) or not.
  549. ///
  550. /// [hardened runtime]: <https://developer.apple.com/documentation/security/hardened_runtime>
  551. #[serde(alias = "hardened-runtime", default = "default_true")]
  552. pub hardened_runtime: bool,
  553. /// Provider short name for notarization.
  554. #[serde(alias = "provider-short-name")]
  555. pub provider_short_name: Option<String>,
  556. /// Path to the entitlements file.
  557. pub entitlements: Option<String>,
  558. /// DMG-specific settings.
  559. #[serde(default)]
  560. pub dmg: DmgConfig,
  561. }
  562. impl Default for MacConfig {
  563. fn default() -> Self {
  564. Self {
  565. frameworks: None,
  566. files: HashMap::new(),
  567. minimum_system_version: macos_minimum_system_version(),
  568. exception_domain: None,
  569. signing_identity: None,
  570. hardened_runtime: true,
  571. provider_short_name: None,
  572. entitlements: None,
  573. dmg: Default::default(),
  574. }
  575. }
  576. }
  577. fn macos_minimum_system_version() -> Option<String> {
  578. Some("10.13".into())
  579. }
  580. fn ios_minimum_system_version() -> String {
  581. "13.0".into()
  582. }
  583. /// Configuration for a target language for the WiX build.
  584. ///
  585. /// See more: <https://v2.tauri.app/reference/config/#wixlanguageconfig>
  586. #[derive(Debug, PartialEq, Eq, Clone, Deserialize, Serialize)]
  587. #[cfg_attr(feature = "schema", derive(JsonSchema))]
  588. #[serde(rename_all = "camelCase", deny_unknown_fields)]
  589. pub struct WixLanguageConfig {
  590. /// The path to a locale (`.wxl`) file. See <https://wixtoolset.org/documentation/manual/v3/howtos/ui_and_localization/build_a_localized_version.html>.
  591. #[serde(alias = "locale-path")]
  592. pub locale_path: Option<String>,
  593. }
  594. /// The languages to build using WiX.
  595. #[derive(Debug, PartialEq, Eq, Clone, Deserialize, Serialize)]
  596. #[cfg_attr(feature = "schema", derive(JsonSchema))]
  597. #[serde(untagged)]
  598. pub enum WixLanguage {
  599. /// A single language to build, without configuration.
  600. One(String),
  601. /// A list of languages to build, without configuration.
  602. List(Vec<String>),
  603. /// A map of languages and its configuration.
  604. Localized(HashMap<String, WixLanguageConfig>),
  605. }
  606. impl Default for WixLanguage {
  607. fn default() -> Self {
  608. Self::One("en-US".into())
  609. }
  610. }
  611. /// Configuration for the MSI bundle using WiX.
  612. ///
  613. /// See more: <https://v2.tauri.app/reference/config/#wixconfig>
  614. #[derive(Debug, Default, PartialEq, Eq, Clone, Deserialize, Serialize)]
  615. #[cfg_attr(feature = "schema", derive(JsonSchema))]
  616. #[serde(rename_all = "camelCase", deny_unknown_fields)]
  617. pub struct WixConfig {
  618. /// MSI installer version in the format `major.minor.patch.build` (build is optional).
  619. ///
  620. /// Because a valid version is required for MSI installer, it will be derived from [`Config::version`] if this field is not set.
  621. ///
  622. /// 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.
  623. /// The third and foruth fields have a maximum value of 65,535.
  624. ///
  625. /// See <https://learn.microsoft.com/en-us/windows/win32/msi/productversion> for more info.
  626. pub version: Option<String>,
  627. /// A GUID upgrade code for MSI installer. This code **_must stay the same across all of your updates_**,
  628. /// otherwise, Windows will treat your update as a different app and your users will have duplicate versions of your app.
  629. ///
  630. /// By default, tauri generates this code by generating a Uuid v5 using the string `<productName>.exe.app.x64` in the DNS namespace.
  631. /// You can use Tauri's CLI to generate and print this code for you, run `tauri inspect wix-upgrade-code`.
  632. ///
  633. /// It is recommended that you set this value in your tauri config file to avoid accidental changes in your upgrade code
  634. /// whenever you want to change your product name.
  635. #[serde(alias = "upgrade-code")]
  636. pub upgrade_code: Option<uuid::Uuid>,
  637. /// The installer languages to build. See <https://docs.microsoft.com/en-us/windows/win32/msi/localizing-the-error-and-actiontext-tables>.
  638. #[serde(default)]
  639. pub language: WixLanguage,
  640. /// A custom .wxs template to use.
  641. pub template: Option<PathBuf>,
  642. /// A list of paths to .wxs files with WiX fragments to use.
  643. #[serde(default, alias = "fragment-paths")]
  644. pub fragment_paths: Vec<PathBuf>,
  645. /// The ComponentGroup element ids you want to reference from the fragments.
  646. #[serde(default, alias = "component-group-refs")]
  647. pub component_group_refs: Vec<String>,
  648. /// The Component element ids you want to reference from the fragments.
  649. #[serde(default, alias = "component-refs")]
  650. pub component_refs: Vec<String>,
  651. /// The FeatureGroup element ids you want to reference from the fragments.
  652. #[serde(default, alias = "feature-group-refs")]
  653. pub feature_group_refs: Vec<String>,
  654. /// The Feature element ids you want to reference from the fragments.
  655. #[serde(default, alias = "feature-refs")]
  656. pub feature_refs: Vec<String>,
  657. /// The Merge element ids you want to reference from the fragments.
  658. #[serde(default, alias = "merge-refs")]
  659. pub merge_refs: Vec<String>,
  660. /// Create an elevated update task within Windows Task Scheduler.
  661. #[serde(default, alias = "enable-elevated-update-task")]
  662. pub enable_elevated_update_task: bool,
  663. /// Path to a bitmap file to use as the installation user interface banner.
  664. /// This bitmap will appear at the top of all but the first page of the installer.
  665. ///
  666. /// The required dimensions are 493px × 58px.
  667. #[serde(alias = "banner-path")]
  668. pub banner_path: Option<PathBuf>,
  669. /// Path to a bitmap file to use on the installation user interface dialogs.
  670. /// It is used on the welcome and completion dialogs.
  671. /// The required dimensions are 493px × 312px.
  672. #[serde(alias = "dialog-image-path")]
  673. pub dialog_image_path: Option<PathBuf>,
  674. }
  675. /// Compression algorithms used in the NSIS installer.
  676. ///
  677. /// See <https://nsis.sourceforge.io/Reference/SetCompressor>
  678. #[derive(Debug, PartialEq, Eq, Clone, Copy, Serialize, Deserialize)]
  679. #[cfg_attr(feature = "schema", derive(JsonSchema))]
  680. #[serde(rename_all = "camelCase", deny_unknown_fields)]
  681. pub enum NsisCompression {
  682. /// ZLIB uses the deflate algorithm, it is a quick and simple method. With the default compression level it uses about 300 KB of memory.
  683. Zlib,
  684. /// 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.
  685. Bzip2,
  686. /// 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.
  687. Lzma,
  688. /// Disable compression
  689. None,
  690. }
  691. impl Default for NsisCompression {
  692. fn default() -> Self {
  693. Self::Lzma
  694. }
  695. }
  696. /// Install Modes for the NSIS installer.
  697. #[derive(Debug, PartialEq, Eq, Clone, Copy, Serialize, Deserialize)]
  698. #[serde(rename_all = "camelCase", deny_unknown_fields)]
  699. #[cfg_attr(feature = "schema", derive(JsonSchema))]
  700. pub enum NSISInstallerMode {
  701. /// Default mode for the installer.
  702. ///
  703. /// Install the app by default in a directory that doesn't require Administrator access.
  704. ///
  705. /// Installer metadata will be saved under the `HKCU` registry path.
  706. CurrentUser,
  707. /// Install the app by default in the `Program Files` folder directory requires Administrator
  708. /// access for the installation.
  709. ///
  710. /// Installer metadata will be saved under the `HKLM` registry path.
  711. PerMachine,
  712. /// Combines both modes and allows the user to choose at install time
  713. /// whether to install for the current user or per machine. Note that this mode
  714. /// will require Administrator access even if the user wants to install it for the current user only.
  715. ///
  716. /// Installer metadata will be saved under the `HKLM` or `HKCU` registry path based on the user's choice.
  717. Both,
  718. }
  719. impl Default for NSISInstallerMode {
  720. fn default() -> Self {
  721. Self::CurrentUser
  722. }
  723. }
  724. /// Configuration for the Installer bundle using NSIS.
  725. #[derive(Debug, Default, PartialEq, Eq, Clone, Deserialize, Serialize)]
  726. #[cfg_attr(feature = "schema", derive(JsonSchema))]
  727. #[serde(rename_all = "camelCase", deny_unknown_fields)]
  728. pub struct NsisConfig {
  729. /// A custom .nsi template to use.
  730. pub template: Option<PathBuf>,
  731. /// The path to a bitmap file to display on the header of installers pages.
  732. ///
  733. /// The recommended dimensions are 150px x 57px.
  734. #[serde(alias = "header-image")]
  735. pub header_image: Option<PathBuf>,
  736. /// The path to a bitmap file for the Welcome page and the Finish page.
  737. ///
  738. /// The recommended dimensions are 164px x 314px.
  739. #[serde(alias = "sidebar-image")]
  740. pub sidebar_image: Option<PathBuf>,
  741. /// The path to an icon file used as the installer icon.
  742. #[serde(alias = "install-icon")]
  743. pub installer_icon: Option<PathBuf>,
  744. /// Whether the installation will be for all users or just the current user.
  745. #[serde(default, alias = "install-mode")]
  746. pub install_mode: NSISInstallerMode,
  747. /// A list of installer languages.
  748. /// By default the OS language is used. If the OS language is not in the list of languages, the first language will be used.
  749. /// To allow the user to select the language, set `display_language_selector` to `true`.
  750. ///
  751. /// See <https://github.com/kichik/nsis/tree/9465c08046f00ccb6eda985abbdbf52c275c6c4d/Contrib/Language%20files> for the complete list of languages.
  752. pub languages: Option<Vec<String>>,
  753. /// A key-value pair where the key is the language and the
  754. /// value is the path to a custom `.nsh` file that holds the translated text for tauri's custom messages.
  755. ///
  756. /// See <https://github.com/tauri-apps/tauri/blob/dev/crates/tauri-bundler/src/bundle/windows/nsis/languages/English.nsh> for an example `.nsh` file.
  757. ///
  758. /// **Note**: the key must be a valid NSIS language and it must be added to [`NsisConfig`] languages array,
  759. pub custom_language_files: Option<HashMap<String, PathBuf>>,
  760. /// Whether to display a language selector dialog before the installer and uninstaller windows are rendered or not.
  761. /// By default the OS language is selected, with a fallback to the first language in the `languages` array.
  762. #[serde(default, alias = "display-language-selector")]
  763. pub display_language_selector: bool,
  764. /// Set the compression algorithm used to compress files in the installer.
  765. ///
  766. /// See <https://nsis.sourceforge.io/Reference/SetCompressor>
  767. #[serde(default)]
  768. pub compression: NsisCompression,
  769. /// Set the folder name for the start menu shortcut.
  770. ///
  771. /// Use this option if you have multiple apps and wish to group their shortcuts under one folder
  772. /// or if you generally prefer to set your shortcut inside a folder.
  773. ///
  774. /// Examples:
  775. /// - `AwesomePublisher`, shortcut will be placed in `%AppData%\Microsoft\Windows\Start Menu\Programs\AwesomePublisher\<your-app>.lnk`
  776. /// - If unset, shortcut will be placed in `%AppData%\Microsoft\Windows\Start Menu\Programs\<your-app>.lnk`
  777. #[serde(alias = "start-menu-folder")]
  778. pub start_menu_folder: Option<String>,
  779. /// A path to a `.nsh` file that contains special NSIS macros to be hooked into the
  780. /// main installer.nsi script.
  781. ///
  782. /// Supported hooks are:
  783. /// - `NSIS_HOOK_PREINSTALL`: This hook runs before copying files, setting registry key values and creating shortcuts.
  784. /// - `NSIS_HOOK_POSTINSTALL`: This hook runs after the installer has finished copying all files, setting the registry keys and created shortcuts.
  785. /// - `NSIS_HOOK_PREUNINSTALL`: This hook runs before removing any files, registry keys and shortcuts.
  786. /// - `NSIS_HOOK_POSTUNINSTALL`: This hook runs after files, registry keys and shortcuts have been removed.
  787. ///
  788. ///
  789. /// ### Example
  790. ///
  791. /// ```nsh
  792. /// !macro NSIS_HOOK_PREINSTALL
  793. /// MessageBox MB_OK "PreInstall"
  794. /// !macroend
  795. ///
  796. /// !macro NSIS_HOOK_POSTINSTALL
  797. /// MessageBox MB_OK "PostInstall"
  798. /// !macroend
  799. ///
  800. /// !macro NSIS_HOOK_PREUNINSTALL
  801. /// MessageBox MB_OK "PreUnInstall"
  802. /// !macroend
  803. ///
  804. /// !macro NSIS_HOOK_POSTUNINSTALL
  805. /// MessageBox MB_OK "PostUninstall"
  806. /// !macroend
  807. ///
  808. /// ```
  809. #[serde(alias = "installer-hooks")]
  810. pub installer_hooks: Option<PathBuf>,
  811. /// Try to ensure that the WebView2 version is equal to or newer than this version,
  812. /// if the user's WebView2 is older than this version,
  813. /// the installer will try to trigger a WebView2 update.
  814. #[serde(alias = "minimum-webview2-version")]
  815. pub minimum_webview2_version: Option<String>,
  816. }
  817. /// Install modes for the Webview2 runtime.
  818. /// Note that for the updater bundle [`Self::DownloadBootstrapper`] is used.
  819. ///
  820. /// For more information see <https://v2.tauri.app/distribute/windows-installer/#webview2-installation-options>.
  821. #[derive(Debug, PartialEq, Eq, Clone, Serialize, Deserialize)]
  822. #[serde(tag = "type", rename_all = "camelCase", deny_unknown_fields)]
  823. #[cfg_attr(feature = "schema", derive(JsonSchema))]
  824. pub enum WebviewInstallMode {
  825. /// Do not install the Webview2 as part of the Windows Installer.
  826. Skip,
  827. /// Download the bootstrapper and run it.
  828. /// Requires an internet connection.
  829. /// Results in a smaller installer size, but is not recommended on Windows 7.
  830. DownloadBootstrapper {
  831. /// Instructs the installer to run the bootstrapper in silent mode. Defaults to `true`.
  832. #[serde(default = "default_true")]
  833. silent: bool,
  834. },
  835. /// Embed the bootstrapper and run it.
  836. /// Requires an internet connection.
  837. /// Increases the installer size by around 1.8MB, but offers better support on Windows 7.
  838. EmbedBootstrapper {
  839. /// Instructs the installer to run the bootstrapper in silent mode. Defaults to `true`.
  840. #[serde(default = "default_true")]
  841. silent: bool,
  842. },
  843. /// Embed the offline installer and run it.
  844. /// Does not require an internet connection.
  845. /// Increases the installer size by around 127MB.
  846. OfflineInstaller {
  847. /// Instructs the installer to run the installer in silent mode. Defaults to `true`.
  848. #[serde(default = "default_true")]
  849. silent: bool,
  850. },
  851. /// Embed a fixed webview2 version and use it at runtime.
  852. /// Increases the installer size by around 180MB.
  853. FixedRuntime {
  854. /// The path to the fixed runtime to use.
  855. ///
  856. /// The fixed version can be downloaded [on the official website](https://developer.microsoft.com/en-us/microsoft-edge/webview2/#download-section).
  857. /// The `.cab` file must be extracted to a folder and this folder path must be defined on this field.
  858. path: PathBuf,
  859. },
  860. }
  861. impl Default for WebviewInstallMode {
  862. fn default() -> Self {
  863. Self::DownloadBootstrapper { silent: true }
  864. }
  865. }
  866. /// Custom Signing Command configuration.
  867. #[derive(Debug, PartialEq, Eq, Clone, Deserialize, Serialize)]
  868. #[cfg_attr(feature = "schema", derive(JsonSchema))]
  869. #[serde(rename_all = "camelCase", deny_unknown_fields, untagged)]
  870. pub enum CustomSignCommandConfig {
  871. /// A string notation of the script to execute.
  872. ///
  873. /// "%1" will be replaced with the path to the binary to be signed.
  874. ///
  875. /// This is a simpler notation for the command.
  876. /// Tauri will split the string with `' '` and use the first element as the command name and the rest as arguments.
  877. ///
  878. /// If you need to use whitespace in the command or arguments, use the object notation [`Self::ScriptWithOptions`].
  879. Command(String),
  880. /// An object notation of the command.
  881. ///
  882. /// This is more complex notation for the command but
  883. /// this allows you to use whitespace in the command and arguments.
  884. CommandWithOptions {
  885. /// The command to run to sign the binary.
  886. cmd: String,
  887. /// The arguments to pass to the command.
  888. ///
  889. /// "%1" will be replaced with the path to the binary to be signed.
  890. args: Vec<String>,
  891. },
  892. }
  893. /// Windows bundler configuration.
  894. ///
  895. /// See more: <https://v2.tauri.app/reference/config/#windowsconfig>
  896. #[derive(Debug, PartialEq, Eq, Clone, Deserialize, Serialize)]
  897. #[cfg_attr(feature = "schema", derive(JsonSchema))]
  898. #[serde(rename_all = "camelCase", deny_unknown_fields)]
  899. pub struct WindowsConfig {
  900. /// Specifies the file digest algorithm to use for creating file signatures.
  901. /// Required for code signing. SHA-256 is recommended.
  902. #[serde(alias = "digest-algorithm")]
  903. pub digest_algorithm: Option<String>,
  904. /// Specifies the SHA1 hash of the signing certificate.
  905. #[serde(alias = "certificate-thumbprint")]
  906. pub certificate_thumbprint: Option<String>,
  907. /// Server to use during timestamping.
  908. #[serde(alias = "timestamp-url")]
  909. pub timestamp_url: Option<String>,
  910. /// Whether to use Time-Stamp Protocol (TSP, a.k.a. RFC 3161) for the timestamp server. Your code signing provider may
  911. /// use a TSP timestamp server, like e.g. SSL.com does. If so, enable TSP by setting to true.
  912. #[serde(default)]
  913. pub tsp: bool,
  914. /// The installation mode for the Webview2 runtime.
  915. #[serde(default, alias = "webview-install-mode")]
  916. pub webview_install_mode: WebviewInstallMode,
  917. /// Validates a second app installation, blocking the user from installing an older version if set to `false`.
  918. ///
  919. /// 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`.
  920. ///
  921. /// The default value of this flag is `true`.
  922. #[serde(default = "default_true", alias = "allow-downgrades")]
  923. pub allow_downgrades: bool,
  924. /// Configuration for the MSI generated with WiX.
  925. pub wix: Option<WixConfig>,
  926. /// Configuration for the installer generated with NSIS.
  927. pub nsis: Option<NsisConfig>,
  928. /// Specify a custom command to sign the binaries.
  929. /// This command needs to have a `%1` in args which is just a placeholder for the binary path,
  930. /// which we will detect and replace before calling the command.
  931. ///
  932. /// By Default we use `signtool.exe` which can be found only on Windows so
  933. /// if you are on another platform and want to cross-compile and sign you will
  934. /// need to use another tool like `osslsigncode`.
  935. #[serde(alias = "sign-command")]
  936. pub sign_command: Option<CustomSignCommandConfig>,
  937. }
  938. impl Default for WindowsConfig {
  939. fn default() -> Self {
  940. Self {
  941. digest_algorithm: None,
  942. certificate_thumbprint: None,
  943. timestamp_url: None,
  944. tsp: false,
  945. webview_install_mode: Default::default(),
  946. allow_downgrades: true,
  947. wix: None,
  948. nsis: None,
  949. sign_command: None,
  950. }
  951. }
  952. }
  953. /// macOS-only. Corresponds to CFBundleTypeRole
  954. #[derive(Debug, Default, PartialEq, Eq, Clone, Deserialize, Serialize)]
  955. #[cfg_attr(feature = "schema", derive(JsonSchema))]
  956. pub enum BundleTypeRole {
  957. /// CFBundleTypeRole.Editor. Files can be read and edited.
  958. #[default]
  959. Editor,
  960. /// CFBundleTypeRole.Viewer. Files can be read.
  961. Viewer,
  962. /// CFBundleTypeRole.Shell
  963. Shell,
  964. /// CFBundleTypeRole.QLGenerator
  965. QLGenerator,
  966. /// CFBundleTypeRole.None
  967. None,
  968. }
  969. impl Display for BundleTypeRole {
  970. fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
  971. match self {
  972. Self::Editor => write!(f, "Editor"),
  973. Self::Viewer => write!(f, "Viewer"),
  974. Self::Shell => write!(f, "Shell"),
  975. Self::QLGenerator => write!(f, "QLGenerator"),
  976. Self::None => write!(f, "None"),
  977. }
  978. }
  979. }
  980. /// An extension for a [`FileAssociation`].
  981. ///
  982. /// A leading `.` is automatically stripped.
  983. #[derive(Debug, PartialEq, Eq, Clone, Serialize)]
  984. #[cfg_attr(feature = "schema", derive(JsonSchema))]
  985. pub struct AssociationExt(pub String);
  986. impl fmt::Display for AssociationExt {
  987. fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
  988. write!(f, "{}", self.0)
  989. }
  990. }
  991. impl<'d> serde::Deserialize<'d> for AssociationExt {
  992. fn deserialize<D: Deserializer<'d>>(deserializer: D) -> Result<Self, D::Error> {
  993. let ext = String::deserialize(deserializer)?;
  994. if let Some(ext) = ext.strip_prefix('.') {
  995. Ok(AssociationExt(ext.into()))
  996. } else {
  997. Ok(AssociationExt(ext))
  998. }
  999. }
  1000. }
  1001. /// File association
  1002. #[derive(Debug, PartialEq, Eq, Clone, Deserialize, Serialize)]
  1003. #[cfg_attr(feature = "schema", derive(JsonSchema))]
  1004. #[serde(rename_all = "camelCase", deny_unknown_fields)]
  1005. pub struct FileAssociation {
  1006. /// File extensions to associate with this app. e.g. 'png'
  1007. pub ext: Vec<AssociationExt>,
  1008. /// The name. Maps to `CFBundleTypeName` on macOS. Default to `ext[0]`
  1009. pub name: Option<String>,
  1010. /// The association description. Windows-only. It is displayed on the `Type` column on Windows Explorer.
  1011. pub description: Option<String>,
  1012. /// The app's role with respect to the type. Maps to `CFBundleTypeRole` on macOS.
  1013. #[serde(default)]
  1014. pub role: BundleTypeRole,
  1015. /// The mime-type e.g. 'image/png' or 'text/plain'. Linux-only.
  1016. #[serde(alias = "mime-type")]
  1017. pub mime_type: Option<String>,
  1018. }
  1019. /// Deep link protocol configuration.
  1020. #[derive(Debug, PartialEq, Eq, Clone, Deserialize, Serialize)]
  1021. #[cfg_attr(feature = "schema", derive(JsonSchema))]
  1022. #[serde(rename_all = "camelCase", deny_unknown_fields)]
  1023. pub struct DeepLinkProtocol {
  1024. /// URL schemes to associate with this app without `://`. For example `my-app`
  1025. pub schemes: Vec<String>,
  1026. /// The protocol name. **macOS-only** and maps to `CFBundleTypeName`. Defaults to `<bundle-id>.<schemes[0]>`
  1027. pub name: Option<String>,
  1028. /// The app's role for these schemes. **macOS-only** and maps to `CFBundleTypeRole`.
  1029. #[serde(default)]
  1030. pub role: BundleTypeRole,
  1031. }
  1032. /// Definition for bundle resources.
  1033. /// Can be either a list of paths to include or a map of source to target paths.
  1034. #[derive(Debug, PartialEq, Eq, Clone, Deserialize, Serialize)]
  1035. #[cfg_attr(feature = "schema", derive(JsonSchema))]
  1036. #[serde(rename_all = "camelCase", deny_unknown_fields, untagged)]
  1037. pub enum BundleResources {
  1038. /// A list of paths to include.
  1039. List(Vec<String>),
  1040. /// A map of source to target paths.
  1041. Map(HashMap<String, String>),
  1042. }
  1043. impl BundleResources {
  1044. /// Adds a path to the resource collection.
  1045. pub fn push(&mut self, path: impl Into<String>) {
  1046. match self {
  1047. Self::List(l) => l.push(path.into()),
  1048. Self::Map(l) => {
  1049. let path = path.into();
  1050. l.insert(path.clone(), path);
  1051. }
  1052. }
  1053. }
  1054. }
  1055. /// Updater type
  1056. #[derive(Debug, PartialEq, Eq, Clone, Deserialize, Serialize)]
  1057. #[cfg_attr(feature = "schema", derive(JsonSchema))]
  1058. #[serde(rename_all = "camelCase", deny_unknown_fields, untagged)]
  1059. pub enum Updater {
  1060. /// Generates lagacy zipped v1 compatible updaters
  1061. String(V1Compatible),
  1062. /// Produce updaters and their signatures or not
  1063. // Can't use untagged on enum field here: https://github.com/GREsau/schemars/issues/222
  1064. Bool(bool),
  1065. }
  1066. impl Default for Updater {
  1067. fn default() -> Self {
  1068. Self::Bool(false)
  1069. }
  1070. }
  1071. /// Generates lagacy zipped v1 compatible updaters
  1072. #[derive(Debug, PartialEq, Eq, Clone, Deserialize, Serialize)]
  1073. #[cfg_attr(feature = "schema", derive(JsonSchema))]
  1074. #[serde(rename_all = "camelCase", deny_unknown_fields)]
  1075. pub enum V1Compatible {
  1076. /// Generates lagacy zipped v1 compatible updaters
  1077. V1Compatible,
  1078. }
  1079. /// Configuration for tauri-bundler.
  1080. ///
  1081. /// See more: <https://v2.tauri.app/reference/config/#bundleconfig>
  1082. #[skip_serializing_none]
  1083. #[derive(Debug, Default, PartialEq, Eq, Clone, Deserialize, Serialize)]
  1084. #[cfg_attr(feature = "schema", derive(JsonSchema))]
  1085. #[serde(rename_all = "camelCase", deny_unknown_fields)]
  1086. pub struct BundleConfig {
  1087. /// Whether Tauri should bundle your application or just output the executable.
  1088. #[serde(default)]
  1089. pub active: bool,
  1090. /// The bundle targets, currently supports ["deb", "rpm", "appimage", "nsis", "msi", "app", "dmg"] or "all".
  1091. #[serde(default)]
  1092. pub targets: BundleTarget,
  1093. #[serde(default)]
  1094. /// Produce updaters and their signatures or not
  1095. pub create_updater_artifacts: Updater,
  1096. /// The application's publisher. Defaults to the second element in the identifier string.
  1097. ///
  1098. /// Currently maps to the Manufacturer property of the Windows Installer
  1099. /// and the Maintainer field of debian packages if the Cargo.toml does not have the authors field.
  1100. pub publisher: Option<String>,
  1101. /// A url to the home page of your application. If unset, will
  1102. /// fallback to `homepage` defined in `Cargo.toml`.
  1103. ///
  1104. /// Supported bundle targets: `deb`, `rpm`, `nsis` and `msi`.
  1105. pub homepage: Option<String>,
  1106. /// The app's icons
  1107. #[serde(default)]
  1108. pub icon: Vec<String>,
  1109. /// App resources to bundle.
  1110. /// Each resource is a path to a file or directory.
  1111. /// Glob patterns are supported.
  1112. pub resources: Option<BundleResources>,
  1113. /// A copyright string associated with your application.
  1114. pub copyright: Option<String>,
  1115. /// The package's license identifier to be included in the appropriate bundles.
  1116. /// If not set, defaults to the license from the Cargo.toml file.
  1117. pub license: Option<String>,
  1118. /// The path to the license file to be included in the appropriate bundles.
  1119. #[serde(alias = "license-file")]
  1120. pub license_file: Option<PathBuf>,
  1121. /// The application kind.
  1122. ///
  1123. /// Should be one of the following:
  1124. /// 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.
  1125. pub category: Option<String>,
  1126. /// File associations to application.
  1127. pub file_associations: Option<Vec<FileAssociation>>,
  1128. /// A short description of your application.
  1129. #[serde(alias = "short-description")]
  1130. pub short_description: Option<String>,
  1131. /// A longer, multi-line description of the application.
  1132. #[serde(alias = "long-description")]
  1133. pub long_description: Option<String>,
  1134. /// Whether to use the project's `target` directory, for caching build tools (e.g., Wix and NSIS) when building this application. Defaults to `false`.
  1135. ///
  1136. /// If true, tools will be cached in `target\.tauri-tools`.
  1137. /// If false, tools will be cached in the current user's platform-specific cache directory.
  1138. ///
  1139. /// 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),
  1140. /// because the Window system's app data directory is restricted.
  1141. #[serde(default, alias = "use-local-tools-dir")]
  1142. pub use_local_tools_dir: bool,
  1143. /// A list of—either absolute or relative—paths to binaries to embed with your application.
  1144. ///
  1145. /// Note that Tauri will look for system-specific binaries following the pattern "binary-name{-target-triple}{.system-extension}".
  1146. ///
  1147. /// E.g. for the external binary "my-binary", Tauri looks for:
  1148. ///
  1149. /// - "my-binary-x86_64-pc-windows-msvc.exe" for Windows
  1150. /// - "my-binary-x86_64-apple-darwin" for macOS
  1151. /// - "my-binary-x86_64-unknown-linux-gnu" for Linux
  1152. ///
  1153. /// so don't forget to provide binaries for all targeted platforms.
  1154. #[serde(alias = "external-bin")]
  1155. pub external_bin: Option<Vec<String>>,
  1156. /// Configuration for the Windows bundles.
  1157. #[serde(default)]
  1158. pub windows: WindowsConfig,
  1159. /// Configuration for the Linux bundles.
  1160. #[serde(default)]
  1161. pub linux: LinuxConfig,
  1162. /// Configuration for the macOS bundles.
  1163. #[serde(rename = "macOS", alias = "macos", default)]
  1164. pub macos: MacConfig,
  1165. /// iOS configuration.
  1166. #[serde(rename = "iOS", alias = "ios", default)]
  1167. pub ios: IosConfig,
  1168. /// Android configuration.
  1169. #[serde(default)]
  1170. pub android: AndroidConfig,
  1171. }
  1172. /// a tuple struct of RGBA colors. Each value has minimum of 0 and maximum of 255.
  1173. #[derive(Debug, PartialEq, Eq, Clone, Deserialize, Serialize, Default)]
  1174. #[cfg_attr(feature = "schema", derive(JsonSchema))]
  1175. #[serde(rename_all = "camelCase", deny_unknown_fields)]
  1176. pub struct Color(pub u8, pub u8, pub u8, pub u8);
  1177. impl From<Color> for (u8, u8, u8, u8) {
  1178. fn from(value: Color) -> Self {
  1179. (value.0, value.1, value.2, value.3)
  1180. }
  1181. }
  1182. /// The window effects configuration object
  1183. #[skip_serializing_none]
  1184. #[derive(Debug, PartialEq, Clone, Deserialize, Serialize, Default)]
  1185. #[cfg_attr(feature = "schema", derive(JsonSchema))]
  1186. #[serde(rename_all = "camelCase", deny_unknown_fields)]
  1187. pub struct WindowEffectsConfig {
  1188. /// List of Window effects to apply to the Window.
  1189. /// Conflicting effects will apply the first one and ignore the rest.
  1190. pub effects: Vec<WindowEffect>,
  1191. /// Window effect state **macOS Only**
  1192. pub state: Option<WindowEffectState>,
  1193. /// Window effect corner radius **macOS Only**
  1194. pub radius: Option<f64>,
  1195. /// Window effect color. Affects [`WindowEffect::Blur`] and [`WindowEffect::Acrylic`] only
  1196. /// on Windows 10 v1903+. Doesn't have any effect on Windows 7 or Windows 11.
  1197. pub color: Option<Color>,
  1198. }
  1199. /// The window configuration object.
  1200. ///
  1201. /// See more: <https://v2.tauri.app/reference/config/#windowconfig>
  1202. #[skip_serializing_none]
  1203. #[derive(Debug, PartialEq, Clone, Deserialize, Serialize)]
  1204. #[cfg_attr(feature = "schema", derive(JsonSchema))]
  1205. #[serde(rename_all = "camelCase", deny_unknown_fields)]
  1206. pub struct WindowConfig {
  1207. /// The window identifier. It must be alphanumeric.
  1208. #[serde(default = "default_window_label")]
  1209. pub label: String,
  1210. /// Whether Tauri should create this window at app startup or not.
  1211. ///
  1212. /// When this is set to `false` you must manually grab the config object via `app.config().app.windows`
  1213. /// and create it with [`WebviewWindowBuilder::from_config`](https://docs.rs/tauri/2.0.0-rc/tauri/webview/struct.WebviewWindowBuilder.html#method.from_config).
  1214. #[serde(default = "default_true")]
  1215. pub create: bool,
  1216. /// The window webview URL.
  1217. #[serde(default)]
  1218. pub url: WebviewUrl,
  1219. /// The user agent for the webview
  1220. #[serde(alias = "user-agent")]
  1221. pub user_agent: Option<String>,
  1222. /// Whether the drag and drop is enabled or not on the webview. By default it is enabled.
  1223. ///
  1224. /// Disabling it is required to use HTML5 drag and drop on the frontend on Windows.
  1225. #[serde(default = "default_true", alias = "drag-drop-enabled")]
  1226. pub drag_drop_enabled: bool,
  1227. /// Whether or not the window starts centered or not.
  1228. #[serde(default)]
  1229. pub center: bool,
  1230. /// The horizontal position of the window's top left corner
  1231. pub x: Option<f64>,
  1232. /// The vertical position of the window's top left corner
  1233. pub y: Option<f64>,
  1234. /// The window width.
  1235. #[serde(default = "default_width")]
  1236. pub width: f64,
  1237. /// The window height.
  1238. #[serde(default = "default_height")]
  1239. pub height: f64,
  1240. /// The min window width.
  1241. #[serde(alias = "min-width")]
  1242. pub min_width: Option<f64>,
  1243. /// The min window height.
  1244. #[serde(alias = "min-height")]
  1245. pub min_height: Option<f64>,
  1246. /// The max window width.
  1247. #[serde(alias = "max-width")]
  1248. pub max_width: Option<f64>,
  1249. /// The max window height.
  1250. #[serde(alias = "max-height")]
  1251. pub max_height: Option<f64>,
  1252. /// Whether the window is resizable or not. When resizable is set to false, native window's maximize button is automatically disabled.
  1253. #[serde(default = "default_true")]
  1254. pub resizable: bool,
  1255. /// Whether the window's native maximize button is enabled or not.
  1256. /// If resizable is set to false, this setting is ignored.
  1257. ///
  1258. /// ## Platform-specific
  1259. ///
  1260. /// - **macOS:** Disables the "zoom" button in the window titlebar, which is also used to enter fullscreen mode.
  1261. /// - **Linux / iOS / Android:** Unsupported.
  1262. #[serde(default = "default_true")]
  1263. pub maximizable: bool,
  1264. /// Whether the window's native minimize button is enabled or not.
  1265. ///
  1266. /// ## Platform-specific
  1267. ///
  1268. /// - **Linux / iOS / Android:** Unsupported.
  1269. #[serde(default = "default_true")]
  1270. pub minimizable: bool,
  1271. /// Whether the window's native close button is enabled or not.
  1272. ///
  1273. /// ## Platform-specific
  1274. ///
  1275. /// - **Linux:** "GTK+ will do its best to convince the window manager not to show a close button.
  1276. /// Depending on the system, this function may not have any effect when called on a window that is already visible"
  1277. /// - **iOS / Android:** Unsupported.
  1278. #[serde(default = "default_true")]
  1279. pub closable: bool,
  1280. /// The window title.
  1281. #[serde(default = "default_title")]
  1282. pub title: String,
  1283. /// Whether the window starts as fullscreen or not.
  1284. #[serde(default)]
  1285. pub fullscreen: bool,
  1286. /// Whether the window will be initially focused or not.
  1287. #[serde(default = "default_true")]
  1288. pub focus: bool,
  1289. /// Whether the window is transparent or not.
  1290. ///
  1291. /// Note that on `macOS` this requires the `macos-private-api` feature flag, enabled under `tauri > macOSPrivateApi`.
  1292. /// WARNING: Using private APIs on `macOS` prevents your application from being accepted to the `App Store`.
  1293. #[serde(default)]
  1294. pub transparent: bool,
  1295. /// Whether the window is maximized or not.
  1296. #[serde(default)]
  1297. pub maximized: bool,
  1298. /// Whether the window is visible or not.
  1299. #[serde(default = "default_true")]
  1300. pub visible: bool,
  1301. /// Whether the window should have borders and bars.
  1302. #[serde(default = "default_true")]
  1303. pub decorations: bool,
  1304. /// Whether the window should always be below other windows.
  1305. #[serde(default, alias = "always-on-bottom")]
  1306. pub always_on_bottom: bool,
  1307. /// Whether the window should always be on top of other windows.
  1308. #[serde(default, alias = "always-on-top")]
  1309. pub always_on_top: bool,
  1310. /// Whether the window should be visible on all workspaces or virtual desktops.
  1311. ///
  1312. /// ## Platform-specific
  1313. ///
  1314. /// - **Windows / iOS / Android:** Unsupported.
  1315. #[serde(default, alias = "visible-on-all-workspaces")]
  1316. pub visible_on_all_workspaces: bool,
  1317. /// Prevents the window contents from being captured by other apps.
  1318. #[serde(default, alias = "content-protected")]
  1319. pub content_protected: bool,
  1320. /// If `true`, hides the window icon from the taskbar on Windows and Linux.
  1321. #[serde(default, alias = "skip-taskbar")]
  1322. pub skip_taskbar: bool,
  1323. /// The initial window theme. Defaults to the system theme. Only implemented on Windows and macOS 10.14+.
  1324. pub theme: Option<crate::Theme>,
  1325. /// The style of the macOS title bar.
  1326. #[serde(default, alias = "title-bar-style")]
  1327. pub title_bar_style: TitleBarStyle,
  1328. /// If `true`, sets the window title to be hidden on macOS.
  1329. #[serde(default, alias = "hidden-title")]
  1330. pub hidden_title: bool,
  1331. /// Whether clicking an inactive window also clicks through to the webview on macOS.
  1332. #[serde(default, alias = "accept-first-mouse")]
  1333. pub accept_first_mouse: bool,
  1334. /// Defines the window [tabbing identifier] for macOS.
  1335. ///
  1336. /// Windows with matching tabbing identifiers will be grouped together.
  1337. /// If the tabbing identifier is not set, automatic tabbing will be disabled.
  1338. ///
  1339. /// [tabbing identifier]: <https://developer.apple.com/documentation/appkit/nswindow/1644704-tabbingidentifier>
  1340. #[serde(default, alias = "tabbing-identifier")]
  1341. pub tabbing_identifier: Option<String>,
  1342. /// Defines additional browser arguments on Windows. By default wry passes `--disable-features=msWebOOUI,msPdfOOUI,msSmartScreenProtection`
  1343. /// so if you use this method, you also need to disable these components by yourself if you want.
  1344. #[serde(default, alias = "additional-browser-args")]
  1345. pub additional_browser_args: Option<String>,
  1346. /// Whether or not the window has shadow.
  1347. ///
  1348. /// ## Platform-specific
  1349. ///
  1350. /// - **Windows:**
  1351. /// - `false` has no effect on decorated window, shadow are always ON.
  1352. /// - `true` will make undecorated window have a 1px white border,
  1353. /// and on Windows 11, it will have a rounded corners.
  1354. /// - **Linux:** Unsupported.
  1355. #[serde(default = "default_true")]
  1356. pub shadow: bool,
  1357. /// Window effects.
  1358. ///
  1359. /// Requires the window to be transparent.
  1360. ///
  1361. /// ## Platform-specific:
  1362. ///
  1363. /// - **Windows**: If using decorations or shadows, you may want to try this workaround <https://github.com/tauri-apps/tao/issues/72#issuecomment-975607891>
  1364. /// - **Linux**: Unsupported
  1365. #[serde(default, alias = "window-effects")]
  1366. pub window_effects: Option<WindowEffectsConfig>,
  1367. /// Whether or not the webview should be launched in incognito mode.
  1368. ///
  1369. /// ## Platform-specific:
  1370. ///
  1371. /// - **Android**: Unsupported.
  1372. #[serde(default)]
  1373. pub incognito: bool,
  1374. /// Sets the window associated with this label to be the parent of the window to be created.
  1375. ///
  1376. /// ## Platform-specific
  1377. ///
  1378. /// - **Windows**: This sets the passed parent as an owner window to the window to be created.
  1379. /// From [MSDN owned windows docs](https://docs.microsoft.com/en-us/windows/win32/winmsg/window-features#owned-windows):
  1380. /// - An owned window is always above its owner in the z-order.
  1381. /// - The system automatically destroys an owned window when its owner is destroyed.
  1382. /// - An owned window is hidden when its owner is minimized.
  1383. /// - **Linux**: This makes the new window transient for parent, see <https://docs.gtk.org/gtk3/method.Window.set_transient_for.html>
  1384. /// - **macOS**: This adds the window as a child of parent, see <https://developer.apple.com/documentation/appkit/nswindow/1419152-addchildwindow?language=objc>
  1385. pub parent: Option<String>,
  1386. /// The proxy URL for the WebView for all network requests.
  1387. ///
  1388. /// Must be either a `http://` or a `socks5://` URL.
  1389. ///
  1390. /// ## Platform-specific
  1391. ///
  1392. /// - **macOS**: Requires the `macos-proxy` feature flag and only compiles for macOS 14+.
  1393. pub proxy_url: Option<Url>,
  1394. /// Whether page zooming by hotkeys is enabled
  1395. ///
  1396. /// ## Platform-specific:
  1397. ///
  1398. /// - **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.
  1399. /// - **MacOS / Linux**: Injects a polyfill that zooms in and out with `ctrl/command` + `-/=`,
  1400. /// 20% in each step, ranging from 20% to 1000%. Requires `webview:allow-set-webview-zoom` permission
  1401. ///
  1402. /// - **Android / iOS**: Unsupported.
  1403. #[serde(default)]
  1404. pub zoom_hotkeys_enabled: bool,
  1405. /// Whether browser extensions can be installed for the webview process
  1406. ///
  1407. /// ## Platform-specific:
  1408. ///
  1409. /// - **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)
  1410. /// - **MacOS / Linux / iOS / Android** - Unsupported.
  1411. #[serde(default)]
  1412. pub browser_extensions_enabled: bool,
  1413. }
  1414. impl Default for WindowConfig {
  1415. fn default() -> Self {
  1416. Self {
  1417. label: default_window_label(),
  1418. url: WebviewUrl::default(),
  1419. create: true,
  1420. user_agent: None,
  1421. drag_drop_enabled: true,
  1422. center: false,
  1423. x: None,
  1424. y: None,
  1425. width: default_width(),
  1426. height: default_height(),
  1427. min_width: None,
  1428. min_height: None,
  1429. max_width: None,
  1430. max_height: None,
  1431. resizable: true,
  1432. maximizable: true,
  1433. minimizable: true,
  1434. closable: true,
  1435. title: default_title(),
  1436. fullscreen: false,
  1437. focus: false,
  1438. transparent: false,
  1439. maximized: false,
  1440. visible: true,
  1441. decorations: true,
  1442. always_on_bottom: false,
  1443. always_on_top: false,
  1444. visible_on_all_workspaces: false,
  1445. content_protected: false,
  1446. skip_taskbar: false,
  1447. theme: None,
  1448. title_bar_style: Default::default(),
  1449. hidden_title: false,
  1450. accept_first_mouse: false,
  1451. tabbing_identifier: None,
  1452. additional_browser_args: None,
  1453. shadow: true,
  1454. window_effects: None,
  1455. incognito: false,
  1456. parent: None,
  1457. proxy_url: None,
  1458. zoom_hotkeys_enabled: false,
  1459. browser_extensions_enabled: false,
  1460. }
  1461. }
  1462. }
  1463. fn default_window_label() -> String {
  1464. "main".to_string()
  1465. }
  1466. fn default_width() -> f64 {
  1467. 800f64
  1468. }
  1469. fn default_height() -> f64 {
  1470. 600f64
  1471. }
  1472. fn default_title() -> String {
  1473. "Tauri App".to_string()
  1474. }
  1475. /// A Content-Security-Policy directive source list.
  1476. /// See <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/Sources#sources>.
  1477. #[derive(Debug, PartialEq, Eq, Clone, Deserialize, Serialize)]
  1478. #[cfg_attr(feature = "schema", derive(JsonSchema))]
  1479. #[serde(rename_all = "camelCase", untagged)]
  1480. pub enum CspDirectiveSources {
  1481. /// An inline list of CSP sources. Same as [`Self::List`], but concatenated with a space separator.
  1482. Inline(String),
  1483. /// A list of CSP sources. The collection will be concatenated with a space separator for the CSP string.
  1484. List(Vec<String>),
  1485. }
  1486. impl Default for CspDirectiveSources {
  1487. fn default() -> Self {
  1488. Self::List(Vec::new())
  1489. }
  1490. }
  1491. impl From<CspDirectiveSources> for Vec<String> {
  1492. fn from(sources: CspDirectiveSources) -> Self {
  1493. match sources {
  1494. CspDirectiveSources::Inline(source) => source.split(' ').map(|s| s.to_string()).collect(),
  1495. CspDirectiveSources::List(l) => l,
  1496. }
  1497. }
  1498. }
  1499. impl CspDirectiveSources {
  1500. /// Whether the given source is configured on this directive or not.
  1501. pub fn contains(&self, source: &str) -> bool {
  1502. match self {
  1503. Self::Inline(s) => s.contains(&format!("{source} ")) || s.contains(&format!(" {source}")),
  1504. Self::List(l) => l.contains(&source.into()),
  1505. }
  1506. }
  1507. /// Appends the given source to this directive.
  1508. pub fn push<S: AsRef<str>>(&mut self, source: S) {
  1509. match self {
  1510. Self::Inline(s) => {
  1511. s.push(' ');
  1512. s.push_str(source.as_ref());
  1513. }
  1514. Self::List(l) => {
  1515. l.push(source.as_ref().to_string());
  1516. }
  1517. }
  1518. }
  1519. /// Extends this CSP directive source list with the given array of sources.
  1520. pub fn extend(&mut self, sources: Vec<String>) {
  1521. for s in sources {
  1522. self.push(s);
  1523. }
  1524. }
  1525. }
  1526. /// A Content-Security-Policy definition.
  1527. /// See <https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP>.
  1528. #[derive(Debug, PartialEq, Eq, Clone, Deserialize, Serialize)]
  1529. #[cfg_attr(feature = "schema", derive(JsonSchema))]
  1530. #[serde(rename_all = "camelCase", untagged)]
  1531. pub enum Csp {
  1532. /// The entire CSP policy in a single text string.
  1533. Policy(String),
  1534. /// An object mapping a directive with its sources values as a list of strings.
  1535. DirectiveMap(HashMap<String, CspDirectiveSources>),
  1536. }
  1537. impl From<HashMap<String, CspDirectiveSources>> for Csp {
  1538. fn from(map: HashMap<String, CspDirectiveSources>) -> Self {
  1539. Self::DirectiveMap(map)
  1540. }
  1541. }
  1542. impl From<Csp> for HashMap<String, CspDirectiveSources> {
  1543. fn from(csp: Csp) -> Self {
  1544. match csp {
  1545. Csp::Policy(policy) => {
  1546. let mut map = HashMap::new();
  1547. for directive in policy.split(';') {
  1548. let mut tokens = directive.trim().split(' ');
  1549. if let Some(directive) = tokens.next() {
  1550. let sources = tokens.map(|s| s.to_string()).collect::<Vec<String>>();
  1551. map.insert(directive.to_string(), CspDirectiveSources::List(sources));
  1552. }
  1553. }
  1554. map
  1555. }
  1556. Csp::DirectiveMap(m) => m,
  1557. }
  1558. }
  1559. }
  1560. impl Display for Csp {
  1561. fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
  1562. match self {
  1563. Self::Policy(s) => write!(f, "{s}"),
  1564. Self::DirectiveMap(m) => {
  1565. let len = m.len();
  1566. let mut i = 0;
  1567. for (directive, sources) in m {
  1568. let sources: Vec<String> = sources.clone().into();
  1569. write!(f, "{} {}", directive, sources.join(" "))?;
  1570. i += 1;
  1571. if i != len {
  1572. write!(f, "; ")?;
  1573. }
  1574. }
  1575. Ok(())
  1576. }
  1577. }
  1578. }
  1579. }
  1580. /// The possible values for the `dangerous_disable_asset_csp_modification` config option.
  1581. #[derive(Debug, PartialEq, Eq, Clone, Deserialize, Serialize)]
  1582. #[serde(untagged)]
  1583. #[cfg_attr(feature = "schema", derive(JsonSchema))]
  1584. pub enum DisabledCspModificationKind {
  1585. /// If `true`, disables all CSP modification.
  1586. /// `false` is the default value and it configures Tauri to control the CSP.
  1587. Flag(bool),
  1588. /// Disables the given list of CSP directives modifications.
  1589. List(Vec<String>),
  1590. }
  1591. impl DisabledCspModificationKind {
  1592. /// Determines whether the given CSP directive can be modified or not.
  1593. pub fn can_modify(&self, directive: &str) -> bool {
  1594. match self {
  1595. Self::Flag(f) => !f,
  1596. Self::List(l) => !l.contains(&directive.into()),
  1597. }
  1598. }
  1599. }
  1600. impl Default for DisabledCspModificationKind {
  1601. fn default() -> Self {
  1602. Self::Flag(false)
  1603. }
  1604. }
  1605. /// Protocol scope definition.
  1606. /// It is a list of glob patterns that restrict the API access from the webview.
  1607. ///
  1608. /// Each pattern can start with a variable that resolves to a system base directory.
  1609. /// The variables are: `$AUDIO`, `$CACHE`, `$CONFIG`, `$DATA`, `$LOCALDATA`, `$DESKTOP`,
  1610. /// `$DOCUMENT`, `$DOWNLOAD`, `$EXE`, `$FONT`, `$HOME`, `$PICTURE`, `$PUBLIC`, `$RUNTIME`,
  1611. /// `$TEMPLATE`, `$VIDEO`, `$RESOURCE`, `$APP`, `$LOG`, `$TEMP`, `$APPCONFIG`, `$APPDATA`,
  1612. /// `$APPLOCALDATA`, `$APPCACHE`, `$APPLOG`.
  1613. #[derive(Debug, PartialEq, Eq, Clone, Deserialize, Serialize)]
  1614. #[serde(untagged)]
  1615. #[cfg_attr(feature = "schema", derive(JsonSchema))]
  1616. pub enum FsScope {
  1617. /// A list of paths that are allowed by this scope.
  1618. AllowedPaths(Vec<PathBuf>),
  1619. /// A complete scope configuration.
  1620. #[serde(rename_all = "camelCase")]
  1621. Scope {
  1622. /// A list of paths that are allowed by this scope.
  1623. #[serde(default)]
  1624. allow: Vec<PathBuf>,
  1625. /// A list of paths that are not allowed by this scope.
  1626. /// This gets precedence over the [`Self::Scope::allow`] list.
  1627. #[serde(default)]
  1628. deny: Vec<PathBuf>,
  1629. /// Whether or not paths that contain components that start with a `.`
  1630. /// will require that `.` appears literally in the pattern; `*`, `?`, `**`,
  1631. /// or `[...]` will not match. This is useful because such files are
  1632. /// conventionally considered hidden on Unix systems and it might be
  1633. /// desirable to skip them when listing files.
  1634. ///
  1635. /// Defaults to `true` on Unix systems and `false` on Windows
  1636. // dotfiles are not supposed to be exposed by default on unix
  1637. #[serde(alias = "require-literal-leading-dot")]
  1638. require_literal_leading_dot: Option<bool>,
  1639. },
  1640. }
  1641. impl Default for FsScope {
  1642. fn default() -> Self {
  1643. Self::AllowedPaths(Vec::new())
  1644. }
  1645. }
  1646. impl FsScope {
  1647. /// The list of allowed paths.
  1648. pub fn allowed_paths(&self) -> &Vec<PathBuf> {
  1649. match self {
  1650. Self::AllowedPaths(p) => p,
  1651. Self::Scope { allow, .. } => allow,
  1652. }
  1653. }
  1654. /// The list of forbidden paths.
  1655. pub fn forbidden_paths(&self) -> Option<&Vec<PathBuf>> {
  1656. match self {
  1657. Self::AllowedPaths(_) => None,
  1658. Self::Scope { deny, .. } => Some(deny),
  1659. }
  1660. }
  1661. }
  1662. /// Config for the asset custom protocol.
  1663. ///
  1664. /// See more: <https://v2.tauri.app/reference/config/#assetprotocolconfig>
  1665. #[derive(Debug, Default, PartialEq, Eq, Clone, Deserialize, Serialize)]
  1666. #[cfg_attr(feature = "schema", derive(JsonSchema))]
  1667. #[serde(rename_all = "camelCase", deny_unknown_fields)]
  1668. pub struct AssetProtocolConfig {
  1669. /// The access scope for the asset protocol.
  1670. #[serde(default)]
  1671. pub scope: FsScope,
  1672. /// Enables the asset protocol.
  1673. #[serde(default)]
  1674. pub enable: bool,
  1675. }
  1676. /// Security configuration.
  1677. ///
  1678. /// See more: <https://v2.tauri.app/reference/config/#securityconfig>
  1679. #[skip_serializing_none]
  1680. #[derive(Debug, Default, PartialEq, Clone, Deserialize, Serialize)]
  1681. #[cfg_attr(feature = "schema", derive(JsonSchema))]
  1682. #[serde(rename_all = "camelCase", deny_unknown_fields)]
  1683. pub struct SecurityConfig {
  1684. /// The Content Security Policy that will be injected on all HTML files on the built application.
  1685. /// If [`dev_csp`](#SecurityConfig.devCsp) is not specified, this value is also injected on dev.
  1686. ///
  1687. /// This is a really important part of the configuration since it helps you ensure your WebView is secured.
  1688. /// See <https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP>.
  1689. pub csp: Option<Csp>,
  1690. /// The Content Security Policy that will be injected on all HTML files on development.
  1691. ///
  1692. /// This is a really important part of the configuration since it helps you ensure your WebView is secured.
  1693. /// See <https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP>.
  1694. #[serde(alias = "dev-csp")]
  1695. pub dev_csp: Option<Csp>,
  1696. /// Freeze the `Object.prototype` when using the custom protocol.
  1697. #[serde(default, alias = "freeze-prototype")]
  1698. pub freeze_prototype: bool,
  1699. /// Disables the Tauri-injected CSP sources.
  1700. ///
  1701. /// At compile time, Tauri parses all the frontend assets and changes the Content-Security-Policy
  1702. /// to only allow loading of your own scripts and styles by injecting nonce and hash sources.
  1703. /// This stricts your CSP, which may introduce issues when using along with other flexing sources.
  1704. ///
  1705. /// This configuration option allows both a boolean and a list of strings as value.
  1706. /// A boolean instructs Tauri to disable the injection for all CSP injections,
  1707. /// and a list of strings indicates the CSP directives that Tauri cannot inject.
  1708. ///
  1709. /// **WARNING:** Only disable this if you know what you are doing and have properly configured the CSP.
  1710. /// Your application might be vulnerable to XSS attacks without this Tauri protection.
  1711. #[serde(default, alias = "dangerous-disable-asset-csp-modification")]
  1712. pub dangerous_disable_asset_csp_modification: DisabledCspModificationKind,
  1713. /// Custom protocol config.
  1714. #[serde(default, alias = "asset-protocol")]
  1715. pub asset_protocol: AssetProtocolConfig,
  1716. /// The pattern to use.
  1717. #[serde(default)]
  1718. pub pattern: PatternKind,
  1719. /// List of capabilities that are enabled on the application.
  1720. ///
  1721. /// If the list is empty, all capabilities are included.
  1722. #[serde(default)]
  1723. pub capabilities: Vec<CapabilityEntry>,
  1724. }
  1725. /// A capability entry which can be either an inlined capability or a reference to a capability defined on its own file.
  1726. #[derive(Debug, Clone, PartialEq, Serialize)]
  1727. #[cfg_attr(feature = "schema", derive(JsonSchema))]
  1728. #[serde(untagged)]
  1729. pub enum CapabilityEntry {
  1730. /// An inlined capability.
  1731. Inlined(Capability),
  1732. /// Reference to a capability identifier.
  1733. Reference(String),
  1734. }
  1735. impl<'de> Deserialize<'de> for CapabilityEntry {
  1736. fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
  1737. where
  1738. D: Deserializer<'de>,
  1739. {
  1740. UntaggedEnumVisitor::new()
  1741. .string(|string| Ok(Self::Reference(string.to_owned())))
  1742. .map(|map| map.deserialize::<Capability>().map(Self::Inlined))
  1743. .deserialize(deserializer)
  1744. }
  1745. }
  1746. /// The application pattern.
  1747. #[skip_serializing_none]
  1748. #[derive(Debug, PartialEq, Eq, Clone, Serialize, Deserialize)]
  1749. #[serde(rename_all = "lowercase", tag = "use", content = "options")]
  1750. #[cfg_attr(feature = "schema", derive(JsonSchema))]
  1751. pub enum PatternKind {
  1752. /// Brownfield pattern.
  1753. Brownfield,
  1754. /// Isolation pattern. Recommended for security purposes.
  1755. Isolation {
  1756. /// The dir containing the index.html file that contains the secure isolation application.
  1757. dir: PathBuf,
  1758. },
  1759. }
  1760. impl Default for PatternKind {
  1761. fn default() -> Self {
  1762. Self::Brownfield
  1763. }
  1764. }
  1765. /// The App configuration object.
  1766. ///
  1767. /// See more: <https://v2.tauri.app/reference/config/#appconfig>
  1768. #[skip_serializing_none]
  1769. #[derive(Debug, Default, PartialEq, Clone, Deserialize, Serialize)]
  1770. #[cfg_attr(feature = "schema", derive(JsonSchema))]
  1771. #[serde(rename_all = "camelCase", deny_unknown_fields)]
  1772. pub struct AppConfig {
  1773. /// The app windows configuration.
  1774. #[serde(default)]
  1775. pub windows: Vec<WindowConfig>,
  1776. /// Security configuration.
  1777. #[serde(default)]
  1778. pub security: SecurityConfig,
  1779. /// Configuration for app tray icon.
  1780. #[serde(alias = "tray-icon")]
  1781. pub tray_icon: Option<TrayIconConfig>,
  1782. /// MacOS private API configuration. Enables the transparent background API and sets the `fullScreenEnabled` preference to `true`.
  1783. #[serde(rename = "macOSPrivateApi", alias = "macos-private-api", default)]
  1784. pub macos_private_api: bool,
  1785. /// Whether we should inject the Tauri API on `window.__TAURI__` or not.
  1786. #[serde(default, alias = "with-global-tauri")]
  1787. pub with_global_tauri: bool,
  1788. /// If set to true "identifier" will be set as GTK app ID (on systems that use GTK).
  1789. #[serde(rename = "enableGTKAppId", alias = "enable-gtk-app-id", default)]
  1790. pub enable_gtk_app_id: bool,
  1791. }
  1792. impl AppConfig {
  1793. /// Returns all Cargo features.
  1794. pub fn all_features() -> Vec<&'static str> {
  1795. vec![
  1796. "tray-icon",
  1797. "macos-private-api",
  1798. "protocol-asset",
  1799. "isolation",
  1800. ]
  1801. }
  1802. /// Returns the enabled Cargo features.
  1803. pub fn features(&self) -> Vec<&str> {
  1804. let mut features = Vec::new();
  1805. if self.tray_icon.is_some() {
  1806. features.push("tray-icon");
  1807. }
  1808. if self.macos_private_api {
  1809. features.push("macos-private-api");
  1810. }
  1811. if self.security.asset_protocol.enable {
  1812. features.push("protocol-asset");
  1813. }
  1814. if let PatternKind::Isolation { .. } = self.security.pattern {
  1815. features.push("isolation");
  1816. }
  1817. features.sort_unstable();
  1818. features
  1819. }
  1820. }
  1821. /// Configuration for application tray icon.
  1822. ///
  1823. /// See more: <https://v2.tauri.app/reference/config/#trayiconconfig>
  1824. #[skip_serializing_none]
  1825. #[derive(Debug, Default, PartialEq, Eq, Clone, Deserialize, Serialize)]
  1826. #[cfg_attr(feature = "schema", derive(JsonSchema))]
  1827. #[serde(rename_all = "camelCase", deny_unknown_fields)]
  1828. pub struct TrayIconConfig {
  1829. /// Set an id for this tray icon so you can reference it later, defaults to `main`.
  1830. pub id: Option<String>,
  1831. /// Path to the default icon to use for the tray icon.
  1832. ///
  1833. /// Note: this stores the image in raw pixels to the final binary,
  1834. /// so keep the icon size (width and height) small
  1835. /// or else it's going to bloat your final executable
  1836. #[serde(alias = "icon-path")]
  1837. pub icon_path: PathBuf,
  1838. /// 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.
  1839. #[serde(default, alias = "icon-as-template")]
  1840. pub icon_as_template: bool,
  1841. /// A Boolean value that determines whether the menu should appear when the tray icon receives a left click on macOS.
  1842. #[serde(default = "default_true", alias = "menu-on-left-click")]
  1843. pub menu_on_left_click: bool,
  1844. /// Title for MacOS tray
  1845. pub title: Option<String>,
  1846. /// Tray icon tooltip on Windows and macOS
  1847. pub tooltip: Option<String>,
  1848. }
  1849. /// General configuration for the iOS target.
  1850. #[skip_serializing_none]
  1851. #[derive(Debug, PartialEq, Eq, Clone, Deserialize, Serialize)]
  1852. #[cfg_attr(feature = "schema", derive(JsonSchema))]
  1853. #[serde(rename_all = "camelCase", deny_unknown_fields)]
  1854. pub struct IosConfig {
  1855. /// A custom [XcodeGen] project.yml template to use.
  1856. ///
  1857. /// [XcodeGen]: <https://github.com/yonaskolb/XcodeGen>
  1858. pub template: Option<PathBuf>,
  1859. /// A list of strings indicating any iOS frameworks that need to be bundled with the application.
  1860. ///
  1861. /// Note that you need to recreate the iOS project for the changes to be applied.
  1862. pub frameworks: Option<Vec<String>>,
  1863. /// The development team. This value is required for iOS development because code signing is enforced.
  1864. /// The `APPLE_DEVELOPMENT_TEAM` environment variable can be set to overwrite it.
  1865. #[serde(alias = "development-team")]
  1866. pub development_team: Option<String>,
  1867. /// A version string indicating the minimum iOS version that the bundled application supports. Defaults to `13.0`.
  1868. ///
  1869. /// Maps to the IPHONEOS_DEPLOYMENT_TARGET value.
  1870. #[serde(
  1871. alias = "minimum-system-version",
  1872. default = "ios_minimum_system_version"
  1873. )]
  1874. pub minimum_system_version: String,
  1875. }
  1876. impl Default for IosConfig {
  1877. fn default() -> Self {
  1878. Self {
  1879. template: None,
  1880. frameworks: None,
  1881. development_team: None,
  1882. minimum_system_version: ios_minimum_system_version(),
  1883. }
  1884. }
  1885. }
  1886. /// General configuration for the iOS target.
  1887. #[skip_serializing_none]
  1888. #[derive(Debug, PartialEq, Eq, Clone, Deserialize, Serialize)]
  1889. #[cfg_attr(feature = "schema", derive(JsonSchema))]
  1890. #[serde(rename_all = "camelCase", deny_unknown_fields)]
  1891. pub struct AndroidConfig {
  1892. /// The minimum API level required for the application to run.
  1893. /// The Android system will prevent the user from installing the application if the system's API level is lower than the value specified.
  1894. #[serde(alias = "min-sdk-version", default = "default_min_sdk_version")]
  1895. pub min_sdk_version: u32,
  1896. /// The version code of the application.
  1897. /// It is limited to 2,100,000,000 as per Google Play Store requirements.
  1898. ///
  1899. /// By default we use your configured version and perform the following math:
  1900. /// versionCode = version.major * 1000000 + version.minor * 1000 + version.patch
  1901. #[serde(alias = "version-code")]
  1902. #[cfg_attr(feature = "schema", validate(range(min = 1, max = 2_100_000_000)))]
  1903. pub version_code: Option<u32>,
  1904. }
  1905. impl Default for AndroidConfig {
  1906. fn default() -> Self {
  1907. Self {
  1908. min_sdk_version: default_min_sdk_version(),
  1909. version_code: None,
  1910. }
  1911. }
  1912. }
  1913. fn default_min_sdk_version() -> u32 {
  1914. 24
  1915. }
  1916. /// Defines the URL or assets to embed in the application.
  1917. #[derive(Debug, PartialEq, Eq, Clone, Deserialize, Serialize)]
  1918. #[cfg_attr(feature = "schema", derive(JsonSchema))]
  1919. #[serde(untagged, deny_unknown_fields)]
  1920. #[non_exhaustive]
  1921. pub enum FrontendDist {
  1922. /// An external URL that should be used as the default application URL.
  1923. Url(Url),
  1924. /// Path to a directory containing the frontend dist assets.
  1925. Directory(PathBuf),
  1926. /// An array of files to embed on the app.
  1927. Files(Vec<PathBuf>),
  1928. }
  1929. impl std::fmt::Display for FrontendDist {
  1930. fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
  1931. match self {
  1932. Self::Url(url) => write!(f, "{url}"),
  1933. Self::Directory(p) => write!(f, "{}", p.display()),
  1934. Self::Files(files) => write!(f, "{}", serde_json::to_string(files).unwrap()),
  1935. }
  1936. }
  1937. }
  1938. /// Describes the shell command to run before `tauri dev`.
  1939. #[derive(Debug, PartialEq, Eq, Clone, Deserialize, Serialize)]
  1940. #[cfg_attr(feature = "schema", derive(JsonSchema))]
  1941. #[serde(rename_all = "camelCase", untagged)]
  1942. pub enum BeforeDevCommand {
  1943. /// Run the given script with the default options.
  1944. Script(String),
  1945. /// Run the given script with custom options.
  1946. ScriptWithOptions {
  1947. /// The script to execute.
  1948. script: String,
  1949. /// The current working directory.
  1950. cwd: Option<String>,
  1951. /// Whether `tauri dev` should wait for the command to finish or not. Defaults to `false`.
  1952. #[serde(default)]
  1953. wait: bool,
  1954. },
  1955. }
  1956. /// Describes a shell command to be executed when a CLI hook is triggered.
  1957. #[derive(Debug, PartialEq, Eq, Clone, Deserialize, Serialize)]
  1958. #[cfg_attr(feature = "schema", derive(JsonSchema))]
  1959. #[serde(rename_all = "camelCase", untagged)]
  1960. pub enum HookCommand {
  1961. /// Run the given script with the default options.
  1962. Script(String),
  1963. /// Run the given script with custom options.
  1964. ScriptWithOptions {
  1965. /// The script to execute.
  1966. script: String,
  1967. /// The current working directory.
  1968. cwd: Option<String>,
  1969. },
  1970. }
  1971. /// The Build configuration object.
  1972. ///
  1973. /// See more: <https://v2.tauri.app/reference/config/#buildconfig>
  1974. #[skip_serializing_none]
  1975. #[derive(Debug, PartialEq, Eq, Clone, Deserialize, Serialize, Default)]
  1976. #[cfg_attr(feature = "schema", derive(JsonSchema))]
  1977. #[serde(rename_all = "camelCase", deny_unknown_fields)]
  1978. pub struct BuildConfig {
  1979. /// The binary used to build and run the application.
  1980. pub runner: Option<String>,
  1981. /// The URL to load in development.
  1982. ///
  1983. /// This is usually an URL to a dev server, which serves your application assets with hot-reload and HMR.
  1984. /// Most modern JavaScript bundlers like [vite](https://vitejs.dev/guide/) provides a way to start a dev server by default.
  1985. ///
  1986. /// If you don't have a dev server or don't want to use one, ignore this option and use [`frontendDist`](BuildConfig::frontend_dist)
  1987. /// and point to a web assets directory, and Tauri CLI will run its built-in dev server and provide a simple hot-reload experience.
  1988. #[serde(alias = "dev-url")]
  1989. pub dev_url: Option<Url>,
  1990. /// The path to the application assets (usually the `dist` folder of your javascript bundler)
  1991. /// or a URL that could be either a custom protocol registered in the tauri app (for example: `myprotocol://`)
  1992. /// or a remote URL (for example: `https://site.com/app`).
  1993. ///
  1994. /// When a path relative to the configuration file is provided,
  1995. /// it is read recursively and all files are embedded in the application binary.
  1996. /// Tauri then looks for an `index.html` and serves it as the default entry point for your application.
  1997. ///
  1998. /// You can also provide a list of paths to be embedded, which allows granular control over what files are added to the binary.
  1999. /// In this case, all files are added to the root and you must reference it that way in your HTML files.
  2000. ///
  2001. /// When a URL is provided, the application won't have bundled assets
  2002. /// and the application will load that URL by default.
  2003. #[serde(alias = "frontend-dist")]
  2004. pub frontend_dist: Option<FrontendDist>,
  2005. /// A shell command to run before `tauri dev` kicks in.
  2006. ///
  2007. /// 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.
  2008. #[serde(alias = "before-dev-command")]
  2009. pub before_dev_command: Option<BeforeDevCommand>,
  2010. /// A shell command to run before `tauri build` kicks in.
  2011. ///
  2012. /// 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.
  2013. #[serde(alias = "before-build-command")]
  2014. pub before_build_command: Option<HookCommand>,
  2015. /// A shell command to run before the bundling phase in `tauri build` kicks in.
  2016. ///
  2017. /// 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.
  2018. #[serde(alias = "before-bundle-command")]
  2019. pub before_bundle_command: Option<HookCommand>,
  2020. /// Features passed to `cargo` commands.
  2021. pub features: Option<Vec<String>>,
  2022. }
  2023. #[derive(Debug, PartialEq, Eq)]
  2024. struct PackageVersion(String);
  2025. impl<'d> serde::Deserialize<'d> for PackageVersion {
  2026. fn deserialize<D: Deserializer<'d>>(deserializer: D) -> Result<Self, D::Error> {
  2027. struct PackageVersionVisitor;
  2028. impl<'d> Visitor<'d> for PackageVersionVisitor {
  2029. type Value = PackageVersion;
  2030. fn expecting(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
  2031. write!(
  2032. formatter,
  2033. "a semver string or a path to a package.json file"
  2034. )
  2035. }
  2036. fn visit_str<E: DeError>(self, value: &str) -> Result<PackageVersion, E> {
  2037. let path = PathBuf::from(value);
  2038. if path.exists() {
  2039. let json_str = read_to_string(&path)
  2040. .map_err(|e| DeError::custom(format!("failed to read version JSON file: {e}")))?;
  2041. let package_json: serde_json::Value = serde_json::from_str(&json_str)
  2042. .map_err(|e| DeError::custom(format!("failed to read version JSON file: {e}")))?;
  2043. if let Some(obj) = package_json.as_object() {
  2044. let version = obj
  2045. .get("version")
  2046. .ok_or_else(|| DeError::custom("JSON must contain a `version` field"))?
  2047. .as_str()
  2048. .ok_or_else(|| {
  2049. DeError::custom(format!("`{} > version` must be a string", path.display()))
  2050. })?;
  2051. Ok(PackageVersion(
  2052. Version::from_str(version)
  2053. .map_err(|_| DeError::custom("`package > version` must be a semver string"))?
  2054. .to_string(),
  2055. ))
  2056. } else {
  2057. Err(DeError::custom(
  2058. "`package > version` value is not a path to a JSON object",
  2059. ))
  2060. }
  2061. } else {
  2062. Ok(PackageVersion(
  2063. Version::from_str(value)
  2064. .map_err(|_| DeError::custom("`package > version` must be a semver string"))?
  2065. .to_string(),
  2066. ))
  2067. }
  2068. }
  2069. }
  2070. deserializer.deserialize_string(PackageVersionVisitor {})
  2071. }
  2072. }
  2073. fn version_deserializer<'de, D>(deserializer: D) -> Result<Option<String>, D::Error>
  2074. where
  2075. D: Deserializer<'de>,
  2076. {
  2077. Option::<PackageVersion>::deserialize(deserializer).map(|v| v.map(|v| v.0))
  2078. }
  2079. /// The Tauri configuration object.
  2080. /// It is read from a file where you can define your frontend assets,
  2081. /// configure the bundler and define a tray icon.
  2082. ///
  2083. /// The configuration file is generated by the
  2084. /// [`tauri init`](https://v2.tauri.app/reference/cli/#init) command that lives in
  2085. /// your Tauri application source directory (src-tauri).
  2086. ///
  2087. /// Once generated, you may modify it at will to customize your Tauri application.
  2088. ///
  2089. /// ## File Formats
  2090. ///
  2091. /// By default, the configuration is defined as a JSON file named `tauri.conf.json`.
  2092. ///
  2093. /// Tauri also supports JSON5 and TOML files via the `config-json5` and `config-toml` Cargo features, respectively.
  2094. /// The JSON5 file name must be either `tauri.conf.json` or `tauri.conf.json5`.
  2095. /// The TOML file name is `Tauri.toml`.
  2096. ///
  2097. /// ## Platform-Specific Configuration
  2098. ///
  2099. /// In addition to the default configuration file, Tauri can
  2100. /// read a platform-specific configuration from `tauri.linux.conf.json`,
  2101. /// `tauri.windows.conf.json`, `tauri.macos.conf.json`, `tauri.android.conf.json` and `tauri.ios.conf.json`
  2102. /// (or `Tauri.linux.toml`, `Tauri.windows.toml`, `Tauri.macos.toml`, `Tauri.android.toml` and `Tauri.ios.toml` if the `Tauri.toml` format is used),
  2103. /// which gets merged with the main configuration object.
  2104. ///
  2105. /// ## Configuration Structure
  2106. ///
  2107. /// The configuration is composed of the following objects:
  2108. ///
  2109. /// - [`app`](#appconfig): The Tauri configuration
  2110. /// - [`build`](#buildconfig): The build configuration
  2111. /// - [`bundle`](#bundleconfig): The bundle configurations
  2112. /// - [`plugins`](#pluginconfig): The plugins configuration
  2113. ///
  2114. /// Example tauri.config.json file:
  2115. ///
  2116. /// ```json
  2117. /// {
  2118. /// "productName": "tauri-app",
  2119. /// "version": "0.1.0",
  2120. /// "build": {
  2121. /// "beforeBuildCommand": "",
  2122. /// "beforeDevCommand": "",
  2123. /// "devUrl": "../dist",
  2124. /// "frontendDist": "../dist"
  2125. /// },
  2126. /// "app": {
  2127. /// "security": {
  2128. /// "csp": null
  2129. /// },
  2130. /// "windows": [
  2131. /// {
  2132. /// "fullscreen": false,
  2133. /// "height": 600,
  2134. /// "resizable": true,
  2135. /// "title": "Tauri App",
  2136. /// "width": 800
  2137. /// }
  2138. /// ]
  2139. /// },
  2140. /// "bundle": {},
  2141. /// "plugins": {}
  2142. /// }
  2143. /// ```
  2144. #[skip_serializing_none]
  2145. #[derive(Debug, Default, PartialEq, Clone, Deserialize, Serialize)]
  2146. #[cfg_attr(feature = "schema", derive(JsonSchema))]
  2147. #[serde(rename_all = "camelCase", deny_unknown_fields)]
  2148. pub struct Config {
  2149. /// The JSON schema for the Tauri config.
  2150. #[serde(rename = "$schema")]
  2151. pub schema: Option<String>,
  2152. /// App name.
  2153. #[serde(alias = "product-name")]
  2154. #[cfg_attr(feature = "schema", validate(regex(pattern = "^[^/\\:*?\"<>|]+$")))]
  2155. pub product_name: Option<String>,
  2156. /// App main binary filename. Defaults to the name of your cargo crate.
  2157. #[serde(alias = "main-binary-name")]
  2158. pub main_binary_name: Option<String>,
  2159. /// App version. It is a semver version number or a path to a `package.json` file containing the `version` field. If removed the version number from `Cargo.toml` is used.
  2160. ///
  2161. /// By default version 1.0 is used on Android.
  2162. #[serde(deserialize_with = "version_deserializer", default)]
  2163. pub version: Option<String>,
  2164. /// The application identifier in reverse domain name notation (e.g. `com.tauri.example`).
  2165. /// This string must be unique across applications since it is used in system configurations like
  2166. /// the bundle ID and path to the webview data directory.
  2167. /// This string must contain only alphanumeric characters (A-Z, a-z, and 0-9), hyphens (-),
  2168. /// and periods (.).
  2169. pub identifier: String,
  2170. /// The App configuration.
  2171. #[serde(default)]
  2172. pub app: AppConfig,
  2173. /// The build configuration.
  2174. #[serde(default = "default_build")]
  2175. pub build: BuildConfig,
  2176. /// The bundler configuration.
  2177. #[serde(default)]
  2178. pub bundle: BundleConfig,
  2179. /// The plugins config.
  2180. #[serde(default)]
  2181. pub plugins: PluginConfig,
  2182. }
  2183. /// The plugin configs holds a HashMap mapping a plugin name to its configuration object.
  2184. ///
  2185. /// See more: <https://v2.tauri.app/reference/config/#pluginconfig>
  2186. #[derive(Debug, Clone, Default, PartialEq, Eq, Deserialize, Serialize)]
  2187. #[cfg_attr(feature = "schema", derive(JsonSchema))]
  2188. pub struct PluginConfig(pub HashMap<String, JsonValue>);
  2189. fn default_build() -> BuildConfig {
  2190. BuildConfig {
  2191. runner: None,
  2192. dev_url: None,
  2193. frontend_dist: None,
  2194. before_dev_command: None,
  2195. before_build_command: None,
  2196. before_bundle_command: None,
  2197. features: None,
  2198. }
  2199. }
  2200. /// Implement `ToTokens` for all config structs, allowing a literal `Config` to be built.
  2201. ///
  2202. /// This allows for a build script to output the values in a `Config` to a `TokenStream`, which can
  2203. /// then be consumed by another crate. Useful for passing a config to both the build script and the
  2204. /// application using tauri while only parsing it once (in the build script).
  2205. #[cfg(feature = "build")]
  2206. mod build {
  2207. use super::*;
  2208. use crate::{literal_struct, tokens::*};
  2209. use proc_macro2::TokenStream;
  2210. use quote::{quote, ToTokens, TokenStreamExt};
  2211. use std::convert::identity;
  2212. impl ToTokens for WebviewUrl {
  2213. fn to_tokens(&self, tokens: &mut TokenStream) {
  2214. let prefix = quote! { ::tauri::utils::config::WebviewUrl };
  2215. tokens.append_all(match self {
  2216. Self::App(path) => {
  2217. let path = path_buf_lit(path);
  2218. quote! { #prefix::App(#path) }
  2219. }
  2220. Self::External(url) => {
  2221. let url = url_lit(url);
  2222. quote! { #prefix::External(#url) }
  2223. }
  2224. Self::CustomProtocol(url) => {
  2225. let url = url_lit(url);
  2226. quote! { #prefix::CustomProtocol(#url) }
  2227. }
  2228. })
  2229. }
  2230. }
  2231. impl ToTokens for crate::Theme {
  2232. fn to_tokens(&self, tokens: &mut TokenStream) {
  2233. let prefix = quote! { ::tauri::utils::Theme };
  2234. tokens.append_all(match self {
  2235. Self::Light => quote! { #prefix::Light },
  2236. Self::Dark => quote! { #prefix::Dark },
  2237. })
  2238. }
  2239. }
  2240. impl ToTokens for Color {
  2241. fn to_tokens(&self, tokens: &mut TokenStream) {
  2242. let Color(r, g, b, a) = self;
  2243. tokens.append_all(quote! {::tauri::utils::config::Color(#r,#g,#b,#a)});
  2244. }
  2245. }
  2246. impl ToTokens for WindowEffectsConfig {
  2247. fn to_tokens(&self, tokens: &mut TokenStream) {
  2248. let effects = vec_lit(self.effects.clone(), |d| d);
  2249. let state = opt_lit(self.state.as_ref());
  2250. let radius = opt_lit(self.radius.as_ref());
  2251. let color = opt_lit(self.color.as_ref());
  2252. literal_struct!(
  2253. tokens,
  2254. ::tauri::utils::config::WindowEffectsConfig,
  2255. effects,
  2256. state,
  2257. radius,
  2258. color
  2259. )
  2260. }
  2261. }
  2262. impl ToTokens for crate::TitleBarStyle {
  2263. fn to_tokens(&self, tokens: &mut TokenStream) {
  2264. let prefix = quote! { ::tauri::utils::TitleBarStyle };
  2265. tokens.append_all(match self {
  2266. Self::Visible => quote! { #prefix::Visible },
  2267. Self::Transparent => quote! { #prefix::Transparent },
  2268. Self::Overlay => quote! { #prefix::Overlay },
  2269. })
  2270. }
  2271. }
  2272. impl ToTokens for crate::WindowEffect {
  2273. fn to_tokens(&self, tokens: &mut TokenStream) {
  2274. let prefix = quote! { ::tauri::utils::WindowEffect };
  2275. #[allow(deprecated)]
  2276. tokens.append_all(match self {
  2277. WindowEffect::AppearanceBased => quote! { #prefix::AppearanceBased},
  2278. WindowEffect::Light => quote! { #prefix::Light},
  2279. WindowEffect::Dark => quote! { #prefix::Dark},
  2280. WindowEffect::MediumLight => quote! { #prefix::MediumLight},
  2281. WindowEffect::UltraDark => quote! { #prefix::UltraDark},
  2282. WindowEffect::Titlebar => quote! { #prefix::Titlebar},
  2283. WindowEffect::Selection => quote! { #prefix::Selection},
  2284. WindowEffect::Menu => quote! { #prefix::Menu},
  2285. WindowEffect::Popover => quote! { #prefix::Popover},
  2286. WindowEffect::Sidebar => quote! { #prefix::Sidebar},
  2287. WindowEffect::HeaderView => quote! { #prefix::HeaderView},
  2288. WindowEffect::Sheet => quote! { #prefix::Sheet},
  2289. WindowEffect::WindowBackground => quote! { #prefix::WindowBackground},
  2290. WindowEffect::HudWindow => quote! { #prefix::HudWindow},
  2291. WindowEffect::FullScreenUI => quote! { #prefix::FullScreenUI},
  2292. WindowEffect::Tooltip => quote! { #prefix::Tooltip},
  2293. WindowEffect::ContentBackground => quote! { #prefix::ContentBackground},
  2294. WindowEffect::UnderWindowBackground => quote! { #prefix::UnderWindowBackground},
  2295. WindowEffect::UnderPageBackground => quote! { #prefix::UnderPageBackground},
  2296. WindowEffect::Mica => quote! { #prefix::Mica},
  2297. WindowEffect::MicaDark => quote! { #prefix::MicaDark},
  2298. WindowEffect::MicaLight => quote! { #prefix::MicaLight},
  2299. WindowEffect::Blur => quote! { #prefix::Blur},
  2300. WindowEffect::Acrylic => quote! { #prefix::Acrylic},
  2301. WindowEffect::Tabbed => quote! { #prefix::Tabbed },
  2302. WindowEffect::TabbedDark => quote! { #prefix::TabbedDark },
  2303. WindowEffect::TabbedLight => quote! { #prefix::TabbedLight },
  2304. })
  2305. }
  2306. }
  2307. impl ToTokens for crate::WindowEffectState {
  2308. fn to_tokens(&self, tokens: &mut TokenStream) {
  2309. let prefix = quote! { ::tauri::utils::WindowEffectState };
  2310. #[allow(deprecated)]
  2311. tokens.append_all(match self {
  2312. WindowEffectState::Active => quote! { #prefix::Active},
  2313. WindowEffectState::FollowsWindowActiveState => quote! { #prefix::FollowsWindowActiveState},
  2314. WindowEffectState::Inactive => quote! { #prefix::Inactive},
  2315. })
  2316. }
  2317. }
  2318. impl ToTokens for WindowConfig {
  2319. fn to_tokens(&self, tokens: &mut TokenStream) {
  2320. let label = str_lit(&self.label);
  2321. let create = &self.create;
  2322. let url = &self.url;
  2323. let user_agent = opt_str_lit(self.user_agent.as_ref());
  2324. let drag_drop_enabled = self.drag_drop_enabled;
  2325. let center = self.center;
  2326. let x = opt_lit(self.x.as_ref());
  2327. let y = opt_lit(self.y.as_ref());
  2328. let width = self.width;
  2329. let height = self.height;
  2330. let min_width = opt_lit(self.min_width.as_ref());
  2331. let min_height = opt_lit(self.min_height.as_ref());
  2332. let max_width = opt_lit(self.max_width.as_ref());
  2333. let max_height = opt_lit(self.max_height.as_ref());
  2334. let resizable = self.resizable;
  2335. let maximizable = self.maximizable;
  2336. let minimizable = self.minimizable;
  2337. let closable = self.closable;
  2338. let title = str_lit(&self.title);
  2339. let proxy_url = opt_lit(self.proxy_url.as_ref().map(url_lit).as_ref());
  2340. let fullscreen = self.fullscreen;
  2341. let focus = self.focus;
  2342. let transparent = self.transparent;
  2343. let maximized = self.maximized;
  2344. let visible = self.visible;
  2345. let decorations = self.decorations;
  2346. let always_on_bottom = self.always_on_bottom;
  2347. let always_on_top = self.always_on_top;
  2348. let visible_on_all_workspaces = self.visible_on_all_workspaces;
  2349. let content_protected = self.content_protected;
  2350. let skip_taskbar = self.skip_taskbar;
  2351. let theme = opt_lit(self.theme.as_ref());
  2352. let title_bar_style = &self.title_bar_style;
  2353. let hidden_title = self.hidden_title;
  2354. let accept_first_mouse = self.accept_first_mouse;
  2355. let tabbing_identifier = opt_str_lit(self.tabbing_identifier.as_ref());
  2356. let additional_browser_args = opt_str_lit(self.additional_browser_args.as_ref());
  2357. let shadow = self.shadow;
  2358. let window_effects = opt_lit(self.window_effects.as_ref());
  2359. let incognito = self.incognito;
  2360. let parent = opt_str_lit(self.parent.as_ref());
  2361. let zoom_hotkeys_enabled = self.zoom_hotkeys_enabled;
  2362. let browser_extensions_enabled = self.browser_extensions_enabled;
  2363. literal_struct!(
  2364. tokens,
  2365. ::tauri::utils::config::WindowConfig,
  2366. label,
  2367. url,
  2368. create,
  2369. user_agent,
  2370. drag_drop_enabled,
  2371. center,
  2372. x,
  2373. y,
  2374. width,
  2375. height,
  2376. min_width,
  2377. min_height,
  2378. max_width,
  2379. max_height,
  2380. resizable,
  2381. maximizable,
  2382. minimizable,
  2383. closable,
  2384. title,
  2385. proxy_url,
  2386. fullscreen,
  2387. focus,
  2388. transparent,
  2389. maximized,
  2390. visible,
  2391. decorations,
  2392. always_on_bottom,
  2393. always_on_top,
  2394. visible_on_all_workspaces,
  2395. content_protected,
  2396. skip_taskbar,
  2397. theme,
  2398. title_bar_style,
  2399. hidden_title,
  2400. accept_first_mouse,
  2401. tabbing_identifier,
  2402. additional_browser_args,
  2403. shadow,
  2404. window_effects,
  2405. incognito,
  2406. parent,
  2407. zoom_hotkeys_enabled,
  2408. browser_extensions_enabled
  2409. );
  2410. }
  2411. }
  2412. impl ToTokens for PatternKind {
  2413. fn to_tokens(&self, tokens: &mut TokenStream) {
  2414. let prefix = quote! { ::tauri::utils::config::PatternKind };
  2415. tokens.append_all(match self {
  2416. Self::Brownfield => quote! { #prefix::Brownfield },
  2417. #[cfg(not(feature = "isolation"))]
  2418. Self::Isolation { dir: _ } => quote! { #prefix::Brownfield },
  2419. #[cfg(feature = "isolation")]
  2420. Self::Isolation { dir } => {
  2421. let dir = path_buf_lit(dir);
  2422. quote! { #prefix::Isolation { dir: #dir } }
  2423. }
  2424. })
  2425. }
  2426. }
  2427. impl ToTokens for WebviewInstallMode {
  2428. fn to_tokens(&self, tokens: &mut TokenStream) {
  2429. let prefix = quote! { ::tauri::utils::config::WebviewInstallMode };
  2430. tokens.append_all(match self {
  2431. Self::Skip => quote! { #prefix::Skip },
  2432. Self::DownloadBootstrapper { silent } => {
  2433. quote! { #prefix::DownloadBootstrapper { silent: #silent } }
  2434. }
  2435. Self::EmbedBootstrapper { silent } => {
  2436. quote! { #prefix::EmbedBootstrapper { silent: #silent } }
  2437. }
  2438. Self::OfflineInstaller { silent } => {
  2439. quote! { #prefix::OfflineInstaller { silent: #silent } }
  2440. }
  2441. Self::FixedRuntime { path } => {
  2442. let path = path_buf_lit(path);
  2443. quote! { #prefix::FixedRuntime { path: #path } }
  2444. }
  2445. })
  2446. }
  2447. }
  2448. impl ToTokens for WindowsConfig {
  2449. fn to_tokens(&self, tokens: &mut TokenStream) {
  2450. let webview_install_mode = &self.webview_install_mode;
  2451. tokens.append_all(quote! { ::tauri::utils::config::WindowsConfig {
  2452. webview_install_mode: #webview_install_mode,
  2453. ..Default::default()
  2454. }})
  2455. }
  2456. }
  2457. impl ToTokens for BundleConfig {
  2458. fn to_tokens(&self, tokens: &mut TokenStream) {
  2459. let publisher = quote!(None);
  2460. let homepage = quote!(None);
  2461. let icon = vec_lit(&self.icon, str_lit);
  2462. let active = self.active;
  2463. let targets = quote!(Default::default());
  2464. let create_updater_artifacts = quote!(Default::default());
  2465. let resources = quote!(None);
  2466. let copyright = quote!(None);
  2467. let category = quote!(None);
  2468. let file_associations = quote!(None);
  2469. let short_description = quote!(None);
  2470. let long_description = quote!(None);
  2471. let use_local_tools_dir = self.use_local_tools_dir;
  2472. let external_bin = opt_vec_lit(self.external_bin.as_ref(), str_lit);
  2473. let windows = &self.windows;
  2474. let license = opt_str_lit(self.license.as_ref());
  2475. let license_file = opt_lit(self.license_file.as_ref().map(path_buf_lit).as_ref());
  2476. let linux = quote!(Default::default());
  2477. let macos = quote!(Default::default());
  2478. let ios = quote!(Default::default());
  2479. let android = quote!(Default::default());
  2480. literal_struct!(
  2481. tokens,
  2482. ::tauri::utils::config::BundleConfig,
  2483. active,
  2484. publisher,
  2485. homepage,
  2486. icon,
  2487. targets,
  2488. create_updater_artifacts,
  2489. resources,
  2490. copyright,
  2491. category,
  2492. license,
  2493. license_file,
  2494. file_associations,
  2495. short_description,
  2496. long_description,
  2497. use_local_tools_dir,
  2498. external_bin,
  2499. windows,
  2500. linux,
  2501. macos,
  2502. ios,
  2503. android
  2504. );
  2505. }
  2506. }
  2507. impl ToTokens for FrontendDist {
  2508. fn to_tokens(&self, tokens: &mut TokenStream) {
  2509. let prefix = quote! { ::tauri::utils::config::FrontendDist };
  2510. tokens.append_all(match self {
  2511. Self::Url(url) => {
  2512. let url = url_lit(url);
  2513. quote! { #prefix::Url(#url) }
  2514. }
  2515. Self::Directory(path) => {
  2516. let path = path_buf_lit(path);
  2517. quote! { #prefix::Directory(#path) }
  2518. }
  2519. Self::Files(files) => {
  2520. let files = vec_lit(files, path_buf_lit);
  2521. quote! { #prefix::Files(#files) }
  2522. }
  2523. })
  2524. }
  2525. }
  2526. impl ToTokens for BuildConfig {
  2527. fn to_tokens(&self, tokens: &mut TokenStream) {
  2528. let dev_url = opt_lit(self.dev_url.as_ref().map(url_lit).as_ref());
  2529. let frontend_dist = opt_lit(self.frontend_dist.as_ref());
  2530. let runner = quote!(None);
  2531. let before_dev_command = quote!(None);
  2532. let before_build_command = quote!(None);
  2533. let before_bundle_command = quote!(None);
  2534. let features = quote!(None);
  2535. literal_struct!(
  2536. tokens,
  2537. ::tauri::utils::config::BuildConfig,
  2538. runner,
  2539. dev_url,
  2540. frontend_dist,
  2541. before_dev_command,
  2542. before_build_command,
  2543. before_bundle_command,
  2544. features
  2545. );
  2546. }
  2547. }
  2548. impl ToTokens for CspDirectiveSources {
  2549. fn to_tokens(&self, tokens: &mut TokenStream) {
  2550. let prefix = quote! { ::tauri::utils::config::CspDirectiveSources };
  2551. tokens.append_all(match self {
  2552. Self::Inline(sources) => {
  2553. let sources = sources.as_str();
  2554. quote!(#prefix::Inline(#sources.into()))
  2555. }
  2556. Self::List(list) => {
  2557. let list = vec_lit(list, str_lit);
  2558. quote!(#prefix::List(#list))
  2559. }
  2560. })
  2561. }
  2562. }
  2563. impl ToTokens for Csp {
  2564. fn to_tokens(&self, tokens: &mut TokenStream) {
  2565. let prefix = quote! { ::tauri::utils::config::Csp };
  2566. tokens.append_all(match self {
  2567. Self::Policy(policy) => {
  2568. let policy = policy.as_str();
  2569. quote!(#prefix::Policy(#policy.into()))
  2570. }
  2571. Self::DirectiveMap(list) => {
  2572. let map = map_lit(
  2573. quote! { ::std::collections::HashMap },
  2574. list,
  2575. str_lit,
  2576. identity,
  2577. );
  2578. quote!(#prefix::DirectiveMap(#map))
  2579. }
  2580. })
  2581. }
  2582. }
  2583. impl ToTokens for DisabledCspModificationKind {
  2584. fn to_tokens(&self, tokens: &mut TokenStream) {
  2585. let prefix = quote! { ::tauri::utils::config::DisabledCspModificationKind };
  2586. tokens.append_all(match self {
  2587. Self::Flag(flag) => {
  2588. quote! { #prefix::Flag(#flag) }
  2589. }
  2590. Self::List(directives) => {
  2591. let directives = vec_lit(directives, str_lit);
  2592. quote! { #prefix::List(#directives) }
  2593. }
  2594. });
  2595. }
  2596. }
  2597. impl ToTokens for CapabilityEntry {
  2598. fn to_tokens(&self, tokens: &mut TokenStream) {
  2599. let prefix = quote! { ::tauri::utils::config::CapabilityEntry };
  2600. tokens.append_all(match self {
  2601. Self::Inlined(capability) => {
  2602. quote! { #prefix::Inlined(#capability) }
  2603. }
  2604. Self::Reference(id) => {
  2605. let id = str_lit(id);
  2606. quote! { #prefix::Reference(#id) }
  2607. }
  2608. });
  2609. }
  2610. }
  2611. impl ToTokens for SecurityConfig {
  2612. fn to_tokens(&self, tokens: &mut TokenStream) {
  2613. let csp = opt_lit(self.csp.as_ref());
  2614. let dev_csp = opt_lit(self.dev_csp.as_ref());
  2615. let freeze_prototype = self.freeze_prototype;
  2616. let dangerous_disable_asset_csp_modification = &self.dangerous_disable_asset_csp_modification;
  2617. let asset_protocol = &self.asset_protocol;
  2618. let pattern = &self.pattern;
  2619. let capabilities = vec_lit(&self.capabilities, identity);
  2620. literal_struct!(
  2621. tokens,
  2622. ::tauri::utils::config::SecurityConfig,
  2623. csp,
  2624. dev_csp,
  2625. freeze_prototype,
  2626. dangerous_disable_asset_csp_modification,
  2627. asset_protocol,
  2628. pattern,
  2629. capabilities
  2630. );
  2631. }
  2632. }
  2633. impl ToTokens for TrayIconConfig {
  2634. fn to_tokens(&self, tokens: &mut TokenStream) {
  2635. let id = opt_str_lit(self.id.as_ref());
  2636. let icon_as_template = self.icon_as_template;
  2637. let menu_on_left_click = self.menu_on_left_click;
  2638. let icon_path = path_buf_lit(&self.icon_path);
  2639. let title = opt_str_lit(self.title.as_ref());
  2640. let tooltip = opt_str_lit(self.tooltip.as_ref());
  2641. literal_struct!(
  2642. tokens,
  2643. ::tauri::utils::config::TrayIconConfig,
  2644. id,
  2645. icon_path,
  2646. icon_as_template,
  2647. menu_on_left_click,
  2648. title,
  2649. tooltip
  2650. );
  2651. }
  2652. }
  2653. impl ToTokens for FsScope {
  2654. fn to_tokens(&self, tokens: &mut TokenStream) {
  2655. let prefix = quote! { ::tauri::utils::config::FsScope };
  2656. tokens.append_all(match self {
  2657. Self::AllowedPaths(allow) => {
  2658. let allowed_paths = vec_lit(allow, path_buf_lit);
  2659. quote! { #prefix::AllowedPaths(#allowed_paths) }
  2660. }
  2661. Self::Scope { allow, deny , require_literal_leading_dot} => {
  2662. let allow = vec_lit(allow, path_buf_lit);
  2663. let deny = vec_lit(deny, path_buf_lit);
  2664. let require_literal_leading_dot = opt_lit(require_literal_leading_dot.as_ref());
  2665. quote! { #prefix::Scope { allow: #allow, deny: #deny, require_literal_leading_dot: #require_literal_leading_dot } }
  2666. }
  2667. });
  2668. }
  2669. }
  2670. impl ToTokens for AssetProtocolConfig {
  2671. fn to_tokens(&self, tokens: &mut TokenStream) {
  2672. let scope = &self.scope;
  2673. tokens.append_all(quote! { ::tauri::utils::config::AssetProtocolConfig { scope: #scope, ..Default::default() } })
  2674. }
  2675. }
  2676. impl ToTokens for AppConfig {
  2677. fn to_tokens(&self, tokens: &mut TokenStream) {
  2678. let windows = vec_lit(&self.windows, identity);
  2679. let security = &self.security;
  2680. let tray_icon = opt_lit(self.tray_icon.as_ref());
  2681. let macos_private_api = self.macos_private_api;
  2682. let with_global_tauri = self.with_global_tauri;
  2683. let enable_gtk_app_id = self.enable_gtk_app_id;
  2684. literal_struct!(
  2685. tokens,
  2686. ::tauri::utils::config::AppConfig,
  2687. windows,
  2688. security,
  2689. tray_icon,
  2690. macos_private_api,
  2691. with_global_tauri,
  2692. enable_gtk_app_id
  2693. );
  2694. }
  2695. }
  2696. impl ToTokens for PluginConfig {
  2697. fn to_tokens(&self, tokens: &mut TokenStream) {
  2698. let config = map_lit(
  2699. quote! { ::std::collections::HashMap },
  2700. &self.0,
  2701. str_lit,
  2702. json_value_lit,
  2703. );
  2704. tokens.append_all(quote! { ::tauri::utils::config::PluginConfig(#config) })
  2705. }
  2706. }
  2707. impl ToTokens for Config {
  2708. fn to_tokens(&self, tokens: &mut TokenStream) {
  2709. let schema = quote!(None);
  2710. let product_name = opt_str_lit(self.product_name.as_ref());
  2711. let main_binary_name = opt_str_lit(self.main_binary_name.as_ref());
  2712. let version = opt_str_lit(self.version.as_ref());
  2713. let identifier = str_lit(&self.identifier);
  2714. let app = &self.app;
  2715. let build = &self.build;
  2716. let bundle = &self.bundle;
  2717. let plugins = &self.plugins;
  2718. literal_struct!(
  2719. tokens,
  2720. ::tauri::utils::config::Config,
  2721. schema,
  2722. product_name,
  2723. main_binary_name,
  2724. version,
  2725. identifier,
  2726. app,
  2727. build,
  2728. bundle,
  2729. plugins
  2730. );
  2731. }
  2732. }
  2733. }
  2734. #[cfg(test)]
  2735. mod test {
  2736. use super::*;
  2737. // TODO: create a test that compares a config to a json config
  2738. #[test]
  2739. // test all of the default functions
  2740. fn test_defaults() {
  2741. // get default app config
  2742. let a_config = AppConfig::default();
  2743. // get default build config
  2744. let b_config = BuildConfig::default();
  2745. // get default window
  2746. let d_windows: Vec<WindowConfig> = vec![];
  2747. // get default bundle
  2748. let d_bundle = BundleConfig::default();
  2749. // create a tauri config.
  2750. let app = AppConfig {
  2751. windows: vec![],
  2752. security: SecurityConfig {
  2753. csp: None,
  2754. dev_csp: None,
  2755. freeze_prototype: false,
  2756. dangerous_disable_asset_csp_modification: DisabledCspModificationKind::Flag(false),
  2757. asset_protocol: AssetProtocolConfig::default(),
  2758. pattern: Default::default(),
  2759. capabilities: Vec::new(),
  2760. },
  2761. tray_icon: None,
  2762. macos_private_api: false,
  2763. with_global_tauri: false,
  2764. enable_gtk_app_id: false,
  2765. };
  2766. // create a build config
  2767. let build = BuildConfig {
  2768. runner: None,
  2769. dev_url: None,
  2770. frontend_dist: None,
  2771. before_dev_command: None,
  2772. before_build_command: None,
  2773. before_bundle_command: None,
  2774. features: None,
  2775. };
  2776. // create a bundle config
  2777. let bundle = BundleConfig {
  2778. active: false,
  2779. targets: Default::default(),
  2780. create_updater_artifacts: Default::default(),
  2781. publisher: None,
  2782. homepage: None,
  2783. icon: Vec::new(),
  2784. resources: None,
  2785. copyright: None,
  2786. category: None,
  2787. file_associations: None,
  2788. short_description: None,
  2789. long_description: None,
  2790. use_local_tools_dir: false,
  2791. license: None,
  2792. license_file: None,
  2793. linux: Default::default(),
  2794. macos: Default::default(),
  2795. external_bin: None,
  2796. windows: Default::default(),
  2797. ios: Default::default(),
  2798. android: Default::default(),
  2799. };
  2800. // test the configs
  2801. assert_eq!(a_config, app);
  2802. assert_eq!(b_config, build);
  2803. assert_eq!(d_bundle, bundle);
  2804. assert_eq!(d_windows, app.windows);
  2805. }
  2806. }