config_definition.rs 24 KB

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