config.rs 94 KB

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