config.rs 112 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480
  1. // Copyright 2019-2021 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. //! This is a core functionality that is not considered part of the stable API.
  10. //! If you use it, note that it may include breaking changes in the future.
  11. #[cfg(target_os = "linux")]
  12. use heck::ToKebabCase;
  13. #[cfg(feature = "schema")]
  14. use schemars::JsonSchema;
  15. use semver::Version;
  16. use serde::{
  17. de::{Deserializer, Error as DeError, Visitor},
  18. Deserialize, Serialize, Serializer,
  19. };
  20. use serde_json::Value as JsonValue;
  21. use serde_with::skip_serializing_none;
  22. use url::Url;
  23. use std::{
  24. collections::HashMap,
  25. fmt::{self, Display},
  26. fs::read_to_string,
  27. path::PathBuf,
  28. str::FromStr,
  29. };
  30. /// Items to help with parsing content into a [`Config`].
  31. pub mod parse;
  32. pub use self::parse::parse;
  33. /// An URL to open on a Tauri webview window.
  34. #[derive(PartialEq, Eq, Debug, Clone, Deserialize, Serialize)]
  35. #[cfg_attr(feature = "schema", derive(JsonSchema))]
  36. #[serde(untagged)]
  37. #[non_exhaustive]
  38. pub enum WindowUrl {
  39. /// An external URL.
  40. External(Url),
  41. /// The path portion of an app URL.
  42. /// For instance, to load `tauri://localhost/users/john`,
  43. /// you can simply provide `users/john` in this configuration.
  44. App(PathBuf),
  45. }
  46. impl fmt::Display for WindowUrl {
  47. fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
  48. match self {
  49. Self::External(url) => write!(f, "{}", url),
  50. Self::App(path) => write!(f, "{}", path.display()),
  51. }
  52. }
  53. }
  54. impl Default for WindowUrl {
  55. fn default() -> Self {
  56. Self::App("index.html".into())
  57. }
  58. }
  59. /// A bundle referenced by tauri-bundler.
  60. #[derive(Debug, PartialEq, Eq, Clone)]
  61. #[cfg_attr(feature = "schema", derive(JsonSchema))]
  62. #[cfg_attr(feature = "schema", schemars(rename_all = "lowercase"))]
  63. pub enum BundleType {
  64. /// The debian bundle (.deb).
  65. Deb,
  66. /// The AppImage bundle (.appimage).
  67. AppImage,
  68. /// The Microsoft Installer bundle (.msi).
  69. Msi,
  70. /// The macOS application bundle (.app).
  71. App,
  72. /// The Apple Disk Image bundle (.dmg).
  73. Dmg,
  74. /// The Tauri updater bundle.
  75. Updater,
  76. }
  77. impl Display for BundleType {
  78. fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
  79. write!(
  80. f,
  81. "{}",
  82. match self {
  83. Self::Deb => "deb",
  84. Self::AppImage => "appimage",
  85. Self::Msi => "msi",
  86. Self::App => "app",
  87. Self::Dmg => "dmg",
  88. Self::Updater => "updater",
  89. }
  90. )
  91. }
  92. }
  93. impl Serialize for BundleType {
  94. fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
  95. where
  96. S: Serializer,
  97. {
  98. serializer.serialize_str(self.to_string().as_ref())
  99. }
  100. }
  101. impl<'de> Deserialize<'de> for BundleType {
  102. fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
  103. where
  104. D: Deserializer<'de>,
  105. {
  106. let s = String::deserialize(deserializer)?;
  107. match s.to_lowercase().as_str() {
  108. "deb" => Ok(Self::Deb),
  109. "appimage" => Ok(Self::AppImage),
  110. "msi" => Ok(Self::Msi),
  111. "app" => Ok(Self::App),
  112. "dmg" => Ok(Self::Dmg),
  113. "updater" => Ok(Self::Updater),
  114. _ => Err(DeError::custom(format!("unknown bundle target '{}'", s))),
  115. }
  116. }
  117. }
  118. /// Targets to bundle. Each value is case insensitive.
  119. #[derive(Debug, PartialEq, Eq, Clone)]
  120. pub enum BundleTarget {
  121. /// Bundle all targets.
  122. All,
  123. /// A list of bundle targets.
  124. List(Vec<BundleType>),
  125. /// A single bundle target.
  126. One(BundleType),
  127. }
  128. #[cfg(feature = "schema")]
  129. impl schemars::JsonSchema for BundleTarget {
  130. fn schema_name() -> std::string::String {
  131. "BundleTarget".to_owned()
  132. }
  133. fn json_schema(gen: &mut schemars::gen::SchemaGenerator) -> schemars::schema::Schema {
  134. let any_of = vec![
  135. schemars::schema::SchemaObject {
  136. enum_values: Some(vec!["all".into()]),
  137. metadata: Some(Box::new(schemars::schema::Metadata {
  138. description: Some("Bundle all targets.".to_owned()),
  139. ..Default::default()
  140. })),
  141. ..Default::default()
  142. }
  143. .into(),
  144. schemars::_private::apply_metadata(
  145. gen.subschema_for::<Vec<BundleType>>(),
  146. schemars::schema::Metadata {
  147. description: Some("A list of bundle targets.".to_owned()),
  148. ..Default::default()
  149. },
  150. ),
  151. schemars::_private::apply_metadata(
  152. gen.subschema_for::<BundleType>(),
  153. schemars::schema::Metadata {
  154. description: Some("A single bundle target.".to_owned()),
  155. ..Default::default()
  156. },
  157. ),
  158. ];
  159. schemars::schema::SchemaObject {
  160. subschemas: Some(Box::new(schemars::schema::SubschemaValidation {
  161. any_of: Some(any_of),
  162. ..Default::default()
  163. })),
  164. metadata: Some(Box::new(schemars::schema::Metadata {
  165. description: Some("Targets to bundle. Each value is case insensitive.".to_owned()),
  166. ..Default::default()
  167. })),
  168. ..Default::default()
  169. }
  170. .into()
  171. }
  172. }
  173. impl Default for BundleTarget {
  174. fn default() -> Self {
  175. Self::All
  176. }
  177. }
  178. impl Serialize for BundleTarget {
  179. fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
  180. where
  181. S: Serializer,
  182. {
  183. match self {
  184. Self::All => serializer.serialize_str("all"),
  185. Self::List(l) => l.serialize(serializer),
  186. Self::One(t) => serializer.serialize_str(t.to_string().as_ref()),
  187. }
  188. }
  189. }
  190. impl<'de> Deserialize<'de> for BundleTarget {
  191. fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
  192. where
  193. D: Deserializer<'de>,
  194. {
  195. #[derive(Deserialize, Serialize)]
  196. #[serde(untagged)]
  197. pub enum BundleTargetInner {
  198. List(Vec<BundleType>),
  199. One(BundleType),
  200. All(String),
  201. }
  202. match BundleTargetInner::deserialize(deserializer)? {
  203. BundleTargetInner::All(s) if s.to_lowercase() == "all" => Ok(Self::All),
  204. BundleTargetInner::All(t) => Err(DeError::custom(format!("invalid bundle type {}", t))),
  205. BundleTargetInner::List(l) => Ok(Self::List(l)),
  206. BundleTargetInner::One(t) => Ok(Self::One(t)),
  207. }
  208. }
  209. }
  210. impl BundleTarget {
  211. /// Gets the bundle targets as a [`Vec`]. The vector is empty when set to [`BundleTarget::All`].
  212. #[allow(dead_code)]
  213. pub fn to_vec(&self) -> Vec<BundleType> {
  214. match self {
  215. Self::All => vec![],
  216. Self::List(list) => list.clone(),
  217. Self::One(i) => vec![i.clone()],
  218. }
  219. }
  220. }
  221. /// Configuration for AppImage bundles.
  222. #[derive(Debug, Default, PartialEq, Eq, Clone, Deserialize, Serialize)]
  223. #[cfg_attr(feature = "schema", derive(JsonSchema))]
  224. #[serde(rename_all = "camelCase", deny_unknown_fields)]
  225. pub struct AppImageConfig {
  226. /// Include additional gstreamer dependencies needed for audio and video playback.
  227. /// This increases the bundle size by ~15-35MB depending on your build system.
  228. #[serde(default)]
  229. pub bundle_media_framework: bool,
  230. }
  231. /// Configuration for Debian (.deb) bundles.
  232. #[skip_serializing_none]
  233. #[derive(Debug, Default, PartialEq, Eq, Clone, Deserialize, Serialize)]
  234. #[cfg_attr(feature = "schema", derive(JsonSchema))]
  235. #[serde(rename_all = "camelCase", deny_unknown_fields)]
  236. pub struct DebConfig {
  237. /// The list of deb dependencies your application relies on.
  238. pub depends: Option<Vec<String>>,
  239. /// The files to include on the package.
  240. #[serde(default)]
  241. pub files: HashMap<PathBuf, PathBuf>,
  242. }
  243. fn de_minimum_system_version<'de, D>(deserializer: D) -> Result<Option<String>, D::Error>
  244. where
  245. D: Deserializer<'de>,
  246. {
  247. let version = Option::<String>::deserialize(deserializer)?;
  248. match version {
  249. Some(v) if v.is_empty() => Ok(minimum_system_version()),
  250. e => Ok(e),
  251. }
  252. }
  253. /// Configuration for the macOS bundles.
  254. #[skip_serializing_none]
  255. #[derive(Debug, PartialEq, Eq, Clone, Deserialize, Serialize)]
  256. #[cfg_attr(feature = "schema", derive(JsonSchema))]
  257. #[serde(rename_all = "camelCase", deny_unknown_fields)]
  258. pub struct MacConfig {
  259. /// A list of strings indicating any macOS X frameworks that need to be bundled with the application.
  260. ///
  261. /// 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.
  262. pub frameworks: Option<Vec<String>>,
  263. /// A version string indicating the minimum macOS X version that the bundled application supports. Defaults to `10.13`.
  264. ///
  265. /// Setting it to `null` completely removes the `LSMinimumSystemVersion` field on the bundle's `Info.plist`
  266. /// and the `MACOSX_DEPLOYMENT_TARGET` environment variable.
  267. ///
  268. /// An empty string is considered an invalid value so the default value is used.
  269. #[serde(
  270. deserialize_with = "de_minimum_system_version",
  271. default = "minimum_system_version"
  272. )]
  273. pub minimum_system_version: Option<String>,
  274. /// Allows your application to communicate with the outside world.
  275. /// It should be a lowercase, without port and protocol domain name.
  276. pub exception_domain: Option<String>,
  277. /// The path to the license file to add to the DMG bundle.
  278. pub license: Option<String>,
  279. /// Identity to use for code signing.
  280. pub signing_identity: Option<String>,
  281. /// Provider short name for notarization.
  282. pub provider_short_name: Option<String>,
  283. /// Path to the entitlements file.
  284. pub entitlements: Option<String>,
  285. }
  286. impl Default for MacConfig {
  287. fn default() -> Self {
  288. Self {
  289. frameworks: None,
  290. minimum_system_version: minimum_system_version(),
  291. exception_domain: None,
  292. license: None,
  293. signing_identity: None,
  294. provider_short_name: None,
  295. entitlements: None,
  296. }
  297. }
  298. }
  299. fn minimum_system_version() -> Option<String> {
  300. Some("10.13".into())
  301. }
  302. /// Configuration for a target language for the WiX build.
  303. #[derive(Debug, PartialEq, Eq, Clone, Deserialize, Serialize)]
  304. #[cfg_attr(feature = "schema", derive(JsonSchema))]
  305. #[serde(rename_all = "camelCase", deny_unknown_fields)]
  306. pub struct WixLanguageConfig {
  307. /// The path to a locale (`.wxl`) file. See <https://wixtoolset.org/documentation/manual/v3/howtos/ui_and_localization/build_a_localized_version.html>.
  308. pub locale_path: Option<String>,
  309. }
  310. /// The languages to build using WiX.
  311. #[derive(Debug, PartialEq, Eq, Clone, Deserialize, Serialize)]
  312. #[cfg_attr(feature = "schema", derive(JsonSchema))]
  313. #[serde(untagged)]
  314. pub enum WixLanguage {
  315. /// A single language to build, without configuration.
  316. One(String),
  317. /// A list of languages to build, without configuration.
  318. List(Vec<String>),
  319. /// A map of languages and its configuration.
  320. Localized(HashMap<String, WixLanguageConfig>),
  321. }
  322. impl Default for WixLanguage {
  323. fn default() -> Self {
  324. Self::One("en-US".into())
  325. }
  326. }
  327. /// Configuration for the MSI bundle using WiX.
  328. #[derive(Debug, Default, PartialEq, Eq, Clone, Deserialize, Serialize)]
  329. #[cfg_attr(feature = "schema", derive(JsonSchema))]
  330. #[serde(rename_all = "camelCase", deny_unknown_fields)]
  331. pub struct WixConfig {
  332. /// The installer languages to build. See <https://docs.microsoft.com/en-us/windows/win32/msi/localizing-the-error-and-actiontext-tables>.
  333. #[serde(default)]
  334. pub language: WixLanguage,
  335. /// A custom .wxs template to use.
  336. pub template: Option<PathBuf>,
  337. /// A list of paths to .wxs files with WiX fragments to use.
  338. #[serde(default)]
  339. pub fragment_paths: Vec<PathBuf>,
  340. /// The ComponentGroup element ids you want to reference from the fragments.
  341. #[serde(default)]
  342. pub component_group_refs: Vec<String>,
  343. /// The Component element ids you want to reference from the fragments.
  344. #[serde(default)]
  345. pub component_refs: Vec<String>,
  346. /// The FeatureGroup element ids you want to reference from the fragments.
  347. #[serde(default)]
  348. pub feature_group_refs: Vec<String>,
  349. /// The Feature element ids you want to reference from the fragments.
  350. #[serde(default)]
  351. pub feature_refs: Vec<String>,
  352. /// The Merge element ids you want to reference from the fragments.
  353. #[serde(default)]
  354. pub merge_refs: Vec<String>,
  355. /// Disables the Webview2 runtime installation after app install.
  356. ///
  357. /// Will be removed in v2, prefer the [`WindowsConfig::webview_install_mode`] option.
  358. #[serde(default)]
  359. pub skip_webview_install: bool,
  360. /// The path to the license file to render on the installer.
  361. ///
  362. /// Must be an RTF file, so if a different extension is provided, we convert it to the RTF format.
  363. pub license: Option<PathBuf>,
  364. /// Create an elevated update task within Windows Task Scheduler.
  365. #[serde(default)]
  366. pub enable_elevated_update_task: bool,
  367. /// Path to a bitmap file to use as the installation user interface banner.
  368. /// This bitmap will appear at the top of all but the first page of the installer.
  369. ///
  370. /// The required dimensions are 493px × 58px.
  371. pub banner_path: Option<PathBuf>,
  372. /// Path to a bitmap file to use on the installation user interface dialogs.
  373. /// It is used on the welcome and completion dialogs.
  374. /// The required dimensions are 493px × 312px.
  375. pub dialog_image_path: Option<PathBuf>,
  376. }
  377. /// Install modes for the Webview2 runtime.
  378. /// Note that for the updater bundle [`Self::DownloadBootstrapper`] is used.
  379. ///
  380. /// For more information see <https://tauri.app/v1/guides/building/windows>.
  381. #[derive(Debug, PartialEq, Eq, Clone, Serialize, Deserialize)]
  382. #[serde(tag = "type", rename_all = "camelCase", deny_unknown_fields)]
  383. #[cfg_attr(feature = "schema", derive(JsonSchema))]
  384. pub enum WebviewInstallMode {
  385. /// Do not install the Webview2 as part of the Windows Installer.
  386. Skip,
  387. /// Download the bootstrapper and run it.
  388. /// Requires internet connection.
  389. /// Results in a smaller installer size, but is not recommended on Windows 7.
  390. DownloadBootstrapper {
  391. /// Instructs the installer to run the bootstrapper in silent mode. Defaults to `true`.
  392. #[serde(default = "default_webview_install_silent")]
  393. silent: bool,
  394. },
  395. /// Embed the bootstrapper and run it.
  396. /// Requires internet connection.
  397. /// Increases the installer size by around 1.8MB, but offers better support on Windows 7.
  398. EmbedBootstrapper {
  399. /// Instructs the installer to run the bootstrapper in silent mode. Defaults to `true`.
  400. #[serde(default = "default_webview_install_silent")]
  401. silent: bool,
  402. },
  403. /// Embed the offline installer and run it.
  404. /// Does not require internet connection.
  405. /// Increases the installer size by around 127MB.
  406. OfflineInstaller {
  407. /// Instructs the installer to run the installer in silent mode. Defaults to `true`.
  408. #[serde(default = "default_webview_install_silent")]
  409. silent: bool,
  410. },
  411. /// Embed a fixed webview2 version and use it at runtime.
  412. /// Increases the installer size by around 180MB.
  413. FixedRuntime {
  414. /// The path to the fixed runtime to use.
  415. ///
  416. /// The fixed version can be downloaded [on the official website](https://developer.microsoft.com/en-us/microsoft-edge/webview2/#download-section).
  417. /// The `.cab` file must be extracted to a folder and this folder path must be defined on this field.
  418. path: PathBuf,
  419. },
  420. }
  421. fn default_webview_install_silent() -> bool {
  422. true
  423. }
  424. impl Default for WebviewInstallMode {
  425. fn default() -> Self {
  426. Self::DownloadBootstrapper {
  427. silent: default_webview_install_silent(),
  428. }
  429. }
  430. }
  431. /// Windows bundler configuration.
  432. #[derive(Debug, PartialEq, Eq, Clone, Deserialize, Serialize)]
  433. #[cfg_attr(feature = "schema", derive(JsonSchema))]
  434. #[serde(rename_all = "camelCase", deny_unknown_fields)]
  435. pub struct WindowsConfig {
  436. /// Specifies the file digest algorithm to use for creating file signatures.
  437. /// Required for code signing. SHA-256 is recommended.
  438. pub digest_algorithm: Option<String>,
  439. /// Specifies the SHA1 hash of the signing certificate.
  440. pub certificate_thumbprint: Option<String>,
  441. /// Server to use during timestamping.
  442. pub timestamp_url: Option<String>,
  443. /// Whether to use Time-Stamp Protocol (TSP, a.k.a. RFC 3161) for the timestamp server. Your code signing provider may
  444. /// use a TSP timestamp server, like e.g. SSL.com does. If so, enable TSP by setting to true.
  445. #[serde(default)]
  446. pub tsp: bool,
  447. /// The installation mode for the Webview2 runtime.
  448. #[serde(default)]
  449. pub webview_install_mode: WebviewInstallMode,
  450. /// Path to the webview fixed runtime to use. Overwrites [`Self::webview_install_mode`] if set.
  451. ///
  452. /// Will be removed in v2, prefer the [`Self::webview_install_mode`] option.
  453. ///
  454. /// The fixed version can be downloaded [on the official website](https://developer.microsoft.com/en-us/microsoft-edge/webview2/#download-section).
  455. /// The `.cab` file must be extracted to a folder and this folder path must be defined on this field.
  456. pub webview_fixed_runtime_path: Option<PathBuf>,
  457. /// Validates a second app installation, blocking the user from installing an older version if set to `false`.
  458. ///
  459. /// 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`.
  460. ///
  461. /// The default value of this flag is `true`.
  462. #[serde(default = "default_allow_downgrades")]
  463. pub allow_downgrades: bool,
  464. /// Configuration for the MSI generated with WiX.
  465. pub wix: Option<WixConfig>,
  466. }
  467. impl Default for WindowsConfig {
  468. fn default() -> Self {
  469. Self {
  470. digest_algorithm: None,
  471. certificate_thumbprint: None,
  472. timestamp_url: None,
  473. tsp: false,
  474. webview_install_mode: Default::default(),
  475. webview_fixed_runtime_path: None,
  476. allow_downgrades: default_allow_downgrades(),
  477. wix: None,
  478. }
  479. }
  480. }
  481. fn default_allow_downgrades() -> bool {
  482. true
  483. }
  484. /// Configuration for tauri-bundler.
  485. #[skip_serializing_none]
  486. #[derive(Debug, Default, PartialEq, Eq, Clone, Deserialize, Serialize)]
  487. #[cfg_attr(feature = "schema", derive(JsonSchema))]
  488. #[serde(rename_all = "camelCase", deny_unknown_fields)]
  489. pub struct BundleConfig {
  490. /// Whether Tauri should bundle your application or just output the executable.
  491. #[serde(default)]
  492. pub active: bool,
  493. /// The bundle targets, currently supports ["deb", "appimage", "msi", "app", "dmg", "updater"] or "all".
  494. #[serde(default)]
  495. pub targets: BundleTarget,
  496. /// The application identifier in reverse domain name notation (e.g. `com.tauri.example`).
  497. /// This string must be unique across applications since it is used in system configurations like
  498. /// the bundle ID and path to the webview data directory.
  499. /// This string must contain only alphanumeric characters (A–Z, a–z, and 0–9), hyphens (-),
  500. /// and periods (.).
  501. pub identifier: String,
  502. /// The app's icons
  503. #[serde(default)]
  504. pub icon: Vec<String>,
  505. /// App resources to bundle.
  506. /// Each resource is a path to a file or directory.
  507. /// Glob patterns are supported.
  508. pub resources: Option<Vec<String>>,
  509. /// A copyright string associated with your application.
  510. pub copyright: Option<String>,
  511. /// The application kind.
  512. ///
  513. /// Should be one of the following:
  514. /// 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.
  515. pub category: Option<String>,
  516. /// A short description of your application.
  517. pub short_description: Option<String>,
  518. /// A longer, multi-line description of the application.
  519. pub long_description: Option<String>,
  520. /// Configuration for the AppImage bundle.
  521. #[serde(default)]
  522. pub appimage: AppImageConfig,
  523. /// Configuration for the Debian bundle.
  524. #[serde(default)]
  525. pub deb: DebConfig,
  526. /// Configuration for the macOS bundles.
  527. #[serde(rename = "macOS", default)]
  528. pub macos: MacConfig,
  529. /// A list of—either absolute or relative—paths to binaries to embed with your application.
  530. ///
  531. /// Note that Tauri will look for system-specific binaries following the pattern "binary-name{-target-triple}{.system-extension}".
  532. ///
  533. /// E.g. for the external binary "my-binary", Tauri looks for:
  534. ///
  535. /// - "my-binary-x86_64-pc-windows-msvc.exe" for Windows
  536. /// - "my-binary-x86_64-apple-darwin" for macOS
  537. /// - "my-binary-x86_64-unknown-linux-gnu" for Linux
  538. ///
  539. /// so don't forget to provide binaries for all targeted platforms.
  540. pub external_bin: Option<Vec<String>>,
  541. /// Configuration for the Windows bundle.
  542. #[serde(default)]
  543. pub windows: WindowsConfig,
  544. }
  545. /// A CLI argument definition.
  546. #[skip_serializing_none]
  547. #[derive(Debug, PartialEq, Eq, Clone, Deserialize, Serialize)]
  548. #[cfg_attr(feature = "schema", derive(JsonSchema))]
  549. #[serde(rename_all = "camelCase", deny_unknown_fields)]
  550. pub struct CliArg {
  551. /// The short version of the argument, without the preceding -.
  552. ///
  553. /// NOTE: Any leading `-` characters will be stripped, and only the first non-character will be used as the short version.
  554. pub short: Option<char>,
  555. /// The unique argument name
  556. pub name: String,
  557. /// The argument description which will be shown on the help information.
  558. /// Typically, this is a short (one line) description of the arg.
  559. pub description: Option<String>,
  560. /// The argument long description which will be shown on the help information.
  561. /// Typically this a more detailed (multi-line) message that describes the argument.
  562. pub long_description: Option<String>,
  563. /// Specifies that the argument takes a value at run time.
  564. ///
  565. /// NOTE: values for arguments may be specified in any of the following methods
  566. /// - Using a space such as -o value or --option value
  567. /// - Using an equals and no space such as -o=value or --option=value
  568. /// - Use a short and no space such as -ovalue
  569. #[serde(default)]
  570. pub takes_value: bool,
  571. /// Specifies that the argument may have an unknown number of multiple values. Without any other settings, this argument may appear only once.
  572. ///
  573. /// For example, --opt val1 val2 is allowed, but --opt val1 val2 --opt val3 is not.
  574. ///
  575. /// NOTE: Setting this requires `takes_value` to be set to true.
  576. #[serde(default)]
  577. pub multiple: bool,
  578. /// Specifies that the argument may appear more than once.
  579. /// For flags, this results in the number of occurrences of the flag being recorded. For example -ddd or -d -d -d would count as three occurrences.
  580. /// For options or arguments that take a value, this does not affect how many values they can accept. (i.e. only one at a time is allowed)
  581. ///
  582. /// For example, --opt val1 --opt val2 is allowed, but --opt val1 val2 is not.
  583. #[serde(default)]
  584. pub multiple_occurrences: bool,
  585. /// Specifies how many values are required to satisfy this argument. For example, if you had a
  586. /// `-f <file>` argument where you wanted exactly 3 'files' you would set
  587. /// `number_of_values = 3`, and this argument wouldn't be satisfied unless the user provided
  588. /// 3 and only 3 values.
  589. ///
  590. /// **NOTE:** Does *not* require `multiple_occurrences = true` to be set. Setting
  591. /// `multiple_occurrences = true` would allow `-f <file> <file> <file> -f <file> <file> <file>` where
  592. /// as *not* setting it would only allow one occurrence of this argument.
  593. ///
  594. /// **NOTE:** implicitly sets `takes_value = true` and `multiple_values = true`.
  595. pub number_of_values: Option<usize>,
  596. /// Specifies a list of possible values for this argument.
  597. /// At runtime, the CLI verifies that only one of the specified values was used, or fails with an error message.
  598. pub possible_values: Option<Vec<String>>,
  599. /// Specifies the minimum number of values for this argument.
  600. /// For example, if you had a -f `<file>` argument where you wanted at least 2 'files',
  601. /// you would set `minValues: 2`, and this argument would be satisfied if the user provided, 2 or more values.
  602. pub min_values: Option<usize>,
  603. /// Specifies the maximum number of values are for this argument.
  604. /// For example, if you had a -f `<file>` argument where you wanted up to 3 'files',
  605. /// you would set .max_values(3), and this argument would be satisfied if the user provided, 1, 2, or 3 values.
  606. pub max_values: Option<usize>,
  607. /// Sets whether or not the argument is required by default.
  608. ///
  609. /// - Required by default means it is required, when no other conflicting rules have been evaluated
  610. /// - Conflicting rules take precedence over being required.
  611. #[serde(default)]
  612. pub required: bool,
  613. /// Sets an arg that override this arg's required setting
  614. /// i.e. this arg will be required unless this other argument is present.
  615. pub required_unless_present: Option<String>,
  616. /// Sets args that override this arg's required setting
  617. /// i.e. this arg will be required unless all these other arguments are present.
  618. pub required_unless_present_all: Option<Vec<String>>,
  619. /// Sets args that override this arg's required setting
  620. /// i.e. this arg will be required unless at least one of these other arguments are present.
  621. pub required_unless_present_any: Option<Vec<String>>,
  622. /// Sets a conflicting argument by name
  623. /// i.e. when using this argument, the following argument can't be present and vice versa.
  624. pub conflicts_with: Option<String>,
  625. /// The same as conflictsWith but allows specifying multiple two-way conflicts per argument.
  626. pub conflicts_with_all: Option<Vec<String>>,
  627. /// Tets an argument by name that is required when this one is present
  628. /// i.e. when using this argument, the following argument must be present.
  629. pub requires: Option<String>,
  630. /// Sts multiple arguments by names that are required when this one is present
  631. /// i.e. when using this argument, the following arguments must be present.
  632. pub requires_all: Option<Vec<String>>,
  633. /// Allows a conditional requirement with the signature [arg, value]
  634. /// the requirement will only become valid if `arg`'s value equals `${value}`.
  635. pub requires_if: Option<Vec<String>>,
  636. /// Allows specifying that an argument is required conditionally with the signature [arg, value]
  637. /// the requirement will only become valid if the `arg`'s value equals `${value}`.
  638. pub required_if_eq: Option<Vec<String>>,
  639. /// Requires that options use the --option=val syntax
  640. /// i.e. an equals between the option and associated value.
  641. pub require_equals: Option<bool>,
  642. /// The positional argument index, starting at 1.
  643. ///
  644. /// The index refers to position according to other positional argument.
  645. /// It does not define position in the argument list as a whole. When utilized with multiple=true,
  646. /// only the last positional argument may be defined as multiple (i.e. the one with the highest index).
  647. #[cfg_attr(feature = "schema", validate(range(min = 1)))]
  648. pub index: Option<usize>,
  649. }
  650. /// describes a CLI configuration
  651. #[skip_serializing_none]
  652. #[derive(Debug, PartialEq, Eq, Clone, Deserialize, Serialize)]
  653. #[cfg_attr(feature = "schema", derive(JsonSchema))]
  654. #[serde(rename_all = "camelCase", deny_unknown_fields)]
  655. pub struct CliConfig {
  656. /// Command description which will be shown on the help information.
  657. pub description: Option<String>,
  658. /// Command long description which will be shown on the help information.
  659. pub long_description: Option<String>,
  660. /// Adds additional help information to be displayed in addition to auto-generated help.
  661. /// This information is displayed before the auto-generated help information.
  662. /// This is often used for header information.
  663. pub before_help: Option<String>,
  664. /// Adds additional help information to be displayed in addition to auto-generated help.
  665. /// This information is displayed after the auto-generated help information.
  666. /// This is often used to describe how to use the arguments, or caveats to be noted.
  667. pub after_help: Option<String>,
  668. /// List of arguments for the command
  669. pub args: Option<Vec<CliArg>>,
  670. /// List of subcommands of this command
  671. pub subcommands: Option<HashMap<String, CliConfig>>,
  672. }
  673. impl CliConfig {
  674. /// List of arguments for the command
  675. pub fn args(&self) -> Option<&Vec<CliArg>> {
  676. self.args.as_ref()
  677. }
  678. /// List of subcommands of this command
  679. pub fn subcommands(&self) -> Option<&HashMap<String, CliConfig>> {
  680. self.subcommands.as_ref()
  681. }
  682. /// Command description which will be shown on the help information.
  683. pub fn description(&self) -> Option<&String> {
  684. self.description.as_ref()
  685. }
  686. /// Command long description which will be shown on the help information.
  687. pub fn long_description(&self) -> Option<&String> {
  688. self.description.as_ref()
  689. }
  690. /// Adds additional help information to be displayed in addition to auto-generated help.
  691. /// This information is displayed before the auto-generated help information.
  692. /// This is often used for header information.
  693. pub fn before_help(&self) -> Option<&String> {
  694. self.before_help.as_ref()
  695. }
  696. /// Adds additional help information to be displayed in addition to auto-generated help.
  697. /// This information is displayed after the auto-generated help information.
  698. /// This is often used to describe how to use the arguments, or caveats to be noted.
  699. pub fn after_help(&self) -> Option<&String> {
  700. self.after_help.as_ref()
  701. }
  702. }
  703. /// The window configuration object.
  704. #[skip_serializing_none]
  705. #[derive(Debug, PartialEq, Clone, Deserialize, Serialize)]
  706. #[cfg_attr(feature = "schema", derive(JsonSchema))]
  707. #[serde(rename_all = "camelCase", deny_unknown_fields)]
  708. pub struct WindowConfig {
  709. /// The window identifier. It must be alphanumeric.
  710. #[serde(default = "default_window_label")]
  711. pub label: String,
  712. /// The window webview URL.
  713. #[serde(default)]
  714. pub url: WindowUrl,
  715. /// Whether the file drop is enabled or not on the webview. By default it is enabled.
  716. ///
  717. /// Disabling it is required to use drag and drop on the frontend on Windows.
  718. #[serde(default = "default_file_drop_enabled")]
  719. pub file_drop_enabled: bool,
  720. /// Whether or not the window starts centered or not.
  721. #[serde(default)]
  722. pub center: bool,
  723. /// The horizontal position of the window's top left corner
  724. pub x: Option<f64>,
  725. /// The vertical position of the window's top left corner
  726. pub y: Option<f64>,
  727. /// The window width.
  728. #[serde(default = "default_width")]
  729. pub width: f64,
  730. /// The window height.
  731. #[serde(default = "default_height")]
  732. pub height: f64,
  733. /// The min window width.
  734. pub min_width: Option<f64>,
  735. /// The min window height.
  736. pub min_height: Option<f64>,
  737. /// The max window width.
  738. pub max_width: Option<f64>,
  739. /// The max window height.
  740. pub max_height: Option<f64>,
  741. /// Whether the window is resizable or not.
  742. #[serde(default = "default_resizable")]
  743. pub resizable: bool,
  744. /// The window title.
  745. #[serde(default = "default_title")]
  746. pub title: String,
  747. /// Whether the window starts as fullscreen or not.
  748. #[serde(default)]
  749. pub fullscreen: bool,
  750. /// Whether the window will be initially hidden or focused.
  751. #[serde(default = "default_focus")]
  752. pub focus: bool,
  753. /// Whether the window is transparent or not.
  754. ///
  755. /// Note that on `macOS` this requires the `macos-private-api` feature flag, enabled under `tauri.conf.json > tauri > macOSPrivateApi`.
  756. /// WARNING: Using private APIs on `macOS` prevents your application from being accepted to the `App Store`.
  757. #[serde(default)]
  758. pub transparent: bool,
  759. /// Whether the window is maximized or not.
  760. #[serde(default)]
  761. pub maximized: bool,
  762. /// Whether the window is visible or not.
  763. #[serde(default = "default_visible")]
  764. pub visible: bool,
  765. /// Whether the window should have borders and bars.
  766. #[serde(default = "default_decorations")]
  767. pub decorations: bool,
  768. /// Whether the window should always be on top of other windows.
  769. #[serde(default)]
  770. pub always_on_top: bool,
  771. /// Whether or not the window icon should be added to the taskbar.
  772. #[serde(default)]
  773. pub skip_taskbar: bool,
  774. /// The initial window theme. Defaults to the system theme. Only implemented on Windows and macOS 10.14+.
  775. pub theme: Option<crate::Theme>,
  776. }
  777. impl Default for WindowConfig {
  778. fn default() -> Self {
  779. Self {
  780. label: default_window_label(),
  781. url: WindowUrl::default(),
  782. file_drop_enabled: default_file_drop_enabled(),
  783. center: false,
  784. x: None,
  785. y: None,
  786. width: default_width(),
  787. height: default_height(),
  788. min_width: None,
  789. min_height: None,
  790. max_width: None,
  791. max_height: None,
  792. resizable: default_resizable(),
  793. title: default_title(),
  794. fullscreen: false,
  795. focus: false,
  796. transparent: false,
  797. maximized: false,
  798. visible: default_visible(),
  799. decorations: default_decorations(),
  800. always_on_top: false,
  801. skip_taskbar: false,
  802. theme: None,
  803. }
  804. }
  805. }
  806. fn default_window_label() -> String {
  807. "main".to_string()
  808. }
  809. fn default_width() -> f64 {
  810. 800f64
  811. }
  812. fn default_height() -> f64 {
  813. 600f64
  814. }
  815. fn default_resizable() -> bool {
  816. true
  817. }
  818. fn default_title() -> String {
  819. "Tauri App".to_string()
  820. }
  821. fn default_focus() -> bool {
  822. true
  823. }
  824. fn default_visible() -> bool {
  825. true
  826. }
  827. fn default_decorations() -> bool {
  828. true
  829. }
  830. fn default_file_drop_enabled() -> bool {
  831. true
  832. }
  833. /// A Content-Security-Policy directive source list.
  834. /// See <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/Sources#sources>.
  835. #[derive(Debug, PartialEq, Eq, Clone, Deserialize, Serialize)]
  836. #[cfg_attr(feature = "schema", derive(JsonSchema))]
  837. #[serde(rename_all = "camelCase", untagged)]
  838. pub enum CspDirectiveSources {
  839. /// An inline list of CSP sources. Same as [`Self::List`], but concatenated with a space separator.
  840. Inline(String),
  841. /// A list of CSP sources. The collection will be concatenated with a space separator for the CSP string.
  842. List(Vec<String>),
  843. }
  844. impl Default for CspDirectiveSources {
  845. fn default() -> Self {
  846. Self::List(Vec::new())
  847. }
  848. }
  849. impl From<CspDirectiveSources> for Vec<String> {
  850. fn from(sources: CspDirectiveSources) -> Self {
  851. match sources {
  852. CspDirectiveSources::Inline(source) => source.split(' ').map(|s| s.to_string()).collect(),
  853. CspDirectiveSources::List(l) => l,
  854. }
  855. }
  856. }
  857. impl CspDirectiveSources {
  858. /// Whether the given source is configured on this directive or not.
  859. pub fn contains(&self, source: &str) -> bool {
  860. match self {
  861. Self::Inline(s) => s.contains(&format!("{} ", source)) || s.contains(&format!(" {}", source)),
  862. Self::List(l) => l.contains(&source.into()),
  863. }
  864. }
  865. /// Appends the given source to this directive.
  866. pub fn push<S: AsRef<str>>(&mut self, source: S) {
  867. match self {
  868. Self::Inline(s) => {
  869. s.push(' ');
  870. s.push_str(source.as_ref());
  871. }
  872. Self::List(l) => {
  873. l.push(source.as_ref().to_string());
  874. }
  875. }
  876. }
  877. /// Extends this CSP directive source list with the given array of sources.
  878. pub fn extend(&mut self, sources: Vec<String>) {
  879. for s in sources {
  880. self.push(s);
  881. }
  882. }
  883. }
  884. /// A Content-Security-Policy definition.
  885. /// See <https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP>.
  886. #[derive(Debug, PartialEq, Eq, Clone, Deserialize, Serialize)]
  887. #[cfg_attr(feature = "schema", derive(JsonSchema))]
  888. #[serde(rename_all = "camelCase", untagged)]
  889. pub enum Csp {
  890. /// The entire CSP policy in a single text string.
  891. Policy(String),
  892. /// An object mapping a directive with its sources values as a list of strings.
  893. DirectiveMap(HashMap<String, CspDirectiveSources>),
  894. }
  895. impl From<HashMap<String, CspDirectiveSources>> for Csp {
  896. fn from(map: HashMap<String, CspDirectiveSources>) -> Self {
  897. Self::DirectiveMap(map)
  898. }
  899. }
  900. impl From<Csp> for HashMap<String, CspDirectiveSources> {
  901. fn from(csp: Csp) -> Self {
  902. match csp {
  903. Csp::Policy(policy) => {
  904. let mut map = HashMap::new();
  905. for directive in policy.split(';') {
  906. let mut tokens = directive.trim().split(' ');
  907. if let Some(directive) = tokens.next() {
  908. let sources = tokens.map(|s| s.to_string()).collect::<Vec<String>>();
  909. map.insert(directive.to_string(), CspDirectiveSources::List(sources));
  910. }
  911. }
  912. map
  913. }
  914. Csp::DirectiveMap(m) => m,
  915. }
  916. }
  917. }
  918. impl Display for Csp {
  919. fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
  920. match self {
  921. Self::Policy(s) => write!(f, "{}", s),
  922. Self::DirectiveMap(m) => {
  923. let len = m.len();
  924. let mut i = 0;
  925. for (directive, sources) in m {
  926. let sources: Vec<String> = sources.clone().into();
  927. write!(f, "{} {}", directive, sources.join(" "))?;
  928. i += 1;
  929. if i != len {
  930. write!(f, "; ")?;
  931. }
  932. }
  933. Ok(())
  934. }
  935. }
  936. }
  937. }
  938. /// The possible values for the `dangerous_disable_asset_csp_modification` config option.
  939. #[derive(Debug, PartialEq, Eq, Clone, Deserialize, Serialize)]
  940. #[serde(untagged)]
  941. #[cfg_attr(feature = "schema", derive(JsonSchema))]
  942. pub enum DisabledCspModificationKind {
  943. /// If `true`, disables all CSP modification.
  944. /// `false` is the default value and it configures Tauri to control the CSP.
  945. Flag(bool),
  946. /// Disables the given list of CSP directives modifications.
  947. List(Vec<String>),
  948. }
  949. impl DisabledCspModificationKind {
  950. /// Determines whether the given CSP directive can be modified or not.
  951. pub fn can_modify(&self, directive: &str) -> bool {
  952. match self {
  953. Self::Flag(f) => !f,
  954. Self::List(l) => !l.contains(&directive.into()),
  955. }
  956. }
  957. }
  958. impl Default for DisabledCspModificationKind {
  959. fn default() -> Self {
  960. Self::Flag(false)
  961. }
  962. }
  963. /// Security configuration.
  964. #[skip_serializing_none]
  965. #[derive(Debug, Default, PartialEq, Eq, Clone, Deserialize, Serialize)]
  966. #[cfg_attr(feature = "schema", derive(JsonSchema))]
  967. #[serde(rename_all = "camelCase", deny_unknown_fields)]
  968. pub struct SecurityConfig {
  969. /// The Content Security Policy that will be injected on all HTML files on the built application.
  970. /// If [`dev_csp`](#SecurityConfig.devCsp) is not specified, this value is also injected on dev.
  971. ///
  972. /// This is a really important part of the configuration since it helps you ensure your WebView is secured.
  973. /// See <https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP>.
  974. pub csp: Option<Csp>,
  975. /// The Content Security Policy that will be injected on all HTML files on development.
  976. ///
  977. /// This is a really important part of the configuration since it helps you ensure your WebView is secured.
  978. /// See <https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP>.
  979. pub dev_csp: Option<Csp>,
  980. /// Freeze the `Object.prototype` when using the custom protocol.
  981. #[serde(default)]
  982. pub freeze_prototype: bool,
  983. /// Disables the Tauri-injected CSP sources.
  984. ///
  985. /// At compile time, Tauri parses all the frontend assets and changes the Content-Security-Policy
  986. /// to only allow loading of your own scripts and styles by injecting nonce and hash sources.
  987. /// This stricts your CSP, which may introduce issues when using along with other flexing sources.
  988. ///
  989. /// This configuration option allows both a boolean and a list of strings as value.
  990. /// A boolean instructs Tauri to disable the injection for all CSP injections,
  991. /// and a list of strings indicates the CSP directives that Tauri cannot inject.
  992. ///
  993. /// **WARNING:** Only disable this if you know what you are doing and have properly configured the CSP.
  994. /// Your application might be vulnerable to XSS attacks without this Tauri protection.
  995. #[serde(default)]
  996. pub dangerous_disable_asset_csp_modification: DisabledCspModificationKind,
  997. }
  998. /// Defines an allowlist type.
  999. pub trait Allowlist {
  1000. /// Returns all features associated with the allowlist struct.
  1001. fn all_features() -> Vec<&'static str>;
  1002. /// Returns the tauri features enabled on this allowlist.
  1003. fn to_features(&self) -> Vec<&'static str>;
  1004. }
  1005. macro_rules! check_feature {
  1006. ($self:ident, $features:ident, $flag:ident, $feature_name: expr) => {
  1007. if $self.$flag {
  1008. $features.push($feature_name)
  1009. }
  1010. };
  1011. }
  1012. /// Filesystem scope definition.
  1013. /// It is a list of glob patterns that restrict the API access from the webview.
  1014. ///
  1015. /// Each pattern can start with a variable that resolves to a system base directory.
  1016. /// The variables are: `$AUDIO`, `$CACHE`, `$CONFIG`, `$DATA`, `$LOCALDATA`, `$DESKTOP`,
  1017. /// `$DOCUMENT`, `$DOWNLOAD`, `$EXE`, `$FONT`, `$HOME`, `$PICTURE`, `$PUBLIC`, `$RUNTIME`,
  1018. /// `$TEMPLATE`, `$VIDEO`, `$RESOURCE`, `$APP`, `$LOG`, `$TEMP`.
  1019. #[derive(Debug, PartialEq, Eq, Clone, Deserialize, Serialize)]
  1020. #[cfg_attr(feature = "schema", derive(JsonSchema))]
  1021. #[serde(untagged)]
  1022. pub enum FsAllowlistScope {
  1023. /// A list of paths that are allowed by this scope.
  1024. AllowedPaths(Vec<PathBuf>),
  1025. /// A complete scope configuration.
  1026. Scope {
  1027. /// A list of paths that are allowed by this scope.
  1028. #[serde(default)]
  1029. allow: Vec<PathBuf>,
  1030. /// A list of paths that are not allowed by this scope.
  1031. /// This gets precedence over the [`Self::Scope::allow`] list.
  1032. #[serde(default)]
  1033. deny: Vec<PathBuf>,
  1034. },
  1035. }
  1036. impl Default for FsAllowlistScope {
  1037. fn default() -> Self {
  1038. Self::AllowedPaths(Vec::new())
  1039. }
  1040. }
  1041. impl FsAllowlistScope {
  1042. /// The list of allowed paths.
  1043. pub fn allowed_paths(&self) -> &Vec<PathBuf> {
  1044. match self {
  1045. Self::AllowedPaths(p) => p,
  1046. Self::Scope { allow, .. } => allow,
  1047. }
  1048. }
  1049. /// The list of forbidden paths.
  1050. pub fn forbidden_paths(&self) -> Option<&Vec<PathBuf>> {
  1051. match self {
  1052. Self::AllowedPaths(_) => None,
  1053. Self::Scope { deny, .. } => Some(deny),
  1054. }
  1055. }
  1056. }
  1057. /// Allowlist for the file system APIs.
  1058. #[derive(Debug, Default, PartialEq, Eq, Clone, Deserialize, Serialize)]
  1059. #[cfg_attr(feature = "schema", derive(JsonSchema))]
  1060. #[serde(rename_all = "camelCase", deny_unknown_fields)]
  1061. pub struct FsAllowlistConfig {
  1062. /// The access scope for the filesystem APIs.
  1063. #[serde(default)]
  1064. pub scope: FsAllowlistScope,
  1065. /// Use this flag to enable all file system API features.
  1066. #[serde(default)]
  1067. pub all: bool,
  1068. /// Read file from local filesystem.
  1069. #[serde(default)]
  1070. pub read_file: bool,
  1071. /// Write file to local filesystem.
  1072. #[serde(default)]
  1073. pub write_file: bool,
  1074. /// Read directory from local filesystem.
  1075. #[serde(default)]
  1076. pub read_dir: bool,
  1077. /// Copy file from local filesystem.
  1078. #[serde(default)]
  1079. pub copy_file: bool,
  1080. /// Create directory from local filesystem.
  1081. #[serde(default)]
  1082. pub create_dir: bool,
  1083. /// Remove directory from local filesystem.
  1084. #[serde(default)]
  1085. pub remove_dir: bool,
  1086. /// Remove file from local filesystem.
  1087. #[serde(default)]
  1088. pub remove_file: bool,
  1089. /// Rename file from local filesystem.
  1090. #[serde(default)]
  1091. pub rename_file: bool,
  1092. }
  1093. impl Allowlist for FsAllowlistConfig {
  1094. fn all_features() -> Vec<&'static str> {
  1095. let allowlist = Self {
  1096. scope: Default::default(),
  1097. all: false,
  1098. read_file: true,
  1099. write_file: true,
  1100. read_dir: true,
  1101. copy_file: true,
  1102. create_dir: true,
  1103. remove_dir: true,
  1104. remove_file: true,
  1105. rename_file: true,
  1106. };
  1107. let mut features = allowlist.to_features();
  1108. features.push("fs-all");
  1109. features
  1110. }
  1111. fn to_features(&self) -> Vec<&'static str> {
  1112. if self.all {
  1113. vec!["fs-all"]
  1114. } else {
  1115. let mut features = Vec::new();
  1116. check_feature!(self, features, read_file, "fs-read-file");
  1117. check_feature!(self, features, write_file, "fs-write-file");
  1118. check_feature!(self, features, read_dir, "fs-read-dir");
  1119. check_feature!(self, features, copy_file, "fs-copy-file");
  1120. check_feature!(self, features, create_dir, "fs-create-dir");
  1121. check_feature!(self, features, remove_dir, "fs-remove-dir");
  1122. check_feature!(self, features, remove_file, "fs-remove-file");
  1123. check_feature!(self, features, rename_file, "fs-rename-file");
  1124. features
  1125. }
  1126. }
  1127. }
  1128. /// Allowlist for the window APIs.
  1129. #[derive(Debug, Default, PartialEq, Eq, Clone, Deserialize, Serialize)]
  1130. #[cfg_attr(feature = "schema", derive(JsonSchema))]
  1131. #[serde(rename_all = "camelCase", deny_unknown_fields)]
  1132. pub struct WindowAllowlistConfig {
  1133. /// Use this flag to enable all window API features.
  1134. #[serde(default)]
  1135. pub all: bool,
  1136. /// Allows dynamic window creation.
  1137. #[serde(default)]
  1138. pub create: bool,
  1139. /// Allows centering the window.
  1140. #[serde(default)]
  1141. pub center: bool,
  1142. /// Allows requesting user attention on the window.
  1143. #[serde(default)]
  1144. pub request_user_attention: bool,
  1145. /// Allows setting the resizable flag of the window.
  1146. #[serde(default)]
  1147. pub set_resizable: bool,
  1148. /// Allows changing the window title.
  1149. #[serde(default)]
  1150. pub set_title: bool,
  1151. /// Allows maximizing the window.
  1152. #[serde(default)]
  1153. pub maximize: bool,
  1154. /// Allows unmaximizing the window.
  1155. #[serde(default)]
  1156. pub unmaximize: bool,
  1157. /// Allows minimizing the window.
  1158. #[serde(default)]
  1159. pub minimize: bool,
  1160. /// Allows unminimizing the window.
  1161. #[serde(default)]
  1162. pub unminimize: bool,
  1163. /// Allows showing the window.
  1164. #[serde(default)]
  1165. pub show: bool,
  1166. /// Allows hiding the window.
  1167. #[serde(default)]
  1168. pub hide: bool,
  1169. /// Allows closing the window.
  1170. #[serde(default)]
  1171. pub close: bool,
  1172. /// Allows setting the decorations flag of the window.
  1173. #[serde(default)]
  1174. pub set_decorations: bool,
  1175. /// Allows setting the always_on_top flag of the window.
  1176. #[serde(default)]
  1177. pub set_always_on_top: bool,
  1178. /// Allows setting the window size.
  1179. #[serde(default)]
  1180. pub set_size: bool,
  1181. /// Allows setting the window minimum size.
  1182. #[serde(default)]
  1183. pub set_min_size: bool,
  1184. /// Allows setting the window maximum size.
  1185. #[serde(default)]
  1186. pub set_max_size: bool,
  1187. /// Allows changing the position of the window.
  1188. #[serde(default)]
  1189. pub set_position: bool,
  1190. /// Allows setting the fullscreen flag of the window.
  1191. #[serde(default)]
  1192. pub set_fullscreen: bool,
  1193. /// Allows focusing the window.
  1194. #[serde(default)]
  1195. pub set_focus: bool,
  1196. /// Allows changing the window icon.
  1197. #[serde(default)]
  1198. pub set_icon: bool,
  1199. /// Allows setting the skip_taskbar flag of the window.
  1200. #[serde(default)]
  1201. pub set_skip_taskbar: bool,
  1202. /// Allows start dragging on the window.
  1203. #[serde(default)]
  1204. pub start_dragging: bool,
  1205. /// Allows opening the system dialog to print the window content.
  1206. #[serde(default)]
  1207. pub print: bool,
  1208. }
  1209. impl Allowlist for WindowAllowlistConfig {
  1210. fn all_features() -> Vec<&'static str> {
  1211. let allowlist = Self {
  1212. all: false,
  1213. create: true,
  1214. center: true,
  1215. request_user_attention: true,
  1216. set_resizable: true,
  1217. set_title: true,
  1218. maximize: true,
  1219. unmaximize: true,
  1220. minimize: true,
  1221. unminimize: true,
  1222. show: true,
  1223. hide: true,
  1224. close: true,
  1225. set_decorations: true,
  1226. set_always_on_top: true,
  1227. set_size: true,
  1228. set_min_size: true,
  1229. set_max_size: true,
  1230. set_position: true,
  1231. set_fullscreen: true,
  1232. set_focus: true,
  1233. set_icon: true,
  1234. set_skip_taskbar: true,
  1235. start_dragging: true,
  1236. print: true,
  1237. };
  1238. let mut features = allowlist.to_features();
  1239. features.push("window-all");
  1240. features
  1241. }
  1242. fn to_features(&self) -> Vec<&'static str> {
  1243. if self.all {
  1244. vec!["window-all"]
  1245. } else {
  1246. let mut features = Vec::new();
  1247. check_feature!(self, features, create, "window-create");
  1248. check_feature!(self, features, center, "window-center");
  1249. check_feature!(
  1250. self,
  1251. features,
  1252. request_user_attention,
  1253. "window-request-user-attention"
  1254. );
  1255. check_feature!(self, features, set_resizable, "window-set-resizable");
  1256. check_feature!(self, features, set_title, "window-set-title");
  1257. check_feature!(self, features, maximize, "window-maximize");
  1258. check_feature!(self, features, unmaximize, "window-unmaximize");
  1259. check_feature!(self, features, minimize, "window-minimize");
  1260. check_feature!(self, features, unminimize, "window-unminimize");
  1261. check_feature!(self, features, show, "window-show");
  1262. check_feature!(self, features, hide, "window-hide");
  1263. check_feature!(self, features, close, "window-close");
  1264. check_feature!(self, features, set_decorations, "window-set-decorations");
  1265. check_feature!(
  1266. self,
  1267. features,
  1268. set_always_on_top,
  1269. "window-set-always-on-top"
  1270. );
  1271. check_feature!(self, features, set_size, "window-set-size");
  1272. check_feature!(self, features, set_min_size, "window-set-min-size");
  1273. check_feature!(self, features, set_max_size, "window-set-max-size");
  1274. check_feature!(self, features, set_position, "window-set-position");
  1275. check_feature!(self, features, set_fullscreen, "window-set-fullscreen");
  1276. check_feature!(self, features, set_focus, "window-set-focus");
  1277. check_feature!(self, features, set_icon, "window-set-icon");
  1278. check_feature!(self, features, set_skip_taskbar, "window-set-skip-taskbar");
  1279. check_feature!(self, features, start_dragging, "window-start-dragging");
  1280. check_feature!(self, features, print, "window-print");
  1281. features
  1282. }
  1283. }
  1284. }
  1285. /// A command allowed to be executed by the webview API.
  1286. #[derive(Debug, PartialEq, Eq, Clone, Serialize)]
  1287. #[cfg_attr(feature = "schema", derive(JsonSchema))]
  1288. pub struct ShellAllowedCommand {
  1289. /// The name for this allowed shell command configuration.
  1290. ///
  1291. /// This name will be used inside of the webview API to call this command along with
  1292. /// any specified arguments.
  1293. pub name: String,
  1294. /// The command name.
  1295. /// It can start with a variable that resolves to a system base directory.
  1296. /// The variables are: `$AUDIO`, `$CACHE`, `$CONFIG`, `$DATA`, `$LOCALDATA`, `$DESKTOP`,
  1297. /// `$DOCUMENT`, `$DOWNLOAD`, `$EXE`, `$FONT`, `$HOME`, `$PICTURE`, `$PUBLIC`, `$RUNTIME`,
  1298. /// `$TEMPLATE`, `$VIDEO`, `$RESOURCE`, `$APP`, `$LOG`, `$TEMP`.
  1299. #[serde(rename = "cmd", default)] // use default just so the schema doesn't flag it as required
  1300. pub command: PathBuf,
  1301. /// The allowed arguments for the command execution.
  1302. #[serde(default)]
  1303. pub args: ShellAllowedArgs,
  1304. /// If this command is a sidecar command.
  1305. #[serde(default)]
  1306. pub sidecar: bool,
  1307. }
  1308. impl<'de> Deserialize<'de> for ShellAllowedCommand {
  1309. fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
  1310. where
  1311. D: Deserializer<'de>,
  1312. {
  1313. #[derive(Deserialize)]
  1314. struct InnerShellAllowedCommand {
  1315. name: String,
  1316. #[serde(rename = "cmd")]
  1317. command: Option<PathBuf>,
  1318. #[serde(default)]
  1319. args: ShellAllowedArgs,
  1320. #[serde(default)]
  1321. sidecar: bool,
  1322. }
  1323. let config = InnerShellAllowedCommand::deserialize(deserializer)?;
  1324. if !config.sidecar && config.command.is_none() {
  1325. return Err(DeError::custom(
  1326. "The shell scope `command` value is required.",
  1327. ));
  1328. }
  1329. Ok(ShellAllowedCommand {
  1330. name: config.name,
  1331. command: config.command.unwrap_or_default(),
  1332. args: config.args,
  1333. sidecar: config.sidecar,
  1334. })
  1335. }
  1336. }
  1337. /// A set of command arguments allowed to be executed by the webview API.
  1338. ///
  1339. /// A value of `true` will allow any arguments to be passed to the command. `false` will disable all
  1340. /// arguments. A list of [`ShellAllowedArg`] will set those arguments as the only valid arguments to
  1341. /// be passed to the attached command configuration.
  1342. #[derive(Debug, PartialEq, Eq, Clone, Deserialize, Serialize)]
  1343. #[cfg_attr(feature = "schema", derive(JsonSchema))]
  1344. #[serde(untagged, deny_unknown_fields)]
  1345. #[non_exhaustive]
  1346. pub enum ShellAllowedArgs {
  1347. /// Use a simple boolean to allow all or disable all arguments to this command configuration.
  1348. Flag(bool),
  1349. /// A specific set of [`ShellAllowedArg`] that are valid to call for the command configuration.
  1350. List(Vec<ShellAllowedArg>),
  1351. }
  1352. impl Default for ShellAllowedArgs {
  1353. fn default() -> Self {
  1354. Self::Flag(false)
  1355. }
  1356. }
  1357. /// A command argument allowed to be executed by the webview API.
  1358. #[derive(Debug, PartialEq, Eq, Clone, Deserialize, Serialize)]
  1359. #[cfg_attr(feature = "schema", derive(JsonSchema))]
  1360. #[serde(untagged, deny_unknown_fields)]
  1361. #[non_exhaustive]
  1362. pub enum ShellAllowedArg {
  1363. /// A non-configurable argument that is passed to the command in the order it was specified.
  1364. Fixed(String),
  1365. /// A variable that is set while calling the command from the webview API.
  1366. ///
  1367. Var {
  1368. /// [regex] validator to require passed values to conform to an expected input.
  1369. ///
  1370. /// This will require the argument value passed to this variable to match the `validator` regex
  1371. /// before it will be executed.
  1372. ///
  1373. /// [regex]: https://docs.rs/regex/latest/regex/#syntax
  1374. validator: String,
  1375. },
  1376. }
  1377. /// Shell scope definition.
  1378. /// It is a list of command names and associated CLI arguments that restrict the API access from the webview.
  1379. #[derive(Debug, Default, PartialEq, Eq, Clone, Deserialize, Serialize)]
  1380. #[cfg_attr(feature = "schema", derive(JsonSchema))]
  1381. pub struct ShellAllowlistScope(pub Vec<ShellAllowedCommand>);
  1382. /// Defines the `shell > open` api scope.
  1383. #[derive(Debug, PartialEq, Eq, Clone, Deserialize, Serialize)]
  1384. #[cfg_attr(feature = "schema", derive(JsonSchema))]
  1385. #[serde(untagged, deny_unknown_fields)]
  1386. #[non_exhaustive]
  1387. pub enum ShellAllowlistOpen {
  1388. /// If the shell open API should be enabled.
  1389. ///
  1390. /// If enabled, the default validation regex (`^https?://`) is used.
  1391. Flag(bool),
  1392. /// Enable the shell open API, with a custom regex that the opened path must match against.
  1393. ///
  1394. /// If using a custom regex to support a non-http(s) schema, care should be used to prevent values
  1395. /// that allow flag-like strings to pass validation. e.g. `--enable-debugging`, `-i`, `/R`.
  1396. Validate(String),
  1397. }
  1398. impl Default for ShellAllowlistOpen {
  1399. fn default() -> Self {
  1400. Self::Flag(false)
  1401. }
  1402. }
  1403. /// Allowlist for the shell APIs.
  1404. #[derive(Debug, Default, PartialEq, Eq, Clone, Deserialize, Serialize)]
  1405. #[cfg_attr(feature = "schema", derive(JsonSchema))]
  1406. #[serde(rename_all = "camelCase", deny_unknown_fields)]
  1407. pub struct ShellAllowlistConfig {
  1408. /// Access scope for the binary execution APIs.
  1409. /// Sidecars are automatically enabled.
  1410. #[serde(default)]
  1411. pub scope: ShellAllowlistScope,
  1412. /// Use this flag to enable all shell API features.
  1413. #[serde(default)]
  1414. pub all: bool,
  1415. /// Enable binary execution.
  1416. #[serde(default)]
  1417. pub execute: bool,
  1418. /// Enable sidecar execution, allowing the JavaScript layer to spawn a sidecar command,
  1419. /// an executable that is shipped with the application.
  1420. /// For more information see <https://tauri.app/v1/guides/building/sidecar>.
  1421. #[serde(default)]
  1422. pub sidecar: bool,
  1423. /// Open URL with the user's default application.
  1424. #[serde(default)]
  1425. pub open: ShellAllowlistOpen,
  1426. }
  1427. impl Allowlist for ShellAllowlistConfig {
  1428. fn all_features() -> Vec<&'static str> {
  1429. let allowlist = Self {
  1430. scope: Default::default(),
  1431. all: false,
  1432. execute: true,
  1433. sidecar: true,
  1434. open: ShellAllowlistOpen::Flag(true),
  1435. };
  1436. let mut features = allowlist.to_features();
  1437. features.push("shell-all");
  1438. features
  1439. }
  1440. fn to_features(&self) -> Vec<&'static str> {
  1441. if self.all {
  1442. vec!["shell-all"]
  1443. } else {
  1444. let mut features = Vec::new();
  1445. check_feature!(self, features, execute, "shell-execute");
  1446. check_feature!(self, features, sidecar, "shell-sidecar");
  1447. if !matches!(self.open, ShellAllowlistOpen::Flag(false)) {
  1448. features.push("shell-open")
  1449. }
  1450. features
  1451. }
  1452. }
  1453. }
  1454. /// Allowlist for the dialog APIs.
  1455. #[derive(Debug, Default, PartialEq, Eq, Clone, Deserialize, Serialize)]
  1456. #[cfg_attr(feature = "schema", derive(JsonSchema))]
  1457. #[serde(rename_all = "camelCase", deny_unknown_fields)]
  1458. pub struct DialogAllowlistConfig {
  1459. /// Use this flag to enable all dialog API features.
  1460. #[serde(default)]
  1461. pub all: bool,
  1462. /// Allows the API to open a dialog window to pick files.
  1463. #[serde(default)]
  1464. pub open: bool,
  1465. /// Allows the API to open a dialog window to pick where to save files.
  1466. #[serde(default)]
  1467. pub save: bool,
  1468. /// Allows the API to show a message dialog window.
  1469. #[serde(default)]
  1470. pub message: bool,
  1471. /// Allows the API to show a dialog window with Yes/No buttons.
  1472. #[serde(default)]
  1473. pub ask: bool,
  1474. /// Allows the API to show a dialog window with Ok/Cancel buttons.
  1475. #[serde(default)]
  1476. pub confirm: bool,
  1477. }
  1478. impl Allowlist for DialogAllowlistConfig {
  1479. fn all_features() -> Vec<&'static str> {
  1480. let allowlist = Self {
  1481. all: false,
  1482. open: true,
  1483. save: true,
  1484. message: true,
  1485. ask: true,
  1486. confirm: true,
  1487. };
  1488. let mut features = allowlist.to_features();
  1489. features.push("dialog-all");
  1490. features
  1491. }
  1492. fn to_features(&self) -> Vec<&'static str> {
  1493. if self.all {
  1494. vec!["dialog-all"]
  1495. } else {
  1496. let mut features = Vec::new();
  1497. check_feature!(self, features, open, "dialog-open");
  1498. check_feature!(self, features, save, "dialog-save");
  1499. check_feature!(self, features, message, "dialog-message");
  1500. check_feature!(self, features, ask, "dialog-ask");
  1501. check_feature!(self, features, confirm, "dialog-confirm");
  1502. features
  1503. }
  1504. }
  1505. }
  1506. /// HTTP API scope definition.
  1507. /// It is a list of URLs that can be accessed by the webview when using the HTTP APIs.
  1508. /// The scoped URL is matched against the request URL using a glob pattern.
  1509. ///
  1510. /// Examples:
  1511. /// - "https://**": allows all HTTPS urls
  1512. /// - "https://*.github.com/tauri-apps/tauri": allows any subdomain of "github.com" with the "tauri-apps/api" path
  1513. /// - "https://myapi.service.com/users/*": allows access to any URLs that begins with "https://myapi.service.com/users/"
  1514. #[allow(rustdoc::bare_urls)]
  1515. #[derive(Debug, Default, PartialEq, Eq, Clone, Deserialize, Serialize)]
  1516. #[cfg_attr(feature = "schema", derive(JsonSchema))]
  1517. pub struct HttpAllowlistScope(pub Vec<Url>);
  1518. /// Allowlist for the HTTP APIs.
  1519. #[derive(Debug, Default, PartialEq, Eq, Clone, Deserialize, Serialize)]
  1520. #[cfg_attr(feature = "schema", derive(JsonSchema))]
  1521. #[serde(rename_all = "camelCase", deny_unknown_fields)]
  1522. pub struct HttpAllowlistConfig {
  1523. /// The access scope for the HTTP APIs.
  1524. #[serde(default)]
  1525. pub scope: HttpAllowlistScope,
  1526. /// Use this flag to enable all HTTP API features.
  1527. #[serde(default)]
  1528. pub all: bool,
  1529. /// Allows making HTTP requests.
  1530. #[serde(default)]
  1531. pub request: bool,
  1532. }
  1533. impl Allowlist for HttpAllowlistConfig {
  1534. fn all_features() -> Vec<&'static str> {
  1535. let allowlist = Self {
  1536. scope: Default::default(),
  1537. all: false,
  1538. request: true,
  1539. };
  1540. let mut features = allowlist.to_features();
  1541. features.push("http-all");
  1542. features
  1543. }
  1544. fn to_features(&self) -> Vec<&'static str> {
  1545. if self.all {
  1546. vec!["http-all"]
  1547. } else {
  1548. let mut features = Vec::new();
  1549. check_feature!(self, features, request, "http-request");
  1550. features
  1551. }
  1552. }
  1553. }
  1554. /// Allowlist for the notification APIs.
  1555. #[derive(Debug, Default, PartialEq, Eq, Clone, Deserialize, Serialize)]
  1556. #[cfg_attr(feature = "schema", derive(JsonSchema))]
  1557. #[serde(rename_all = "camelCase", deny_unknown_fields)]
  1558. pub struct NotificationAllowlistConfig {
  1559. /// Use this flag to enable all notification API features.
  1560. #[serde(default)]
  1561. pub all: bool,
  1562. }
  1563. impl Allowlist for NotificationAllowlistConfig {
  1564. fn all_features() -> Vec<&'static str> {
  1565. let allowlist = Self { all: false };
  1566. let mut features = allowlist.to_features();
  1567. features.push("notification-all");
  1568. features
  1569. }
  1570. fn to_features(&self) -> Vec<&'static str> {
  1571. if self.all {
  1572. vec!["notification-all"]
  1573. } else {
  1574. vec![]
  1575. }
  1576. }
  1577. }
  1578. /// Allowlist for the global shortcut APIs.
  1579. #[derive(Debug, Default, PartialEq, Eq, Clone, Deserialize, Serialize)]
  1580. #[cfg_attr(feature = "schema", derive(JsonSchema))]
  1581. #[serde(rename_all = "camelCase", deny_unknown_fields)]
  1582. pub struct GlobalShortcutAllowlistConfig {
  1583. /// Use this flag to enable all global shortcut API features.
  1584. #[serde(default)]
  1585. pub all: bool,
  1586. }
  1587. impl Allowlist for GlobalShortcutAllowlistConfig {
  1588. fn all_features() -> Vec<&'static str> {
  1589. let allowlist = Self { all: false };
  1590. let mut features = allowlist.to_features();
  1591. features.push("global-shortcut-all");
  1592. features
  1593. }
  1594. fn to_features(&self) -> Vec<&'static str> {
  1595. if self.all {
  1596. vec!["global-shortcut-all"]
  1597. } else {
  1598. vec![]
  1599. }
  1600. }
  1601. }
  1602. /// Allowlist for the OS APIs.
  1603. #[derive(Debug, Default, PartialEq, Eq, Clone, Deserialize, Serialize)]
  1604. #[cfg_attr(feature = "schema", derive(JsonSchema))]
  1605. #[serde(rename_all = "camelCase", deny_unknown_fields)]
  1606. pub struct OsAllowlistConfig {
  1607. /// Use this flag to enable all OS API features.
  1608. #[serde(default)]
  1609. pub all: bool,
  1610. }
  1611. impl Allowlist for OsAllowlistConfig {
  1612. fn all_features() -> Vec<&'static str> {
  1613. let allowlist = Self { all: false };
  1614. let mut features = allowlist.to_features();
  1615. features.push("os-all");
  1616. features
  1617. }
  1618. fn to_features(&self) -> Vec<&'static str> {
  1619. if self.all {
  1620. vec!["os-all"]
  1621. } else {
  1622. vec![]
  1623. }
  1624. }
  1625. }
  1626. /// Allowlist for the path APIs.
  1627. #[derive(Debug, Default, PartialEq, Eq, Clone, Deserialize, Serialize)]
  1628. #[cfg_attr(feature = "schema", derive(JsonSchema))]
  1629. #[serde(rename_all = "camelCase", deny_unknown_fields)]
  1630. pub struct PathAllowlistConfig {
  1631. /// Use this flag to enable all path API features.
  1632. #[serde(default)]
  1633. pub all: bool,
  1634. }
  1635. impl Allowlist for PathAllowlistConfig {
  1636. fn all_features() -> Vec<&'static str> {
  1637. let allowlist = Self { all: false };
  1638. let mut features = allowlist.to_features();
  1639. features.push("path-all");
  1640. features
  1641. }
  1642. fn to_features(&self) -> Vec<&'static str> {
  1643. if self.all {
  1644. vec!["path-all"]
  1645. } else {
  1646. vec![]
  1647. }
  1648. }
  1649. }
  1650. /// Allowlist for the custom protocols.
  1651. #[derive(Debug, Default, PartialEq, Eq, Clone, Deserialize, Serialize)]
  1652. #[cfg_attr(feature = "schema", derive(JsonSchema))]
  1653. #[serde(rename_all = "camelCase", deny_unknown_fields)]
  1654. pub struct ProtocolAllowlistConfig {
  1655. /// The access scope for the asset protocol.
  1656. #[serde(default)]
  1657. pub asset_scope: FsAllowlistScope,
  1658. /// Use this flag to enable all custom protocols.
  1659. #[serde(default)]
  1660. pub all: bool,
  1661. /// Enables the asset protocol.
  1662. #[serde(default)]
  1663. pub asset: bool,
  1664. }
  1665. impl Allowlist for ProtocolAllowlistConfig {
  1666. fn all_features() -> Vec<&'static str> {
  1667. let allowlist = Self {
  1668. asset_scope: Default::default(),
  1669. all: false,
  1670. asset: true,
  1671. };
  1672. let mut features = allowlist.to_features();
  1673. features.push("protocol-all");
  1674. features
  1675. }
  1676. fn to_features(&self) -> Vec<&'static str> {
  1677. if self.all {
  1678. vec!["protocol-all"]
  1679. } else {
  1680. let mut features = Vec::new();
  1681. check_feature!(self, features, asset, "protocol-asset");
  1682. features
  1683. }
  1684. }
  1685. }
  1686. /// Allowlist for the process APIs.
  1687. #[derive(Debug, Default, PartialEq, Eq, Clone, Deserialize, Serialize)]
  1688. #[cfg_attr(feature = "schema", derive(JsonSchema))]
  1689. #[serde(rename_all = "camelCase", deny_unknown_fields)]
  1690. pub struct ProcessAllowlistConfig {
  1691. /// Use this flag to enable all process APIs.
  1692. #[serde(default)]
  1693. pub all: bool,
  1694. /// Enables the relaunch API.
  1695. #[serde(default)]
  1696. pub relaunch: bool,
  1697. /// Dangerous option that allows macOS to relaunch even if the binary contains a symlink.
  1698. ///
  1699. /// This is due to macOS having less symlink protection. Highly recommended to not set this flag
  1700. /// unless you have a very specific reason too, and understand the implications of it.
  1701. #[serde(default)]
  1702. pub relaunch_dangerous_allow_symlink_macos: bool,
  1703. /// Enables the exit API.
  1704. #[serde(default)]
  1705. pub exit: bool,
  1706. }
  1707. impl Allowlist for ProcessAllowlistConfig {
  1708. fn all_features() -> Vec<&'static str> {
  1709. let allowlist = Self {
  1710. all: false,
  1711. relaunch: true,
  1712. relaunch_dangerous_allow_symlink_macos: false,
  1713. exit: true,
  1714. };
  1715. let mut features = allowlist.to_features();
  1716. features.push("process-all");
  1717. features
  1718. }
  1719. fn to_features(&self) -> Vec<&'static str> {
  1720. if self.all {
  1721. vec!["process-all"]
  1722. } else {
  1723. let mut features = Vec::new();
  1724. check_feature!(self, features, relaunch, "process-relaunch");
  1725. check_feature!(
  1726. self,
  1727. features,
  1728. relaunch_dangerous_allow_symlink_macos,
  1729. "process-relaunch-dangerous-allow-symlink-macos"
  1730. );
  1731. check_feature!(self, features, exit, "process-exit");
  1732. features
  1733. }
  1734. }
  1735. }
  1736. /// Allowlist for the clipboard APIs.
  1737. #[derive(Debug, Default, PartialEq, Eq, Clone, Deserialize, Serialize)]
  1738. #[cfg_attr(feature = "schema", derive(JsonSchema))]
  1739. #[serde(rename_all = "camelCase", deny_unknown_fields)]
  1740. pub struct ClipboardAllowlistConfig {
  1741. /// Use this flag to enable all clipboard APIs.
  1742. #[serde(default)]
  1743. pub all: bool,
  1744. /// Enables the clipboard's `writeText` API.
  1745. #[serde(default)]
  1746. pub write_text: bool,
  1747. /// Enables the clipboard's `readText` API.
  1748. #[serde(default)]
  1749. pub read_text: bool,
  1750. }
  1751. impl Allowlist for ClipboardAllowlistConfig {
  1752. fn all_features() -> Vec<&'static str> {
  1753. let allowlist = Self {
  1754. all: false,
  1755. write_text: true,
  1756. read_text: true,
  1757. };
  1758. let mut features = allowlist.to_features();
  1759. features.push("clipboard-all");
  1760. features
  1761. }
  1762. fn to_features(&self) -> Vec<&'static str> {
  1763. if self.all {
  1764. vec!["clipboard-all"]
  1765. } else {
  1766. let mut features = Vec::new();
  1767. check_feature!(self, features, write_text, "clipboard-write-text");
  1768. check_feature!(self, features, read_text, "clipboard-read-text");
  1769. features
  1770. }
  1771. }
  1772. }
  1773. /// Allowlist configuration.
  1774. #[derive(Debug, Default, PartialEq, Eq, Clone, Deserialize, Serialize)]
  1775. #[cfg_attr(feature = "schema", derive(JsonSchema))]
  1776. #[serde(rename_all = "camelCase", deny_unknown_fields)]
  1777. pub struct AllowlistConfig {
  1778. /// Use this flag to enable all API features.
  1779. #[serde(default)]
  1780. pub all: bool,
  1781. /// File system API allowlist.
  1782. #[serde(default)]
  1783. pub fs: FsAllowlistConfig,
  1784. /// Window API allowlist.
  1785. #[serde(default)]
  1786. pub window: WindowAllowlistConfig,
  1787. /// Shell API allowlist.
  1788. #[serde(default)]
  1789. pub shell: ShellAllowlistConfig,
  1790. /// Dialog API allowlist.
  1791. #[serde(default)]
  1792. pub dialog: DialogAllowlistConfig,
  1793. /// HTTP API allowlist.
  1794. #[serde(default)]
  1795. pub http: HttpAllowlistConfig,
  1796. /// Notification API allowlist.
  1797. #[serde(default)]
  1798. pub notification: NotificationAllowlistConfig,
  1799. /// Global shortcut API allowlist.
  1800. #[serde(default)]
  1801. pub global_shortcut: GlobalShortcutAllowlistConfig,
  1802. /// OS allowlist.
  1803. #[serde(default)]
  1804. pub os: OsAllowlistConfig,
  1805. /// Path API allowlist.
  1806. #[serde(default)]
  1807. pub path: PathAllowlistConfig,
  1808. /// Custom protocol allowlist.
  1809. #[serde(default)]
  1810. pub protocol: ProtocolAllowlistConfig,
  1811. /// Process API allowlist.
  1812. #[serde(default)]
  1813. pub process: ProcessAllowlistConfig,
  1814. /// Clipboard APIs allowlist.
  1815. #[serde(default)]
  1816. pub clipboard: ClipboardAllowlistConfig,
  1817. }
  1818. impl Allowlist for AllowlistConfig {
  1819. fn all_features() -> Vec<&'static str> {
  1820. let mut features = vec!["api-all"];
  1821. features.extend(FsAllowlistConfig::all_features());
  1822. features.extend(WindowAllowlistConfig::all_features());
  1823. features.extend(ShellAllowlistConfig::all_features());
  1824. features.extend(DialogAllowlistConfig::all_features());
  1825. features.extend(HttpAllowlistConfig::all_features());
  1826. features.extend(NotificationAllowlistConfig::all_features());
  1827. features.extend(GlobalShortcutAllowlistConfig::all_features());
  1828. features.extend(OsAllowlistConfig::all_features());
  1829. features.extend(PathAllowlistConfig::all_features());
  1830. features.extend(ProtocolAllowlistConfig::all_features());
  1831. features.extend(ProcessAllowlistConfig::all_features());
  1832. features.extend(ClipboardAllowlistConfig::all_features());
  1833. features
  1834. }
  1835. fn to_features(&self) -> Vec<&'static str> {
  1836. if self.all {
  1837. vec!["api-all"]
  1838. } else {
  1839. let mut features = Vec::new();
  1840. features.extend(self.fs.to_features());
  1841. features.extend(self.window.to_features());
  1842. features.extend(self.shell.to_features());
  1843. features.extend(self.dialog.to_features());
  1844. features.extend(self.http.to_features());
  1845. features.extend(self.notification.to_features());
  1846. features.extend(self.global_shortcut.to_features());
  1847. features.extend(self.os.to_features());
  1848. features.extend(self.path.to_features());
  1849. features.extend(self.protocol.to_features());
  1850. features.extend(self.process.to_features());
  1851. features.extend(self.clipboard.to_features());
  1852. features
  1853. }
  1854. }
  1855. }
  1856. /// The application pattern.
  1857. #[skip_serializing_none]
  1858. #[derive(Debug, PartialEq, Eq, Clone, Serialize, Deserialize)]
  1859. #[serde(rename_all = "lowercase", tag = "use", content = "options")]
  1860. #[cfg_attr(feature = "schema", derive(JsonSchema))]
  1861. pub enum PatternKind {
  1862. /// Brownfield pattern.
  1863. Brownfield,
  1864. /// Isolation pattern. Recommended for security purposes.
  1865. #[cfg(feature = "isolation")]
  1866. Isolation {
  1867. /// The dir containing the index.html file that contains the secure isolation application.
  1868. dir: PathBuf,
  1869. },
  1870. }
  1871. impl Default for PatternKind {
  1872. fn default() -> Self {
  1873. Self::Brownfield
  1874. }
  1875. }
  1876. /// The Tauri configuration object.
  1877. #[skip_serializing_none]
  1878. #[derive(Debug, Default, PartialEq, Clone, Deserialize, Serialize)]
  1879. #[cfg_attr(feature = "schema", derive(JsonSchema))]
  1880. #[serde(rename_all = "camelCase", deny_unknown_fields)]
  1881. pub struct TauriConfig {
  1882. /// The pattern to use.
  1883. #[serde(default)]
  1884. pub pattern: PatternKind,
  1885. /// The windows configuration.
  1886. #[serde(default)]
  1887. pub windows: Vec<WindowConfig>,
  1888. /// The CLI configuration.
  1889. pub cli: Option<CliConfig>,
  1890. /// The bundler configuration.
  1891. #[serde(default)]
  1892. pub bundle: BundleConfig,
  1893. /// The allowlist configuration.
  1894. #[serde(default)]
  1895. pub allowlist: AllowlistConfig,
  1896. /// Security configuration.
  1897. #[serde(default)]
  1898. pub security: SecurityConfig,
  1899. /// The updater configuration.
  1900. #[serde(default)]
  1901. pub updater: UpdaterConfig,
  1902. /// Configuration for app system tray.
  1903. pub system_tray: Option<SystemTrayConfig>,
  1904. /// MacOS private API configuration. Enables the transparent background API and sets the `fullScreenEnabled` preference to `true`.
  1905. #[serde(rename = "macOSPrivateApi", default)]
  1906. pub macos_private_api: bool,
  1907. }
  1908. impl TauriConfig {
  1909. /// Returns all Cargo features.
  1910. #[allow(dead_code)]
  1911. pub fn all_features() -> Vec<&'static str> {
  1912. let mut features = AllowlistConfig::all_features();
  1913. features.extend(vec![
  1914. "cli",
  1915. "updater",
  1916. "system-tray",
  1917. "macos-private-api",
  1918. "isolation",
  1919. ]);
  1920. features
  1921. }
  1922. /// Returns the enabled Cargo features.
  1923. #[allow(dead_code)]
  1924. pub fn features(&self) -> Vec<&str> {
  1925. let mut features = self.allowlist.to_features();
  1926. if self.cli.is_some() {
  1927. features.push("cli");
  1928. }
  1929. if self.updater.active {
  1930. features.push("updater");
  1931. }
  1932. if self.system_tray.is_some() {
  1933. features.push("system-tray");
  1934. }
  1935. if self.macos_private_api {
  1936. features.push("macos-private-api");
  1937. }
  1938. #[cfg(feature = "isolation")]
  1939. if let PatternKind::Isolation { .. } = self.pattern {
  1940. features.push("isolation");
  1941. }
  1942. features.sort_unstable();
  1943. features
  1944. }
  1945. }
  1946. /// A URL to an updater server.
  1947. ///
  1948. /// The URL must use the `https` scheme on production.
  1949. #[skip_serializing_none]
  1950. #[derive(Debug, PartialEq, Eq, Clone, Serialize)]
  1951. #[cfg_attr(feature = "schema", derive(JsonSchema))]
  1952. pub struct UpdaterEndpoint(pub Url);
  1953. impl std::fmt::Display for UpdaterEndpoint {
  1954. fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
  1955. write!(f, "{}", self.0)
  1956. }
  1957. }
  1958. impl<'de> Deserialize<'de> for UpdaterEndpoint {
  1959. fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
  1960. where
  1961. D: Deserializer<'de>,
  1962. {
  1963. let url = Url::deserialize(deserializer)?;
  1964. #[cfg(all(not(debug_assertions), not(feature = "schema")))]
  1965. {
  1966. if url.scheme() != "https" {
  1967. return Err(serde::de::Error::custom(
  1968. "The configured updater endpoint must use the `https` protocol.",
  1969. ));
  1970. }
  1971. }
  1972. Ok(Self(url))
  1973. }
  1974. }
  1975. /// Install modes for the Windows update.
  1976. #[derive(Debug, PartialEq, Eq, Clone)]
  1977. #[cfg_attr(feature = "schema", derive(JsonSchema))]
  1978. #[cfg_attr(feature = "schema", schemars(rename_all = "camelCase"))]
  1979. pub enum WindowsUpdateInstallMode {
  1980. /// Specifies there's a basic UI during the installation process, including a final dialog box at the end.
  1981. BasicUi,
  1982. /// The quiet mode means there's no user interaction required.
  1983. /// Requires admin privileges if the installer does.
  1984. Quiet,
  1985. /// Specifies unattended mode, which means the installation only shows a progress bar.
  1986. Passive,
  1987. // to add more modes, we need to check if the updater relaunch makes sense
  1988. // i.e. for a full UI mode, the user can also mark the installer to start the app
  1989. }
  1990. impl WindowsUpdateInstallMode {
  1991. /// Returns the associated `msiexec.exe` arguments.
  1992. pub fn msiexec_args(&self) -> &'static [&'static str] {
  1993. match self {
  1994. Self::BasicUi => &["/qb+"],
  1995. Self::Quiet => &["/quiet"],
  1996. Self::Passive => &["/passive"],
  1997. }
  1998. }
  1999. }
  2000. impl Display for WindowsUpdateInstallMode {
  2001. fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
  2002. write!(
  2003. f,
  2004. "{}",
  2005. match self {
  2006. Self::BasicUi => "basicUI",
  2007. Self::Quiet => "quiet",
  2008. Self::Passive => "passive",
  2009. }
  2010. )
  2011. }
  2012. }
  2013. impl Default for WindowsUpdateInstallMode {
  2014. fn default() -> Self {
  2015. Self::Passive
  2016. }
  2017. }
  2018. impl Serialize for WindowsUpdateInstallMode {
  2019. fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
  2020. where
  2021. S: Serializer,
  2022. {
  2023. serializer.serialize_str(self.to_string().as_ref())
  2024. }
  2025. }
  2026. impl<'de> Deserialize<'de> for WindowsUpdateInstallMode {
  2027. fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
  2028. where
  2029. D: Deserializer<'de>,
  2030. {
  2031. let s = String::deserialize(deserializer)?;
  2032. match s.to_lowercase().as_str() {
  2033. "basicui" => Ok(Self::BasicUi),
  2034. "quiet" => Ok(Self::Quiet),
  2035. "passive" => Ok(Self::Passive),
  2036. _ => Err(DeError::custom(format!(
  2037. "unknown update install mode '{}'",
  2038. s
  2039. ))),
  2040. }
  2041. }
  2042. }
  2043. /// The updater configuration for Windows.
  2044. #[skip_serializing_none]
  2045. #[derive(Debug, Default, PartialEq, Eq, Clone, Serialize, Deserialize)]
  2046. #[cfg_attr(feature = "schema", derive(JsonSchema))]
  2047. #[serde(rename_all = "camelCase", deny_unknown_fields)]
  2048. pub struct UpdaterWindowsConfig {
  2049. /// The installation mode for the update on Windows. Defaults to `passive`.
  2050. #[serde(default)]
  2051. pub install_mode: WindowsUpdateInstallMode,
  2052. }
  2053. /// The Updater configuration object.
  2054. #[skip_serializing_none]
  2055. #[derive(Debug, PartialEq, Eq, Clone, Serialize)]
  2056. #[cfg_attr(feature = "schema", derive(JsonSchema))]
  2057. #[serde(rename_all = "camelCase", deny_unknown_fields)]
  2058. pub struct UpdaterConfig {
  2059. /// Whether the updater is active or not.
  2060. #[serde(default)]
  2061. pub active: bool,
  2062. /// Display built-in dialog or use event system if disabled.
  2063. #[serde(default = "default_dialog")]
  2064. pub dialog: bool,
  2065. /// The updater endpoints. TLS is enforced on production.
  2066. ///
  2067. /// The updater URL can contain the following variables:
  2068. /// - {{current_version}}: The version of the app that is requesting the update
  2069. /// - {{target}}: The operating system name (one of `linux`, `windows` or `darwin`).
  2070. /// - {{arch}}: The architecture of the machine (one of `x86_64`, `i686`, `aarch64` or `armv7`).
  2071. ///
  2072. /// # Examples
  2073. /// - "https://my.cdn.com/latest.json": a raw JSON endpoint that returns the latest version and download links for each platform.
  2074. /// - "https://updates.app.dev/{{target}}?version={{current_version}}&arch={{arch}}": a dedicated API with positional and query string arguments.
  2075. #[allow(rustdoc::bare_urls)]
  2076. pub endpoints: Option<Vec<UpdaterEndpoint>>,
  2077. /// Signature public key.
  2078. #[serde(default)] // use default just so the schema doesn't flag it as required
  2079. pub pubkey: String,
  2080. /// The Windows configuration for the updater.
  2081. #[serde(default)]
  2082. pub windows: UpdaterWindowsConfig,
  2083. }
  2084. impl<'de> Deserialize<'de> for UpdaterConfig {
  2085. fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
  2086. where
  2087. D: Deserializer<'de>,
  2088. {
  2089. #[derive(Deserialize)]
  2090. struct InnerUpdaterConfig {
  2091. #[serde(default)]
  2092. active: bool,
  2093. #[serde(default = "default_dialog")]
  2094. dialog: bool,
  2095. endpoints: Option<Vec<UpdaterEndpoint>>,
  2096. pubkey: Option<String>,
  2097. #[serde(default)]
  2098. windows: UpdaterWindowsConfig,
  2099. }
  2100. let config = InnerUpdaterConfig::deserialize(deserializer)?;
  2101. if config.active && config.pubkey.is_none() {
  2102. return Err(DeError::custom(
  2103. "The updater `pubkey` configuration is required.",
  2104. ));
  2105. }
  2106. Ok(UpdaterConfig {
  2107. active: config.active,
  2108. dialog: config.dialog,
  2109. endpoints: config.endpoints,
  2110. pubkey: config.pubkey.unwrap_or_default(),
  2111. windows: config.windows,
  2112. })
  2113. }
  2114. }
  2115. impl Default for UpdaterConfig {
  2116. fn default() -> Self {
  2117. Self {
  2118. active: false,
  2119. dialog: default_dialog(),
  2120. endpoints: None,
  2121. pubkey: "".into(),
  2122. windows: Default::default(),
  2123. }
  2124. }
  2125. }
  2126. /// Configuration for application system tray icon.
  2127. #[skip_serializing_none]
  2128. #[derive(Debug, Default, PartialEq, Eq, Clone, Deserialize, Serialize)]
  2129. #[cfg_attr(feature = "schema", derive(JsonSchema))]
  2130. #[serde(rename_all = "camelCase", deny_unknown_fields)]
  2131. pub struct SystemTrayConfig {
  2132. /// Path to the icon to use on the system tray.
  2133. ///
  2134. /// It is forced to be a `.png` file on Linux and macOS, and a `.ico` file on Windows.
  2135. pub icon_path: PathBuf,
  2136. /// 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.
  2137. #[serde(default)]
  2138. pub icon_as_template: bool,
  2139. /// A Boolean value that determines whether the menu should appear when the tray icon receives a left click on macOS.
  2140. #[serde(default = "default_tray_menu_on_left_click")]
  2141. pub menu_on_left_click: bool,
  2142. }
  2143. fn default_tray_menu_on_left_click() -> bool {
  2144. true
  2145. }
  2146. // We enable the unnecessary_wraps because we need
  2147. // to use an Option for dialog otherwise the CLI schema will mark
  2148. // the dialog as a required field which is not as we default it to true.
  2149. fn default_dialog() -> bool {
  2150. true
  2151. }
  2152. /// Defines the URL or assets to embed in the application.
  2153. #[derive(Debug, PartialEq, Eq, Clone, Deserialize, Serialize)]
  2154. #[cfg_attr(feature = "schema", derive(JsonSchema))]
  2155. #[serde(untagged, deny_unknown_fields)]
  2156. #[non_exhaustive]
  2157. pub enum AppUrl {
  2158. /// The app's external URL, or the path to the directory containing the app assets.
  2159. Url(WindowUrl),
  2160. /// An array of files to embed on the app.
  2161. Files(Vec<PathBuf>),
  2162. }
  2163. impl std::fmt::Display for AppUrl {
  2164. fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
  2165. match self {
  2166. Self::Url(url) => write!(f, "{}", url),
  2167. Self::Files(files) => write!(f, "{}", serde_json::to_string(files).unwrap()),
  2168. }
  2169. }
  2170. }
  2171. /// The Build configuration object.
  2172. #[skip_serializing_none]
  2173. #[derive(Debug, PartialEq, Eq, Clone, Deserialize, Serialize)]
  2174. #[cfg_attr(feature = "schema", derive(JsonSchema))]
  2175. #[serde(rename_all = "camelCase", deny_unknown_fields)]
  2176. pub struct BuildConfig {
  2177. /// The binary used to build and run the application.
  2178. pub runner: Option<String>,
  2179. /// The path to the application assets or URL to load in development.
  2180. ///
  2181. /// This is usually an URL to a dev server, which serves your application assets
  2182. /// with live reloading. Most modern JavaScript bundlers provides a way to start a dev server by default.
  2183. ///
  2184. /// See [vite](https://vitejs.dev/guide/), [Webpack DevServer](https://webpack.js.org/configuration/dev-server/) and [sirv](https://github.com/lukeed/sirv)
  2185. /// for examples on how to set up a dev server.
  2186. #[serde(default = "default_dev_path")]
  2187. pub dev_path: AppUrl,
  2188. /// The path to the application assets or URL to load in production.
  2189. ///
  2190. /// When a path relative to the configuration file is provided,
  2191. /// it is read recursively and all files are embedded in the application binary.
  2192. /// Tauri then looks for an `index.html` file unless you provide a custom window URL.
  2193. ///
  2194. /// You can also provide a list of paths to be embedded, which allows granular control over what files are added to the binary.
  2195. /// In this case, all files are added to the root and you must reference it that way in your HTML files.
  2196. ///
  2197. /// When an URL is provided, the application won't have bundled assets
  2198. /// and the application will load that URL by default.
  2199. #[serde(default = "default_dist_dir")]
  2200. pub dist_dir: AppUrl,
  2201. /// A shell command to run before `tauri dev` kicks in.
  2202. ///
  2203. /// The TAURI_PLATFORM, TAURI_ARCH, TAURI_FAMILY, TAURI_PLATFORM_VERSION, TAURI_PLATFORM_TYPE and TAURI_DEBUG environment variables are set if you perform conditional compilation.
  2204. pub before_dev_command: Option<String>,
  2205. /// A shell command to run before `tauri build` kicks in.
  2206. ///
  2207. /// The TAURI_PLATFORM, TAURI_ARCH, TAURI_FAMILY, TAURI_PLATFORM_VERSION, TAURI_PLATFORM_TYPE and TAURI_DEBUG environment variables are set if you perform conditional compilation.
  2208. pub before_build_command: Option<String>,
  2209. /// Features passed to `cargo` commands.
  2210. pub features: Option<Vec<String>>,
  2211. /// Whether we should inject the Tauri API on `window.__TAURI__` or not.
  2212. #[serde(default)]
  2213. pub with_global_tauri: bool,
  2214. }
  2215. impl Default for BuildConfig {
  2216. fn default() -> Self {
  2217. Self {
  2218. runner: None,
  2219. dev_path: default_dev_path(),
  2220. dist_dir: default_dist_dir(),
  2221. before_dev_command: None,
  2222. before_build_command: None,
  2223. features: None,
  2224. with_global_tauri: false,
  2225. }
  2226. }
  2227. }
  2228. fn default_dev_path() -> AppUrl {
  2229. AppUrl::Url(WindowUrl::External(
  2230. Url::parse("http://localhost:8080").unwrap(),
  2231. ))
  2232. }
  2233. fn default_dist_dir() -> AppUrl {
  2234. AppUrl::Url(WindowUrl::App("../dist".into()))
  2235. }
  2236. #[derive(Debug, PartialEq, Eq)]
  2237. struct PackageVersion(String);
  2238. impl<'d> serde::Deserialize<'d> for PackageVersion {
  2239. fn deserialize<D: Deserializer<'d>>(deserializer: D) -> Result<PackageVersion, D::Error> {
  2240. struct PackageVersionVisitor;
  2241. impl<'d> Visitor<'d> for PackageVersionVisitor {
  2242. type Value = PackageVersion;
  2243. fn expecting(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
  2244. write!(
  2245. formatter,
  2246. "a semver string or a path to a package.json file"
  2247. )
  2248. }
  2249. fn visit_str<E: DeError>(self, value: &str) -> Result<PackageVersion, E> {
  2250. let path = PathBuf::from(value);
  2251. if path.exists() {
  2252. let json_str = read_to_string(&path)
  2253. .map_err(|e| DeError::custom(format!("failed to read version JSON file: {}", e)))?;
  2254. let package_json: serde_json::Value = serde_json::from_str(&json_str)
  2255. .map_err(|e| DeError::custom(format!("failed to read version JSON file: {}", e)))?;
  2256. if let Some(obj) = package_json.as_object() {
  2257. let version = obj
  2258. .get("version")
  2259. .ok_or_else(|| DeError::custom("JSON must contain a `version` field"))?
  2260. .as_str()
  2261. .ok_or_else(|| {
  2262. DeError::custom(format!("`{} > version` must be a string", path.display()))
  2263. })?;
  2264. Ok(PackageVersion(
  2265. Version::from_str(version)
  2266. .map_err(|_| DeError::custom("`package > version` must be a semver string"))?
  2267. .to_string(),
  2268. ))
  2269. } else {
  2270. Err(DeError::custom(
  2271. "`package > version` value is not a path to a JSON object",
  2272. ))
  2273. }
  2274. } else {
  2275. Ok(PackageVersion(
  2276. Version::from_str(value)
  2277. .map_err(|_| DeError::custom("`package > version` must be a semver string"))?
  2278. .to_string(),
  2279. ))
  2280. }
  2281. }
  2282. }
  2283. deserializer.deserialize_string(PackageVersionVisitor {})
  2284. }
  2285. }
  2286. /// The package configuration.
  2287. #[derive(Debug, Clone, Default, PartialEq, Eq, Deserialize, Serialize)]
  2288. #[cfg_attr(feature = "schema", derive(JsonSchema))]
  2289. #[serde(rename_all = "camelCase", deny_unknown_fields)]
  2290. pub struct PackageConfig {
  2291. /// App name.
  2292. pub product_name: Option<String>,
  2293. /// App version. It is a semver version number or a path to a `package.json` file contaning the `version` field.
  2294. #[serde(deserialize_with = "version_deserializer", default)]
  2295. pub version: Option<String>,
  2296. }
  2297. fn version_deserializer<'de, D>(deserializer: D) -> Result<Option<String>, D::Error>
  2298. where
  2299. D: Deserializer<'de>,
  2300. {
  2301. Option::<PackageVersion>::deserialize(deserializer).map(|v| v.map(|v| v.0))
  2302. }
  2303. impl PackageConfig {
  2304. /// The binary name.
  2305. #[allow(dead_code)]
  2306. pub fn binary_name(&self) -> Option<String> {
  2307. #[cfg(target_os = "linux")]
  2308. {
  2309. self.product_name.as_ref().map(|n| n.to_kebab_case())
  2310. }
  2311. #[cfg(not(target_os = "linux"))]
  2312. {
  2313. self.product_name.clone()
  2314. }
  2315. }
  2316. }
  2317. /// The tauri.conf.json is a file generated by the
  2318. /// [`tauri init`](https://tauri.app/v1/api/cli#init) command that lives in
  2319. /// your Tauri application source directory (src-tauri).
  2320. ///
  2321. /// Once generated, you may modify it at will to customize your Tauri application.
  2322. ///
  2323. /// ## Platform-Specific Configuration
  2324. ///
  2325. /// In addition to the JSON defined on the `tauri.conf.json` file, Tauri can
  2326. /// read a platform-specific configuration from `tauri.linux.conf.json`,
  2327. /// `tauri.windows.conf.json`, and `tauri.macos.conf.json` and merges it with
  2328. /// the main `tauri.conf.json` configuration.
  2329. ///
  2330. /// ## Configuration Structure
  2331. ///
  2332. /// `tauri.conf.json` is composed of the following objects:
  2333. ///
  2334. /// - [`package`](#packageconfig): Package settings
  2335. /// - [`tauri`](#tauriconfig): The Tauri config
  2336. /// - [`build`](#buildconfig): The build configuration
  2337. /// - [`plugins`](#pluginconfig): The plugins config
  2338. ///
  2339. /// ```json title="Example tauri.config.json file"
  2340. /// {
  2341. /// "build": {
  2342. /// "beforeBuildCommand": "",
  2343. /// "beforeDevCommand": "",
  2344. /// "devPath": "../dist",
  2345. /// "distDir": "../dist"
  2346. /// },
  2347. /// "package": {
  2348. /// "productName": "tauri-app",
  2349. /// "version": "0.1.0"
  2350. /// },
  2351. /// "tauri": {
  2352. /// "allowlist": {
  2353. /// "all": true
  2354. /// },
  2355. /// "bundle": {},
  2356. /// "security": {
  2357. /// "csp": null
  2358. /// },
  2359. /// "updater": {
  2360. /// "active": false
  2361. /// },
  2362. /// "windows": [
  2363. /// {
  2364. /// "fullscreen": false,
  2365. /// "height": 600,
  2366. /// "resizable": true,
  2367. /// "title": "Tauri App",
  2368. /// "width": 800
  2369. /// }
  2370. /// ]
  2371. /// }
  2372. /// }
  2373. /// ```
  2374. #[skip_serializing_none]
  2375. #[derive(Debug, Default, PartialEq, Clone, Deserialize, Serialize)]
  2376. #[cfg_attr(feature = "schema", derive(JsonSchema))]
  2377. #[serde(rename_all = "camelCase", deny_unknown_fields)]
  2378. pub struct Config {
  2379. /// The JSON schema for the Tauri config.
  2380. #[serde(rename = "$schema")]
  2381. pub schema: Option<String>,
  2382. /// Package settings.
  2383. #[serde(default)]
  2384. pub package: PackageConfig,
  2385. /// The Tauri configuration.
  2386. #[serde(default)]
  2387. pub tauri: TauriConfig,
  2388. /// The build configuration.
  2389. #[serde(default = "default_build")]
  2390. pub build: BuildConfig,
  2391. /// The plugins config.
  2392. #[serde(default)]
  2393. pub plugins: PluginConfig,
  2394. }
  2395. /// The plugin configs holds a HashMap mapping a plugin name to its configuration object.
  2396. #[derive(Debug, Clone, Default, PartialEq, Eq, Deserialize, Serialize)]
  2397. #[cfg_attr(feature = "schema", derive(JsonSchema))]
  2398. pub struct PluginConfig(pub HashMap<String, JsonValue>);
  2399. fn default_build() -> BuildConfig {
  2400. BuildConfig {
  2401. runner: None,
  2402. dev_path: default_dev_path(),
  2403. dist_dir: default_dist_dir(),
  2404. before_dev_command: None,
  2405. before_build_command: None,
  2406. features: None,
  2407. with_global_tauri: false,
  2408. }
  2409. }
  2410. /// Implement `ToTokens` for all config structs, allowing a literal `Config` to be built.
  2411. ///
  2412. /// This allows for a build script to output the values in a `Config` to a `TokenStream`, which can
  2413. /// then be consumed by another crate. Useful for passing a config to both the build script and the
  2414. /// application using tauri while only parsing it once (in the build script).
  2415. #[cfg(feature = "build")]
  2416. mod build {
  2417. use std::{convert::identity, path::Path};
  2418. use proc_macro2::TokenStream;
  2419. use quote::{quote, ToTokens, TokenStreamExt};
  2420. use super::*;
  2421. use serde_json::Value as JsonValue;
  2422. /// Create a `String` constructor `TokenStream`.
  2423. ///
  2424. /// e.g. `"Hello World" -> String::from("Hello World").
  2425. /// This takes a `&String` to reduce casting all the `&String` -> `&str` manually.
  2426. fn str_lit(s: impl AsRef<str>) -> TokenStream {
  2427. let s = s.as_ref();
  2428. quote! { #s.into() }
  2429. }
  2430. /// Create an `Option` constructor `TokenStream`.
  2431. fn opt_lit(item: Option<&impl ToTokens>) -> TokenStream {
  2432. match item {
  2433. None => quote! { ::core::option::Option::None },
  2434. Some(item) => quote! { ::core::option::Option::Some(#item) },
  2435. }
  2436. }
  2437. /// Helper function to combine an `opt_lit` with `str_lit`.
  2438. fn opt_str_lit(item: Option<impl AsRef<str>>) -> TokenStream {
  2439. opt_lit(item.map(str_lit).as_ref())
  2440. }
  2441. /// Helper function to combine an `opt_lit` with a list of `str_lit`
  2442. fn opt_vec_str_lit(item: Option<impl IntoIterator<Item = impl AsRef<str>>>) -> TokenStream {
  2443. opt_lit(item.map(|list| vec_lit(list, str_lit)).as_ref())
  2444. }
  2445. /// Create a `Vec` constructor, mapping items with a function that spits out `TokenStream`s.
  2446. fn vec_lit<Raw, Tokens>(
  2447. list: impl IntoIterator<Item = Raw>,
  2448. map: impl Fn(Raw) -> Tokens,
  2449. ) -> TokenStream
  2450. where
  2451. Tokens: ToTokens,
  2452. {
  2453. let items = list.into_iter().map(map);
  2454. quote! { vec![#(#items),*] }
  2455. }
  2456. /// Create a `PathBuf` constructor `TokenStream`.
  2457. ///
  2458. /// e.g. `"Hello World" -> String::from("Hello World").
  2459. fn path_buf_lit(s: impl AsRef<Path>) -> TokenStream {
  2460. let s = s.as_ref().to_string_lossy().into_owned();
  2461. quote! { ::std::path::PathBuf::from(#s) }
  2462. }
  2463. /// Creates a `Url` constructor `TokenStream`.
  2464. fn url_lit(url: &Url) -> TokenStream {
  2465. let url = url.as_str();
  2466. quote! { #url.parse().unwrap() }
  2467. }
  2468. /// Create a map constructor, mapping keys and values with other `TokenStream`s.
  2469. ///
  2470. /// This function is pretty generic because the types of keys AND values get transformed.
  2471. fn map_lit<Map, Key, Value, TokenStreamKey, TokenStreamValue, FuncKey, FuncValue>(
  2472. map_type: TokenStream,
  2473. map: Map,
  2474. map_key: FuncKey,
  2475. map_value: FuncValue,
  2476. ) -> TokenStream
  2477. where
  2478. <Map as IntoIterator>::IntoIter: ExactSizeIterator,
  2479. Map: IntoIterator<Item = (Key, Value)>,
  2480. TokenStreamKey: ToTokens,
  2481. TokenStreamValue: ToTokens,
  2482. FuncKey: Fn(Key) -> TokenStreamKey,
  2483. FuncValue: Fn(Value) -> TokenStreamValue,
  2484. {
  2485. let ident = quote::format_ident!("map");
  2486. let map = map.into_iter();
  2487. if map.len() > 0 {
  2488. let items = map.map(|(key, value)| {
  2489. let key = map_key(key);
  2490. let value = map_value(value);
  2491. quote! { #ident.insert(#key, #value); }
  2492. });
  2493. quote! {{
  2494. let mut #ident = #map_type::new();
  2495. #(#items)*
  2496. #ident
  2497. }}
  2498. } else {
  2499. quote! { #map_type::new() }
  2500. }
  2501. }
  2502. /// Create a `serde_json::Value` variant `TokenStream` for a number
  2503. fn json_value_number_lit(num: &serde_json::Number) -> TokenStream {
  2504. // See https://docs.rs/serde_json/1/serde_json/struct.Number.html for guarantees
  2505. let prefix = quote! { ::serde_json::Value };
  2506. if num.is_u64() {
  2507. // guaranteed u64
  2508. let num = num.as_u64().unwrap();
  2509. quote! { #prefix::Number(#num.into()) }
  2510. } else if num.is_i64() {
  2511. // guaranteed i64
  2512. let num = num.as_i64().unwrap();
  2513. quote! { #prefix::Number(#num.into()) }
  2514. } else if num.is_f64() {
  2515. // guaranteed f64
  2516. let num = num.as_f64().unwrap();
  2517. quote! { #prefix::Number(#num.into()) }
  2518. } else {
  2519. // invalid number
  2520. quote! { #prefix::Null }
  2521. }
  2522. }
  2523. /// Create a `serde_json::Value` constructor `TokenStream`
  2524. fn json_value_lit(jv: &JsonValue) -> TokenStream {
  2525. let prefix = quote! { ::serde_json::Value };
  2526. match jv {
  2527. JsonValue::Null => quote! { #prefix::Null },
  2528. JsonValue::Bool(bool) => quote! { #prefix::Bool(#bool) },
  2529. JsonValue::Number(number) => json_value_number_lit(number),
  2530. JsonValue::String(str) => {
  2531. let s = str_lit(str);
  2532. quote! { #prefix::String(#s) }
  2533. }
  2534. JsonValue::Array(vec) => {
  2535. let items = vec.iter().map(json_value_lit);
  2536. quote! { #prefix::Array(vec![#(#items),*]) }
  2537. }
  2538. JsonValue::Object(map) => {
  2539. let map = map_lit(quote! { ::serde_json::Map }, map, str_lit, json_value_lit);
  2540. quote! { #prefix::Object(#map) }
  2541. }
  2542. }
  2543. }
  2544. /// Write a `TokenStream` of the `$struct`'s fields to the `$tokens`.
  2545. ///
  2546. /// All fields must represent a binding of the same name that implements `ToTokens`.
  2547. macro_rules! literal_struct {
  2548. ($tokens:ident, $struct:ident, $($field:ident),+) => {
  2549. $tokens.append_all(quote! {
  2550. ::tauri::utils::config::$struct {
  2551. $($field: #$field),+
  2552. }
  2553. });
  2554. };
  2555. }
  2556. impl ToTokens for WindowUrl {
  2557. fn to_tokens(&self, tokens: &mut TokenStream) {
  2558. let prefix = quote! { ::tauri::utils::config::WindowUrl };
  2559. tokens.append_all(match self {
  2560. Self::App(path) => {
  2561. let path = path_buf_lit(&path);
  2562. quote! { #prefix::App(#path) }
  2563. }
  2564. Self::External(url) => {
  2565. let url = url_lit(url);
  2566. quote! { #prefix::External(#url) }
  2567. }
  2568. })
  2569. }
  2570. }
  2571. impl ToTokens for crate::Theme {
  2572. fn to_tokens(&self, tokens: &mut TokenStream) {
  2573. let prefix = quote! { ::tauri::utils::Theme };
  2574. tokens.append_all(match self {
  2575. Self::Light => quote! { #prefix::Light },
  2576. Self::Dark => quote! { #prefix::Dark },
  2577. })
  2578. }
  2579. }
  2580. impl ToTokens for WindowConfig {
  2581. fn to_tokens(&self, tokens: &mut TokenStream) {
  2582. let label = str_lit(&self.label);
  2583. let url = &self.url;
  2584. let file_drop_enabled = self.file_drop_enabled;
  2585. let center = self.center;
  2586. let x = opt_lit(self.x.as_ref());
  2587. let y = opt_lit(self.y.as_ref());
  2588. let width = self.width;
  2589. let height = self.height;
  2590. let min_width = opt_lit(self.min_width.as_ref());
  2591. let min_height = opt_lit(self.min_height.as_ref());
  2592. let max_width = opt_lit(self.max_width.as_ref());
  2593. let max_height = opt_lit(self.max_height.as_ref());
  2594. let resizable = self.resizable;
  2595. let title = str_lit(&self.title);
  2596. let fullscreen = self.fullscreen;
  2597. let focus = self.focus;
  2598. let transparent = self.transparent;
  2599. let maximized = self.maximized;
  2600. let visible = self.visible;
  2601. let decorations = self.decorations;
  2602. let always_on_top = self.always_on_top;
  2603. let skip_taskbar = self.skip_taskbar;
  2604. let theme = opt_lit(self.theme.as_ref());
  2605. literal_struct!(
  2606. tokens,
  2607. WindowConfig,
  2608. label,
  2609. url,
  2610. file_drop_enabled,
  2611. center,
  2612. x,
  2613. y,
  2614. width,
  2615. height,
  2616. min_width,
  2617. min_height,
  2618. max_width,
  2619. max_height,
  2620. resizable,
  2621. title,
  2622. fullscreen,
  2623. focus,
  2624. transparent,
  2625. maximized,
  2626. visible,
  2627. decorations,
  2628. always_on_top,
  2629. skip_taskbar,
  2630. theme
  2631. );
  2632. }
  2633. }
  2634. impl ToTokens for CliArg {
  2635. fn to_tokens(&self, tokens: &mut TokenStream) {
  2636. let short = opt_lit(self.short.as_ref());
  2637. let name = str_lit(&self.name);
  2638. let description = opt_str_lit(self.description.as_ref());
  2639. let long_description = opt_str_lit(self.long_description.as_ref());
  2640. let takes_value = self.takes_value;
  2641. let multiple = self.multiple;
  2642. let multiple_occurrences = self.multiple_occurrences;
  2643. let number_of_values = opt_lit(self.number_of_values.as_ref());
  2644. let possible_values = opt_vec_str_lit(self.possible_values.as_ref());
  2645. let min_values = opt_lit(self.min_values.as_ref());
  2646. let max_values = opt_lit(self.max_values.as_ref());
  2647. let required = self.required;
  2648. let required_unless_present = opt_str_lit(self.required_unless_present.as_ref());
  2649. let required_unless_present_all = opt_vec_str_lit(self.required_unless_present_all.as_ref());
  2650. let required_unless_present_any = opt_vec_str_lit(self.required_unless_present_any.as_ref());
  2651. let conflicts_with = opt_str_lit(self.conflicts_with.as_ref());
  2652. let conflicts_with_all = opt_vec_str_lit(self.conflicts_with_all.as_ref());
  2653. let requires = opt_str_lit(self.requires.as_ref());
  2654. let requires_all = opt_vec_str_lit(self.requires_all.as_ref());
  2655. let requires_if = opt_vec_str_lit(self.requires_if.as_ref());
  2656. let required_if_eq = opt_vec_str_lit(self.required_if_eq.as_ref());
  2657. let require_equals = opt_lit(self.require_equals.as_ref());
  2658. let index = opt_lit(self.index.as_ref());
  2659. literal_struct!(
  2660. tokens,
  2661. CliArg,
  2662. short,
  2663. name,
  2664. description,
  2665. long_description,
  2666. takes_value,
  2667. multiple,
  2668. multiple_occurrences,
  2669. number_of_values,
  2670. possible_values,
  2671. min_values,
  2672. max_values,
  2673. required,
  2674. required_unless_present,
  2675. required_unless_present_all,
  2676. required_unless_present_any,
  2677. conflicts_with,
  2678. conflicts_with_all,
  2679. requires,
  2680. requires_all,
  2681. requires_if,
  2682. required_if_eq,
  2683. require_equals,
  2684. index
  2685. );
  2686. }
  2687. }
  2688. impl ToTokens for CliConfig {
  2689. fn to_tokens(&self, tokens: &mut TokenStream) {
  2690. let description = opt_str_lit(self.description.as_ref());
  2691. let long_description = opt_str_lit(self.long_description.as_ref());
  2692. let before_help = opt_str_lit(self.before_help.as_ref());
  2693. let after_help = opt_str_lit(self.after_help.as_ref());
  2694. let args = {
  2695. let args = self.args.as_ref().map(|args| {
  2696. let arg = args.iter().map(|a| quote! { #a });
  2697. quote! { vec![#(#arg),*] }
  2698. });
  2699. opt_lit(args.as_ref())
  2700. };
  2701. let subcommands = opt_lit(
  2702. self
  2703. .subcommands
  2704. .as_ref()
  2705. .map(|map| {
  2706. map_lit(
  2707. quote! { ::std::collections::HashMap },
  2708. map,
  2709. str_lit,
  2710. identity,
  2711. )
  2712. })
  2713. .as_ref(),
  2714. );
  2715. literal_struct!(
  2716. tokens,
  2717. CliConfig,
  2718. description,
  2719. long_description,
  2720. before_help,
  2721. after_help,
  2722. args,
  2723. subcommands
  2724. );
  2725. }
  2726. }
  2727. impl ToTokens for PatternKind {
  2728. fn to_tokens(&self, tokens: &mut TokenStream) {
  2729. let prefix = quote! { ::tauri::utils::config::PatternKind };
  2730. tokens.append_all(match self {
  2731. Self::Brownfield => quote! { #prefix::Brownfield },
  2732. #[cfg(feature = "isolation")]
  2733. Self::Isolation { dir } => {
  2734. let dir = path_buf_lit(dir);
  2735. quote! { #prefix::Isolation { dir: #dir } }
  2736. }
  2737. })
  2738. }
  2739. }
  2740. impl ToTokens for WebviewInstallMode {
  2741. fn to_tokens(&self, tokens: &mut TokenStream) {
  2742. let prefix = quote! { ::tauri::utils::config::WebviewInstallMode };
  2743. tokens.append_all(match self {
  2744. Self::Skip => quote! { #prefix::Skip },
  2745. Self::DownloadBootstrapper { silent } => {
  2746. quote! { #prefix::DownloadBootstrapper { silent: #silent } }
  2747. }
  2748. Self::EmbedBootstrapper { silent } => {
  2749. quote! { #prefix::EmbedBootstrapper { silent: #silent } }
  2750. }
  2751. Self::OfflineInstaller { silent } => {
  2752. quote! { #prefix::OfflineInstaller { silent: #silent } }
  2753. }
  2754. Self::FixedRuntime { path } => {
  2755. let path = path_buf_lit(&path);
  2756. quote! { #prefix::FixedRuntime { path: #path } }
  2757. }
  2758. })
  2759. }
  2760. }
  2761. impl ToTokens for WindowsConfig {
  2762. fn to_tokens(&self, tokens: &mut TokenStream) {
  2763. let webview_install_mode = if let Some(fixed_runtime_path) = &self.webview_fixed_runtime_path
  2764. {
  2765. WebviewInstallMode::FixedRuntime {
  2766. path: fixed_runtime_path.clone(),
  2767. }
  2768. } else {
  2769. self.webview_install_mode.clone()
  2770. };
  2771. tokens.append_all(quote! { ::tauri::utils::config::WindowsConfig {
  2772. webview_install_mode: #webview_install_mode,
  2773. ..Default::default()
  2774. }})
  2775. }
  2776. }
  2777. impl ToTokens for BundleConfig {
  2778. fn to_tokens(&self, tokens: &mut TokenStream) {
  2779. let identifier = str_lit(&self.identifier);
  2780. let icon = vec_lit(&self.icon, str_lit);
  2781. let active = self.active;
  2782. let targets = quote!(Default::default());
  2783. let resources = quote!(None);
  2784. let copyright = quote!(None);
  2785. let category = quote!(None);
  2786. let short_description = quote!(None);
  2787. let long_description = quote!(None);
  2788. let appimage = quote!(Default::default());
  2789. let deb = quote!(Default::default());
  2790. let macos = quote!(Default::default());
  2791. let external_bin = opt_vec_str_lit(self.external_bin.as_ref());
  2792. let windows = &self.windows;
  2793. literal_struct!(
  2794. tokens,
  2795. BundleConfig,
  2796. active,
  2797. identifier,
  2798. icon,
  2799. targets,
  2800. resources,
  2801. copyright,
  2802. category,
  2803. short_description,
  2804. long_description,
  2805. appimage,
  2806. deb,
  2807. macos,
  2808. external_bin,
  2809. windows
  2810. );
  2811. }
  2812. }
  2813. impl ToTokens for AppUrl {
  2814. fn to_tokens(&self, tokens: &mut TokenStream) {
  2815. let prefix = quote! { ::tauri::utils::config::AppUrl };
  2816. tokens.append_all(match self {
  2817. Self::Url(url) => {
  2818. quote! { #prefix::Url(#url) }
  2819. }
  2820. Self::Files(files) => {
  2821. let files = vec_lit(files, path_buf_lit);
  2822. quote! { #prefix::Files(#files) }
  2823. }
  2824. })
  2825. }
  2826. }
  2827. impl ToTokens for BuildConfig {
  2828. fn to_tokens(&self, tokens: &mut TokenStream) {
  2829. let dev_path = &self.dev_path;
  2830. let dist_dir = &self.dist_dir;
  2831. let with_global_tauri = self.with_global_tauri;
  2832. let runner = quote!(None);
  2833. let before_dev_command = quote!(None);
  2834. let before_build_command = quote!(None);
  2835. let features = quote!(None);
  2836. literal_struct!(
  2837. tokens,
  2838. BuildConfig,
  2839. runner,
  2840. dev_path,
  2841. dist_dir,
  2842. with_global_tauri,
  2843. before_dev_command,
  2844. before_build_command,
  2845. features
  2846. );
  2847. }
  2848. }
  2849. impl ToTokens for WindowsUpdateInstallMode {
  2850. fn to_tokens(&self, tokens: &mut TokenStream) {
  2851. let prefix = quote! { ::tauri::utils::config::WindowsUpdateInstallMode };
  2852. tokens.append_all(match self {
  2853. Self::BasicUi => quote! { #prefix::BasicUi },
  2854. Self::Quiet => quote! { #prefix::Quiet },
  2855. Self::Passive => quote! { #prefix::Passive },
  2856. })
  2857. }
  2858. }
  2859. impl ToTokens for UpdaterWindowsConfig {
  2860. fn to_tokens(&self, tokens: &mut TokenStream) {
  2861. let install_mode = &self.install_mode;
  2862. literal_struct!(tokens, UpdaterWindowsConfig, install_mode);
  2863. }
  2864. }
  2865. impl ToTokens for UpdaterConfig {
  2866. fn to_tokens(&self, tokens: &mut TokenStream) {
  2867. let active = self.active;
  2868. let dialog = self.dialog;
  2869. let pubkey = str_lit(&self.pubkey);
  2870. let endpoints = opt_lit(
  2871. self
  2872. .endpoints
  2873. .as_ref()
  2874. .map(|list| {
  2875. vec_lit(list, |url| {
  2876. let url = url.0.as_str();
  2877. quote! { ::tauri::utils::config::UpdaterEndpoint(#url.parse().unwrap()) }
  2878. })
  2879. })
  2880. .as_ref(),
  2881. );
  2882. let windows = &self.windows;
  2883. literal_struct!(
  2884. tokens,
  2885. UpdaterConfig,
  2886. active,
  2887. dialog,
  2888. pubkey,
  2889. endpoints,
  2890. windows
  2891. );
  2892. }
  2893. }
  2894. impl ToTokens for CspDirectiveSources {
  2895. fn to_tokens(&self, tokens: &mut TokenStream) {
  2896. let prefix = quote! { ::tauri::utils::config::CspDirectiveSources };
  2897. tokens.append_all(match self {
  2898. Self::Inline(sources) => {
  2899. let sources = sources.as_str();
  2900. quote!(#prefix::Inline(#sources.into()))
  2901. }
  2902. Self::List(list) => {
  2903. let list = vec_lit(list, str_lit);
  2904. quote!(#prefix::List(#list))
  2905. }
  2906. })
  2907. }
  2908. }
  2909. impl ToTokens for Csp {
  2910. fn to_tokens(&self, tokens: &mut TokenStream) {
  2911. let prefix = quote! { ::tauri::utils::config::Csp };
  2912. tokens.append_all(match self {
  2913. Self::Policy(policy) => {
  2914. let policy = policy.as_str();
  2915. quote!(#prefix::Policy(#policy.into()))
  2916. }
  2917. Self::DirectiveMap(list) => {
  2918. let map = map_lit(
  2919. quote! { ::std::collections::HashMap },
  2920. list,
  2921. str_lit,
  2922. identity,
  2923. );
  2924. quote!(#prefix::DirectiveMap(#map))
  2925. }
  2926. })
  2927. }
  2928. }
  2929. impl ToTokens for DisabledCspModificationKind {
  2930. fn to_tokens(&self, tokens: &mut TokenStream) {
  2931. let prefix = quote! { ::tauri::utils::config::DisabledCspModificationKind };
  2932. tokens.append_all(match self {
  2933. Self::Flag(flag) => {
  2934. quote! { #prefix::Flag(#flag) }
  2935. }
  2936. Self::List(directives) => {
  2937. let directives = vec_lit(directives, str_lit);
  2938. quote! { #prefix::List(#directives) }
  2939. }
  2940. });
  2941. }
  2942. }
  2943. impl ToTokens for SecurityConfig {
  2944. fn to_tokens(&self, tokens: &mut TokenStream) {
  2945. let csp = opt_lit(self.csp.as_ref());
  2946. let dev_csp = opt_lit(self.dev_csp.as_ref());
  2947. let freeze_prototype = self.freeze_prototype;
  2948. let dangerous_disable_asset_csp_modification = &self.dangerous_disable_asset_csp_modification;
  2949. literal_struct!(
  2950. tokens,
  2951. SecurityConfig,
  2952. csp,
  2953. dev_csp,
  2954. freeze_prototype,
  2955. dangerous_disable_asset_csp_modification
  2956. );
  2957. }
  2958. }
  2959. impl ToTokens for SystemTrayConfig {
  2960. fn to_tokens(&self, tokens: &mut TokenStream) {
  2961. let icon_as_template = self.icon_as_template;
  2962. let menu_on_left_click = self.menu_on_left_click;
  2963. let icon_path = path_buf_lit(&self.icon_path);
  2964. literal_struct!(
  2965. tokens,
  2966. SystemTrayConfig,
  2967. icon_path,
  2968. icon_as_template,
  2969. menu_on_left_click
  2970. );
  2971. }
  2972. }
  2973. impl ToTokens for FsAllowlistScope {
  2974. fn to_tokens(&self, tokens: &mut TokenStream) {
  2975. let prefix = quote! { ::tauri::utils::config::FsAllowlistScope };
  2976. tokens.append_all(match self {
  2977. Self::AllowedPaths(allow) => {
  2978. let allowed_paths = vec_lit(allow, path_buf_lit);
  2979. quote! { #prefix::AllowedPaths(#allowed_paths) }
  2980. }
  2981. Self::Scope { allow, deny } => {
  2982. let allow = vec_lit(allow, path_buf_lit);
  2983. let deny = vec_lit(deny, path_buf_lit);
  2984. quote! { #prefix::Scope { allow: #allow, deny: #deny } }
  2985. }
  2986. });
  2987. }
  2988. }
  2989. impl ToTokens for FsAllowlistConfig {
  2990. fn to_tokens(&self, tokens: &mut TokenStream) {
  2991. let scope = &self.scope;
  2992. tokens.append_all(quote! { ::tauri::utils::config::FsAllowlistConfig { scope: #scope, ..Default::default() } })
  2993. }
  2994. }
  2995. impl ToTokens for ProtocolAllowlistConfig {
  2996. fn to_tokens(&self, tokens: &mut TokenStream) {
  2997. let asset_scope = &self.asset_scope;
  2998. tokens.append_all(quote! { ::tauri::utils::config::ProtocolAllowlistConfig { asset_scope: #asset_scope, ..Default::default() } })
  2999. }
  3000. }
  3001. impl ToTokens for HttpAllowlistScope {
  3002. fn to_tokens(&self, tokens: &mut TokenStream) {
  3003. let allowed_urls = vec_lit(&self.0, url_lit);
  3004. tokens.append_all(quote! { ::tauri::utils::config::HttpAllowlistScope(#allowed_urls) })
  3005. }
  3006. }
  3007. impl ToTokens for HttpAllowlistConfig {
  3008. fn to_tokens(&self, tokens: &mut TokenStream) {
  3009. let scope = &self.scope;
  3010. tokens.append_all(quote! { ::tauri::utils::config::HttpAllowlistConfig { scope: #scope, ..Default::default() } })
  3011. }
  3012. }
  3013. impl ToTokens for ShellAllowedCommand {
  3014. fn to_tokens(&self, tokens: &mut TokenStream) {
  3015. let name = str_lit(&self.name);
  3016. let command = path_buf_lit(&self.command);
  3017. let args = &self.args;
  3018. let sidecar = &self.sidecar;
  3019. literal_struct!(tokens, ShellAllowedCommand, name, command, args, sidecar);
  3020. }
  3021. }
  3022. impl ToTokens for ShellAllowedArgs {
  3023. fn to_tokens(&self, tokens: &mut TokenStream) {
  3024. let prefix = quote! { ::tauri::utils::config::ShellAllowedArgs };
  3025. tokens.append_all(match self {
  3026. Self::Flag(flag) => quote!(#prefix::Flag(#flag)),
  3027. Self::List(list) => {
  3028. let list = vec_lit(list, identity);
  3029. quote!(#prefix::List(#list))
  3030. }
  3031. })
  3032. }
  3033. }
  3034. impl ToTokens for ShellAllowedArg {
  3035. fn to_tokens(&self, tokens: &mut TokenStream) {
  3036. let prefix = quote! { ::tauri::utils::config::ShellAllowedArg };
  3037. tokens.append_all(match self {
  3038. Self::Fixed(fixed) => {
  3039. let fixed = str_lit(fixed);
  3040. quote!(#prefix::Fixed(#fixed))
  3041. }
  3042. Self::Var { validator } => {
  3043. let validator = str_lit(validator);
  3044. quote!(#prefix::Var { validator: #validator })
  3045. }
  3046. })
  3047. }
  3048. }
  3049. impl ToTokens for ShellAllowlistOpen {
  3050. fn to_tokens(&self, tokens: &mut TokenStream) {
  3051. let prefix = quote! { ::tauri::utils::config::ShellAllowlistOpen };
  3052. tokens.append_all(match self {
  3053. Self::Flag(flag) => quote!(#prefix::Flag(#flag)),
  3054. Self::Validate(regex) => quote!(#prefix::Validate(#regex)),
  3055. })
  3056. }
  3057. }
  3058. impl ToTokens for ShellAllowlistScope {
  3059. fn to_tokens(&self, tokens: &mut TokenStream) {
  3060. let allowed_commands = vec_lit(&self.0, identity);
  3061. tokens.append_all(quote! { ::tauri::utils::config::ShellAllowlistScope(#allowed_commands) })
  3062. }
  3063. }
  3064. impl ToTokens for ShellAllowlistConfig {
  3065. fn to_tokens(&self, tokens: &mut TokenStream) {
  3066. let scope = &self.scope;
  3067. tokens.append_all(quote! { ::tauri::utils::config::ShellAllowlistConfig { scope: #scope, ..Default::default() } })
  3068. }
  3069. }
  3070. impl ToTokens for AllowlistConfig {
  3071. fn to_tokens(&self, tokens: &mut TokenStream) {
  3072. let fs = &self.fs;
  3073. let protocol = &self.protocol;
  3074. let http = &self.http;
  3075. let shell = &self.shell;
  3076. tokens.append_all(
  3077. quote! { ::tauri::utils::config::AllowlistConfig { fs: #fs, protocol: #protocol, http: #http, shell: #shell, ..Default::default() } },
  3078. )
  3079. }
  3080. }
  3081. impl ToTokens for TauriConfig {
  3082. fn to_tokens(&self, tokens: &mut TokenStream) {
  3083. let pattern = &self.pattern;
  3084. let windows = vec_lit(&self.windows, identity);
  3085. let cli = opt_lit(self.cli.as_ref());
  3086. let bundle = &self.bundle;
  3087. let updater = &self.updater;
  3088. let security = &self.security;
  3089. let system_tray = opt_lit(self.system_tray.as_ref());
  3090. let allowlist = &self.allowlist;
  3091. let macos_private_api = self.macos_private_api;
  3092. literal_struct!(
  3093. tokens,
  3094. TauriConfig,
  3095. pattern,
  3096. windows,
  3097. cli,
  3098. bundle,
  3099. updater,
  3100. security,
  3101. system_tray,
  3102. allowlist,
  3103. macos_private_api
  3104. );
  3105. }
  3106. }
  3107. impl ToTokens for PluginConfig {
  3108. fn to_tokens(&self, tokens: &mut TokenStream) {
  3109. let config = map_lit(
  3110. quote! { ::std::collections::HashMap },
  3111. &self.0,
  3112. str_lit,
  3113. json_value_lit,
  3114. );
  3115. tokens.append_all(quote! { ::tauri::utils::config::PluginConfig(#config) })
  3116. }
  3117. }
  3118. impl ToTokens for PackageConfig {
  3119. fn to_tokens(&self, tokens: &mut TokenStream) {
  3120. let product_name = opt_str_lit(self.product_name.as_ref());
  3121. let version = opt_str_lit(self.version.as_ref());
  3122. literal_struct!(tokens, PackageConfig, product_name, version);
  3123. }
  3124. }
  3125. impl ToTokens for Config {
  3126. fn to_tokens(&self, tokens: &mut TokenStream) {
  3127. let schema = quote!(None);
  3128. let package = &self.package;
  3129. let tauri = &self.tauri;
  3130. let build = &self.build;
  3131. let plugins = &self.plugins;
  3132. literal_struct!(tokens, Config, schema, package, tauri, build, plugins);
  3133. }
  3134. }
  3135. }
  3136. #[cfg(test)]
  3137. mod test {
  3138. use super::*;
  3139. // TODO: create a test that compares a config to a json config
  3140. #[test]
  3141. // test all of the default functions
  3142. fn test_defaults() {
  3143. // get default tauri config
  3144. let t_config = TauriConfig::default();
  3145. // get default build config
  3146. let b_config = BuildConfig::default();
  3147. // get default dev path
  3148. let d_path = default_dev_path();
  3149. // get default window
  3150. let d_windows: Vec<WindowConfig> = vec![];
  3151. // get default bundle
  3152. let d_bundle = BundleConfig::default();
  3153. // get default updater
  3154. let d_updater = UpdaterConfig::default();
  3155. // create a tauri config.
  3156. let tauri = TauriConfig {
  3157. pattern: Default::default(),
  3158. windows: vec![],
  3159. bundle: BundleConfig {
  3160. active: false,
  3161. targets: Default::default(),
  3162. identifier: String::from(""),
  3163. icon: Vec::new(),
  3164. resources: None,
  3165. copyright: None,
  3166. category: None,
  3167. short_description: None,
  3168. long_description: None,
  3169. appimage: Default::default(),
  3170. deb: Default::default(),
  3171. macos: Default::default(),
  3172. external_bin: None,
  3173. windows: Default::default(),
  3174. },
  3175. cli: None,
  3176. updater: UpdaterConfig {
  3177. active: false,
  3178. dialog: true,
  3179. pubkey: "".into(),
  3180. endpoints: None,
  3181. windows: Default::default(),
  3182. },
  3183. security: SecurityConfig {
  3184. csp: None,
  3185. dev_csp: None,
  3186. freeze_prototype: false,
  3187. dangerous_disable_asset_csp_modification: DisabledCspModificationKind::Flag(false),
  3188. },
  3189. allowlist: AllowlistConfig::default(),
  3190. system_tray: None,
  3191. macos_private_api: false,
  3192. };
  3193. // create a build config
  3194. let build = BuildConfig {
  3195. runner: None,
  3196. dev_path: AppUrl::Url(WindowUrl::External(
  3197. Url::parse("http://localhost:8080").unwrap(),
  3198. )),
  3199. dist_dir: AppUrl::Url(WindowUrl::App("../dist".into())),
  3200. before_dev_command: None,
  3201. before_build_command: None,
  3202. features: None,
  3203. with_global_tauri: false,
  3204. };
  3205. // test the configs
  3206. assert_eq!(t_config, tauri);
  3207. assert_eq!(b_config, build);
  3208. assert_eq!(d_bundle, tauri.bundle);
  3209. assert_eq!(d_updater, tauri.updater);
  3210. assert_eq!(
  3211. d_path,
  3212. AppUrl::Url(WindowUrl::External(
  3213. Url::parse("http://localhost:8080").unwrap()
  3214. ))
  3215. );
  3216. assert_eq!(d_windows, tauri.windows);
  3217. }
  3218. }