config_definition.rs 23 KB

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