config_definition.rs 21 KB

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