config_definition.rs 23 KB

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