config_definition.rs 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643
  1. // Copyright 2019-2021 Tauri Programme within The Commons Conservancy
  2. // SPDX-License-Identifier: Apache-2.0
  3. // SPDX-License-Identifier: MIT
  4. #![allow(clippy::field_reassign_with_default)]
  5. use schemars::JsonSchema;
  6. use serde::{Deserialize, Serialize};
  7. use serde_json::Value as JsonValue;
  8. use serde_with::skip_serializing_none;
  9. use std::{collections::HashMap, path::PathBuf};
  10. #[derive(Debug, PartialEq, Clone, Deserialize, Serialize, JsonSchema)]
  11. #[serde(untagged)]
  12. pub enum BundleTarget {
  13. All(Vec<String>),
  14. One(String),
  15. }
  16. #[skip_serializing_none]
  17. #[derive(Debug, Default, PartialEq, Clone, Deserialize, Serialize, JsonSchema)]
  18. #[serde(rename_all = "camelCase", deny_unknown_fields)]
  19. pub struct DebConfig {
  20. pub depends: Option<Vec<String>>,
  21. #[serde(default)]
  22. pub use_bootstrapper: bool,
  23. }
  24. #[skip_serializing_none]
  25. #[derive(Debug, Default, PartialEq, Clone, Deserialize, Serialize, JsonSchema)]
  26. #[serde(rename_all = "camelCase", deny_unknown_fields)]
  27. pub struct MacConfig {
  28. pub frameworks: Option<Vec<String>>,
  29. pub minimum_system_version: Option<String>,
  30. pub exception_domain: Option<String>,
  31. pub license: Option<String>,
  32. #[serde(default)]
  33. pub use_bootstrapper: bool,
  34. pub signing_identity: Option<String>,
  35. pub entitlements: Option<String>,
  36. }
  37. #[derive(Debug, Default, PartialEq, Clone, Deserialize, Serialize, JsonSchema)]
  38. #[serde(rename_all = "camelCase", deny_unknown_fields)]
  39. pub struct WixConfig {
  40. pub template: Option<PathBuf>,
  41. #[serde(default)]
  42. pub fragment_paths: Vec<PathBuf>,
  43. #[serde(default)]
  44. pub component_group_refs: Vec<String>,
  45. #[serde(default)]
  46. pub component_refs: Vec<String>,
  47. #[serde(default)]
  48. pub feature_group_refs: Vec<String>,
  49. #[serde(default)]
  50. pub feature_refs: Vec<String>,
  51. #[serde(default)]
  52. pub merge_refs: Vec<String>,
  53. }
  54. #[derive(Debug, Default, PartialEq, Clone, Deserialize, Serialize, JsonSchema)]
  55. #[serde(rename_all = "camelCase", deny_unknown_fields)]
  56. pub struct WindowsConfig {
  57. pub digest_algorithm: Option<String>,
  58. pub certificate_thumbprint: Option<String>,
  59. pub timestamp_url: Option<String>,
  60. pub wix: Option<WixConfig>,
  61. }
  62. #[skip_serializing_none]
  63. #[derive(Debug, Default, PartialEq, Clone, Deserialize, Serialize, JsonSchema)]
  64. #[serde(rename_all = "camelCase", deny_unknown_fields)]
  65. pub struct PackageConfig {
  66. /// App name. Automatically converted to kebab-case on Linux.
  67. pub product_name: Option<String>,
  68. /// App version.
  69. pub version: Option<String>,
  70. }
  71. #[skip_serializing_none]
  72. #[derive(Debug, Default, PartialEq, Clone, Deserialize, Serialize, JsonSchema)]
  73. #[serde(rename_all = "camelCase", deny_unknown_fields)]
  74. pub struct BundleConfig {
  75. /// Whether we should build your app with tauri-bundler or plain `cargo build`
  76. #[serde(default)]
  77. pub active: bool,
  78. /// The bundle targets, currently supports ["deb", "app", "msi", "appimage", "dmg"] or "all"
  79. pub targets: Option<BundleTarget>,
  80. /// The app's identifier
  81. pub identifier: Option<String>,
  82. /// The app's icons
  83. pub icon: Option<Vec<String>>,
  84. /// App resources to bundle.
  85. /// Each resource is a path to a file or directory.
  86. /// Glob patterns are supported.
  87. pub resources: Option<Vec<String>>,
  88. pub copyright: Option<String>,
  89. pub category: Option<String>,
  90. pub short_description: Option<String>,
  91. pub long_description: Option<String>,
  92. #[serde(default)]
  93. pub deb: DebConfig,
  94. #[serde(rename = "macOS", default)]
  95. pub macos: MacConfig,
  96. pub external_bin: Option<Vec<String>>,
  97. #[serde(default)]
  98. pub windows: WindowsConfig,
  99. }
  100. /// A CLI argument definition
  101. #[skip_serializing_none]
  102. #[derive(Debug, PartialEq, Clone, Deserialize, Serialize, JsonSchema)]
  103. #[serde(rename_all = "camelCase", deny_unknown_fields)]
  104. pub struct CliArg {
  105. /// The short version of the argument, without the preceding -.
  106. ///
  107. /// NOTE: Any leading - characters will be stripped, and only the first non - character will be used as the short version.
  108. pub short: Option<char>,
  109. /// The unique argument name
  110. pub name: String,
  111. /// The argument description which will be shown on the help information.
  112. /// Typically, this is a short (one line) description of the arg.
  113. pub description: Option<String>,
  114. /// The argument long description which will be shown on the help information.
  115. /// Typically this a more detailed (multi-line) message that describes the argument.
  116. pub long_description: Option<String>,
  117. /// Specifies that the argument takes a value at run time.
  118. ///
  119. /// NOTE: values for arguments may be specified in any of the following methods
  120. /// - Using a space such as -o value or --option value
  121. /// - Using an equals and no space such as -o=value or --option=value
  122. /// - Use a short and no space such as -ovalue
  123. pub takes_value: Option<bool>,
  124. /// Specifies that the argument may appear more than once.
  125. ///
  126. /// - For flags, this results in the number of occurrences of the flag being recorded.
  127. /// For example -ddd or -d -d -d would count as three occurrences.
  128. /// - For options there is a distinct difference in multiple occurrences vs multiple values.
  129. /// For example, --opt val1 val2 is one occurrence, but two values. Whereas --opt val1 --opt val2 is two occurrences.
  130. pub multiple: Option<bool>,
  131. /// specifies that the argument may appear more than once.
  132. pub multiple_occurrences: Option<bool>,
  133. ///
  134. pub number_of_values: Option<u64>,
  135. /// Specifies a list of possible values for this argument.
  136. /// At runtime, the CLI verifies that only one of the specified values was used, or fails with an error message.
  137. pub possible_values: Option<Vec<String>>,
  138. /// Specifies the minimum number of values for this argument.
  139. /// For example, if you had a -f <file> argument where you wanted at least 2 'files',
  140. /// you would set `minValues: 2`, and this argument would be satisfied if the user provided, 2 or more values.
  141. pub min_values: Option<u64>,
  142. /// Specifies the maximum number of values are for this argument.
  143. /// For example, if you had a -f <file> argument where you wanted up to 3 'files',
  144. /// you would set .max_values(3), and this argument would be satisfied if the user provided, 1, 2, or 3 values.
  145. pub max_values: Option<u64>,
  146. /// Sets whether or not the argument is required by default.
  147. ///
  148. /// - Required by default means it is required, when no other conflicting rules have been evaluated
  149. /// - Conflicting rules take precedence over being required.
  150. pub required: Option<bool>,
  151. /// Sets an arg that override this arg's required setting
  152. /// i.e. this arg will be required unless this other argument is present.
  153. pub required_unless_present: Option<String>,
  154. /// Sets args that override this arg's required setting
  155. /// i.e. this arg will be required unless all these other arguments are present.
  156. pub required_unless_present_all: Option<Vec<String>>,
  157. /// Sets args that override this arg's required setting
  158. /// i.e. this arg will be required unless at least one of these other arguments are present.
  159. pub required_unless_present_any: Option<Vec<String>>,
  160. /// Sets a conflicting argument by name
  161. /// i.e. when using this argument, the following argument can't be present and vice versa.
  162. pub conflicts_with: Option<String>,
  163. /// The same as conflictsWith but allows specifying multiple two-way conflicts per argument.
  164. pub conflicts_with_all: Option<Vec<String>>,
  165. /// Tets an argument by name that is required when this one is present
  166. /// i.e. when using this argument, the following argument must be present.
  167. pub requires: Option<String>,
  168. /// Sts multiple arguments by names that are required when this one is present
  169. /// i.e. when using this argument, the following arguments must be present.
  170. pub requires_all: Option<Vec<String>>,
  171. /// Allows a conditional requirement with the signature [arg, value]
  172. /// the requirement will only become valid if `arg`'s value equals `${value}`.
  173. pub requires_if: Option<Vec<String>>,
  174. /// Allows specifying that an argument is required conditionally with the signature [arg, value]
  175. /// the requirement will only become valid if the `arg`'s value equals `${value}`.
  176. pub required_if_eq: Option<Vec<String>>,
  177. /// Requires that options use the --option=val syntax
  178. /// i.e. an equals between the option and associated value.
  179. pub require_equals: Option<bool>,
  180. /// The positional argument index, starting at 1.
  181. ///
  182. /// The index refers to position according to other positional argument.
  183. /// It does not define position in the argument list as a whole. When utilized with multiple=true,
  184. /// only the last positional argument may be defined as multiple (i.e. the one with the highest index).
  185. pub index: Option<u64>,
  186. }
  187. /// describes a CLI configuration
  188. #[skip_serializing_none]
  189. #[derive(Debug, PartialEq, Clone, Deserialize, Serialize, JsonSchema)]
  190. #[serde(rename_all = "camelCase", deny_unknown_fields)]
  191. pub struct CliConfig {
  192. /// command description which will be shown on the help information
  193. description: Option<String>,
  194. /// command long description which will be shown on the help information
  195. long_description: Option<String>,
  196. /// adds additional help information to be displayed in addition to auto-generated help
  197. /// this information is displayed before the auto-generated help information.
  198. /// this is often used for header information
  199. before_help: Option<String>,
  200. /// adds additional help information to be displayed in addition to auto-generated help
  201. /// this information is displayed after the auto-generated help information
  202. /// this is often used to describe how to use the arguments, or caveats to be noted.
  203. after_help: Option<String>,
  204. /// list of args for the command
  205. args: Option<Vec<CliArg>>,
  206. /// list of subcommands of this command.
  207. ///
  208. /// subcommands are effectively sub-apps, because they can contain their own arguments, subcommands, usage, etc.
  209. /// they also function just like the app command, in that they get their own auto generated help and usage
  210. subcommands: Option<HashMap<String, CliConfig>>,
  211. }
  212. #[derive(Debug, PartialEq, Clone, Deserialize, Serialize, JsonSchema)]
  213. #[serde(untagged)]
  214. pub enum Port {
  215. /// Port with a numeric value.
  216. Value(u16),
  217. /// Random port.
  218. Random,
  219. }
  220. /// The window configuration object.
  221. #[skip_serializing_none]
  222. #[derive(Debug, Default, PartialEq, Clone, Deserialize, Serialize, JsonSchema)]
  223. #[serde(rename_all = "camelCase", deny_unknown_fields)]
  224. pub struct WindowConfig {
  225. /// The window identifier.
  226. pub label: Option<String>,
  227. /// The window webview URL.
  228. pub url: Option<String>,
  229. /// The horizontal position of the window's top left corner
  230. pub x: Option<f64>,
  231. /// The vertical position of the window's top left corner
  232. pub y: Option<f64>,
  233. /// The window width.
  234. pub width: Option<f64>,
  235. /// The window height.
  236. pub height: Option<f64>,
  237. /// The min window width.
  238. pub min_width: Option<f64>,
  239. /// The min window height.
  240. pub min_height: Option<f64>,
  241. /// The max window width.
  242. pub max_width: Option<f64>,
  243. /// The max window height.
  244. pub max_height: Option<f64>,
  245. /// Whether the window is resizable or not.
  246. #[serde(default)]
  247. pub resizable: bool,
  248. /// The window title.
  249. pub title: Option<String>,
  250. /// Whether the window starts as fullscreen or not.
  251. #[serde(default)]
  252. pub fullscreen: bool,
  253. /// Whether the window is transparent or not.
  254. #[serde(default)]
  255. pub transparent: bool,
  256. /// Whether the window is maximized or not.
  257. #[serde(default)]
  258. pub maximized: bool,
  259. /// Whether the window is visible or not.
  260. #[serde(default = "default_visible")]
  261. pub visible: bool,
  262. /// Whether the window should have borders and bars.
  263. #[serde(default = "default_decorations")]
  264. pub decorations: bool,
  265. /// Whether the window should always be on top of other windows.
  266. #[serde(default)]
  267. pub always_on_top: bool,
  268. }
  269. fn default_visible() -> bool {
  270. true
  271. }
  272. fn default_decorations() -> bool {
  273. true
  274. }
  275. #[skip_serializing_none]
  276. #[derive(Debug, Default, PartialEq, Clone, Deserialize, Serialize, JsonSchema)]
  277. #[serde(rename_all = "camelCase", deny_unknown_fields)]
  278. pub struct SecurityConfig {
  279. pub csp: Option<String>,
  280. }
  281. trait Allowlist {
  282. fn to_features(&self) -> Vec<&str>;
  283. }
  284. macro_rules! check_feature {
  285. ($self:ident, $features:ident, $flag:ident, $feature_name: expr) => {
  286. if $self.$flag {
  287. $features.push($feature_name)
  288. }
  289. };
  290. }
  291. #[derive(Debug, Default, PartialEq, Clone, Deserialize, Serialize, JsonSchema)]
  292. #[serde(rename_all = "camelCase", deny_unknown_fields)]
  293. struct FsAllowlistConfig {
  294. #[serde(default)]
  295. all: bool,
  296. #[serde(default)]
  297. read_text_file: bool,
  298. #[serde(default)]
  299. read_binary_file: bool,
  300. #[serde(default)]
  301. write_file: bool,
  302. #[serde(default)]
  303. write_binary_file: bool,
  304. #[serde(default)]
  305. read_dir: bool,
  306. #[serde(default)]
  307. copy_file: bool,
  308. #[serde(default)]
  309. create_dir: bool,
  310. #[serde(default)]
  311. remove_dir: bool,
  312. #[serde(default)]
  313. remove_file: bool,
  314. #[serde(default)]
  315. rename_file: bool,
  316. #[serde(default)]
  317. path: bool,
  318. }
  319. impl Allowlist for FsAllowlistConfig {
  320. fn to_features(&self) -> Vec<&str> {
  321. if self.all {
  322. vec!["fs-all"]
  323. } else {
  324. let mut features = Vec::new();
  325. check_feature!(self, features, read_text_file, "fs-read-text-file");
  326. check_feature!(self, features, read_binary_file, "fs-read-binary-file");
  327. check_feature!(self, features, write_file, "fs-write-file");
  328. check_feature!(self, features, write_binary_file, "fs-write-binary-file");
  329. check_feature!(self, features, read_dir, "fs-read-dir");
  330. check_feature!(self, features, copy_file, "fs-copy-file");
  331. check_feature!(self, features, create_dir, "fs-create-dir");
  332. check_feature!(self, features, remove_dir, "fs-remove-dir");
  333. check_feature!(self, features, remove_file, "fs-remove-file");
  334. check_feature!(self, features, rename_file, "fs-rename-file");
  335. check_feature!(self, features, path, "fs-path");
  336. features
  337. }
  338. }
  339. }
  340. #[derive(Debug, Default, PartialEq, Clone, Deserialize, Serialize, JsonSchema)]
  341. #[serde(rename_all = "camelCase", deny_unknown_fields)]
  342. struct WindowAllowlistConfig {
  343. #[serde(default)]
  344. all: bool,
  345. #[serde(default)]
  346. create: bool,
  347. }
  348. impl Allowlist for WindowAllowlistConfig {
  349. fn to_features(&self) -> Vec<&str> {
  350. if self.all {
  351. vec!["window-all"]
  352. } else {
  353. let mut features = Vec::new();
  354. check_feature!(self, features, create, "window-create");
  355. features
  356. }
  357. }
  358. }
  359. #[derive(Debug, Default, PartialEq, Clone, Deserialize, Serialize, JsonSchema)]
  360. #[serde(rename_all = "camelCase", deny_unknown_fields)]
  361. struct ShellAllowlistConfig {
  362. #[serde(default)]
  363. all: bool,
  364. #[serde(default)]
  365. execute: bool,
  366. #[serde(default)]
  367. open: bool,
  368. }
  369. impl Allowlist for ShellAllowlistConfig {
  370. fn to_features(&self) -> Vec<&str> {
  371. if self.all {
  372. vec!["shell-all"]
  373. } else {
  374. let mut features = Vec::new();
  375. check_feature!(self, features, execute, "shell-execute");
  376. check_feature!(self, features, open, "shell-open");
  377. features
  378. }
  379. }
  380. }
  381. #[derive(Debug, Default, PartialEq, Clone, Deserialize, Serialize, JsonSchema)]
  382. #[serde(rename_all = "camelCase", deny_unknown_fields)]
  383. struct DialogAllowlistConfig {
  384. #[serde(default)]
  385. all: bool,
  386. #[serde(default)]
  387. open: bool,
  388. #[serde(default)]
  389. save: bool,
  390. }
  391. impl Allowlist for DialogAllowlistConfig {
  392. fn to_features(&self) -> Vec<&str> {
  393. if self.all {
  394. vec!["dialog-all"]
  395. } else {
  396. let mut features = Vec::new();
  397. check_feature!(self, features, open, "dialog-open");
  398. check_feature!(self, features, save, "dialog-save");
  399. features
  400. }
  401. }
  402. }
  403. #[derive(Debug, Default, PartialEq, Clone, Deserialize, Serialize, JsonSchema)]
  404. #[serde(rename_all = "camelCase", deny_unknown_fields)]
  405. struct HttpAllowlistConfig {
  406. #[serde(default)]
  407. all: bool,
  408. #[serde(default)]
  409. request: bool,
  410. }
  411. impl Allowlist for HttpAllowlistConfig {
  412. fn to_features(&self) -> Vec<&str> {
  413. if self.all {
  414. vec!["http-all"]
  415. } else {
  416. let mut features = Vec::new();
  417. check_feature!(self, features, request, "http-request");
  418. features
  419. }
  420. }
  421. }
  422. #[derive(Debug, Default, PartialEq, Clone, Deserialize, Serialize, JsonSchema)]
  423. #[serde(rename_all = "camelCase", deny_unknown_fields)]
  424. struct NotificationAllowlistConfig {
  425. #[serde(default)]
  426. all: bool,
  427. }
  428. impl Allowlist for NotificationAllowlistConfig {
  429. fn to_features(&self) -> Vec<&str> {
  430. if self.all {
  431. vec!["notification-all"]
  432. } else {
  433. vec![]
  434. }
  435. }
  436. }
  437. #[derive(Debug, Default, PartialEq, Clone, Deserialize, Serialize, JsonSchema)]
  438. #[serde(rename_all = "camelCase", deny_unknown_fields)]
  439. struct GlobalShortcutAllowlistConfig {
  440. #[serde(default)]
  441. all: bool,
  442. }
  443. impl Allowlist for GlobalShortcutAllowlistConfig {
  444. fn to_features(&self) -> Vec<&str> {
  445. if self.all {
  446. vec!["global-shortcut-all"]
  447. } else {
  448. vec![]
  449. }
  450. }
  451. }
  452. #[derive(Debug, Default, PartialEq, Clone, Deserialize, Serialize, JsonSchema)]
  453. #[serde(rename_all = "camelCase", deny_unknown_fields)]
  454. struct AllowlistConfig {
  455. #[serde(default)]
  456. all: bool,
  457. #[serde(default)]
  458. fs: FsAllowlistConfig,
  459. #[serde(default)]
  460. window: WindowAllowlistConfig,
  461. #[serde(default)]
  462. shell: ShellAllowlistConfig,
  463. #[serde(default)]
  464. dialog: DialogAllowlistConfig,
  465. #[serde(default)]
  466. http: HttpAllowlistConfig,
  467. #[serde(default)]
  468. notification: NotificationAllowlistConfig,
  469. #[serde(default)]
  470. global_shortcut: GlobalShortcutAllowlistConfig,
  471. }
  472. impl Allowlist for AllowlistConfig {
  473. fn to_features(&self) -> Vec<&str> {
  474. if self.all {
  475. vec!["api-all"]
  476. } else {
  477. let mut features = Vec::new();
  478. features.extend(self.fs.to_features());
  479. features.extend(self.window.to_features());
  480. features.extend(self.shell.to_features());
  481. features.extend(self.dialog.to_features());
  482. features.extend(self.http.to_features());
  483. features.extend(self.notification.to_features());
  484. features.extend(self.global_shortcut.to_features());
  485. features
  486. }
  487. }
  488. }
  489. /// The Tauri configuration object.
  490. #[skip_serializing_none]
  491. #[derive(Debug, Default, PartialEq, Clone, Deserialize, Serialize, JsonSchema)]
  492. #[serde(rename_all = "camelCase", deny_unknown_fields)]
  493. pub struct TauriConfig {
  494. /// The windows configuration.
  495. #[serde(default)]
  496. pub windows: Vec<WindowConfig>,
  497. /// The CLI configuration.
  498. pub cli: Option<CliConfig>,
  499. /// The bundler configuration.
  500. #[serde(default)]
  501. pub bundle: BundleConfig,
  502. #[serde(default)]
  503. allowlist: AllowlistConfig,
  504. pub security: Option<SecurityConfig>,
  505. /// The updater configuration.
  506. #[serde(default = "default_updater")]
  507. pub updater: UpdaterConfig,
  508. }
  509. impl TauriConfig {
  510. #[allow(dead_code)]
  511. pub fn features(&self) -> Vec<&str> {
  512. self.allowlist.to_features()
  513. }
  514. }
  515. #[skip_serializing_none]
  516. #[derive(Debug, Default, PartialEq, Clone, Deserialize, Serialize, JsonSchema)]
  517. #[serde(rename_all = "camelCase", deny_unknown_fields)]
  518. pub struct UpdaterConfig {
  519. /// Whether the updater is active or not.
  520. #[serde(default)]
  521. pub active: bool,
  522. /// Display built-in dialog or use event system if disabled.
  523. #[serde(default = "default_dialog")]
  524. pub dialog: Option<bool>,
  525. /// The updater endpoints.
  526. pub endpoints: Option<Vec<String>>,
  527. /// Optional pubkey.
  528. pub pubkey: Option<String>,
  529. }
  530. // We enable the unnecessary_wraps because we need
  531. // to use an Option for dialog otherwise the CLI schema will mark
  532. // the dialog as a required field which is not as we default it to true.
  533. #[allow(clippy::unnecessary_wraps)]
  534. fn default_dialog() -> Option<bool> {
  535. Some(true)
  536. }
  537. /// The Build configuration object.
  538. #[skip_serializing_none]
  539. #[derive(Debug, PartialEq, Clone, Deserialize, Serialize, JsonSchema)]
  540. #[serde(rename_all = "camelCase", deny_unknown_fields)]
  541. pub struct BuildConfig {
  542. /// the app's dev server URL, or the path to the directory containing an index.html file
  543. #[serde(default = "default_dev_path")]
  544. pub dev_path: String,
  545. /// the path to the app's dist dir. This path must contain your index.html file.
  546. #[serde(default = "default_dist_dir")]
  547. pub dist_dir: String,
  548. /// a shell command to run before `tauri dev` kicks in
  549. pub before_dev_command: Option<String>,
  550. /// a shell command to run before `tauri build` kicks in
  551. pub before_build_command: Option<String>,
  552. /// Whether we should inject the Tauri API on `window.__TAURI__` or not.
  553. #[serde(default)]
  554. pub with_global_tauri: bool,
  555. }
  556. fn default_dev_path() -> String {
  557. "".to_string()
  558. }
  559. fn default_dist_dir() -> String {
  560. "../dist".to_string()
  561. }
  562. type JsonObject = HashMap<String, JsonValue>;
  563. /// The tauri.conf.json mapper.
  564. #[skip_serializing_none]
  565. #[derive(Debug, PartialEq, Clone, Deserialize, Serialize, JsonSchema)]
  566. #[serde(rename_all = "camelCase", deny_unknown_fields)]
  567. pub struct Config {
  568. /// Package settings.
  569. #[serde(default)]
  570. pub package: PackageConfig,
  571. /// The Tauri configuration.
  572. #[serde(default)]
  573. pub tauri: TauriConfig,
  574. /// The build configuration.
  575. #[serde(default = "default_build")]
  576. pub build: BuildConfig,
  577. /// The plugins config.
  578. #[serde(default)]
  579. pub plugins: HashMap<String, JsonObject>,
  580. }
  581. fn default_build() -> BuildConfig {
  582. BuildConfig {
  583. dev_path: default_dev_path(),
  584. dist_dir: default_dist_dir(),
  585. before_dev_command: None,
  586. before_build_command: None,
  587. with_global_tauri: false,
  588. }
  589. }
  590. fn default_updater() -> UpdaterConfig {
  591. UpdaterConfig {
  592. active: false,
  593. dialog: Some(true),
  594. endpoints: None,
  595. pubkey: None,
  596. }
  597. }