config_definition.rs 21 KB

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