config_definition.rs 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712
  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. /// The horizontal position of the window's top left corner
  256. pub x: Option<f64>,
  257. /// The vertical position of the window's top left corner
  258. pub y: Option<f64>,
  259. /// The window width.
  260. pub width: Option<f64>,
  261. /// The window height.
  262. pub height: Option<f64>,
  263. /// The min window width.
  264. pub min_width: Option<f64>,
  265. /// The min window height.
  266. pub min_height: Option<f64>,
  267. /// The max window width.
  268. pub max_width: Option<f64>,
  269. /// The max window height.
  270. pub max_height: Option<f64>,
  271. /// Whether the window is resizable or not.
  272. #[serde(default)]
  273. pub resizable: bool,
  274. /// The window title.
  275. pub title: Option<String>,
  276. /// Whether the window starts as fullscreen or not.
  277. #[serde(default)]
  278. pub fullscreen: bool,
  279. /// Whether the window is transparent or not.
  280. #[serde(default)]
  281. pub transparent: bool,
  282. /// Whether the window is maximized or not.
  283. #[serde(default)]
  284. pub maximized: bool,
  285. /// Whether the window is visible or not.
  286. #[serde(default = "default_visible")]
  287. pub visible: bool,
  288. /// Whether the window should have borders and bars.
  289. #[serde(default = "default_decorations")]
  290. pub decorations: bool,
  291. /// Whether the window should always be on top of other windows.
  292. #[serde(default)]
  293. pub always_on_top: bool,
  294. }
  295. fn default_visible() -> bool {
  296. true
  297. }
  298. fn default_decorations() -> bool {
  299. true
  300. }
  301. fn default_file_drop_enabled() -> bool {
  302. true
  303. }
  304. #[skip_serializing_none]
  305. #[derive(Debug, Default, PartialEq, Clone, Deserialize, Serialize, JsonSchema)]
  306. #[serde(rename_all = "camelCase", deny_unknown_fields)]
  307. pub struct SecurityConfig {
  308. pub csp: Option<String>,
  309. }
  310. pub trait Allowlist {
  311. fn to_features(&self) -> Vec<&str>;
  312. }
  313. macro_rules! check_feature {
  314. ($self:ident, $features:ident, $flag:ident, $feature_name: expr) => {
  315. if $self.$flag {
  316. $features.push($feature_name)
  317. }
  318. };
  319. }
  320. #[derive(Debug, Default, PartialEq, Clone, Deserialize, Serialize, JsonSchema)]
  321. #[serde(rename_all = "camelCase", deny_unknown_fields)]
  322. pub struct FsAllowlistConfig {
  323. #[serde(default)]
  324. pub all: bool,
  325. #[serde(default)]
  326. pub read_text_file: bool,
  327. #[serde(default)]
  328. pub read_binary_file: bool,
  329. #[serde(default)]
  330. pub write_file: bool,
  331. #[serde(default)]
  332. pub write_binary_file: bool,
  333. #[serde(default)]
  334. pub read_dir: bool,
  335. #[serde(default)]
  336. pub copy_file: bool,
  337. #[serde(default)]
  338. pub create_dir: bool,
  339. #[serde(default)]
  340. pub remove_dir: bool,
  341. #[serde(default)]
  342. pub remove_file: bool,
  343. #[serde(default)]
  344. pub rename_file: bool,
  345. #[serde(default)]
  346. pub path: bool,
  347. }
  348. impl Allowlist for FsAllowlistConfig {
  349. fn to_features(&self) -> Vec<&str> {
  350. if self.all {
  351. vec!["fs-all"]
  352. } else {
  353. let mut features = Vec::new();
  354. check_feature!(self, features, read_text_file, "fs-read-text-file");
  355. check_feature!(self, features, read_binary_file, "fs-read-binary-file");
  356. check_feature!(self, features, write_file, "fs-write-file");
  357. check_feature!(self, features, write_binary_file, "fs-write-binary-file");
  358. check_feature!(self, features, read_dir, "fs-read-dir");
  359. check_feature!(self, features, copy_file, "fs-copy-file");
  360. check_feature!(self, features, create_dir, "fs-create-dir");
  361. check_feature!(self, features, remove_dir, "fs-remove-dir");
  362. check_feature!(self, features, remove_file, "fs-remove-file");
  363. check_feature!(self, features, rename_file, "fs-rename-file");
  364. check_feature!(self, features, path, "fs-path");
  365. features
  366. }
  367. }
  368. }
  369. #[derive(Debug, Default, PartialEq, Clone, Deserialize, Serialize, JsonSchema)]
  370. #[serde(rename_all = "camelCase", deny_unknown_fields)]
  371. pub struct WindowAllowlistConfig {
  372. #[serde(default)]
  373. pub all: bool,
  374. #[serde(default)]
  375. pub create: bool,
  376. }
  377. impl Allowlist for WindowAllowlistConfig {
  378. fn to_features(&self) -> Vec<&str> {
  379. if self.all {
  380. vec!["window-all"]
  381. } else {
  382. let mut features = Vec::new();
  383. check_feature!(self, features, create, "window-create");
  384. features
  385. }
  386. }
  387. }
  388. #[derive(Debug, Default, PartialEq, Clone, Deserialize, Serialize, JsonSchema)]
  389. #[serde(rename_all = "camelCase", deny_unknown_fields)]
  390. pub struct ShellAllowlistConfig {
  391. #[serde(default)]
  392. pub all: bool,
  393. #[serde(default)]
  394. pub execute: bool,
  395. #[serde(default)]
  396. pub open: bool,
  397. }
  398. impl Allowlist for ShellAllowlistConfig {
  399. fn to_features(&self) -> Vec<&str> {
  400. if self.all {
  401. vec!["shell-all"]
  402. } else {
  403. let mut features = Vec::new();
  404. check_feature!(self, features, execute, "shell-execute");
  405. check_feature!(self, features, open, "shell-open");
  406. features
  407. }
  408. }
  409. }
  410. #[derive(Debug, Default, PartialEq, Clone, Deserialize, Serialize, JsonSchema)]
  411. #[serde(rename_all = "camelCase", deny_unknown_fields)]
  412. pub struct DialogAllowlistConfig {
  413. #[serde(default)]
  414. pub all: bool,
  415. #[serde(default)]
  416. pub open: bool,
  417. #[serde(default)]
  418. pub save: bool,
  419. }
  420. impl Allowlist for DialogAllowlistConfig {
  421. fn to_features(&self) -> Vec<&str> {
  422. if self.all {
  423. vec!["dialog-all"]
  424. } else {
  425. let mut features = Vec::new();
  426. check_feature!(self, features, open, "dialog-open");
  427. check_feature!(self, features, save, "dialog-save");
  428. features
  429. }
  430. }
  431. }
  432. #[derive(Debug, Default, PartialEq, Clone, Deserialize, Serialize, JsonSchema)]
  433. #[serde(rename_all = "camelCase", deny_unknown_fields)]
  434. pub struct HttpAllowlistConfig {
  435. #[serde(default)]
  436. pub all: bool,
  437. #[serde(default)]
  438. pub request: bool,
  439. }
  440. impl Allowlist for HttpAllowlistConfig {
  441. fn to_features(&self) -> Vec<&str> {
  442. if self.all {
  443. vec!["http-all"]
  444. } else {
  445. let mut features = Vec::new();
  446. check_feature!(self, features, request, "http-request");
  447. features
  448. }
  449. }
  450. }
  451. #[derive(Debug, Default, PartialEq, Clone, Deserialize, Serialize, JsonSchema)]
  452. #[serde(rename_all = "camelCase", deny_unknown_fields)]
  453. pub struct NotificationAllowlistConfig {
  454. #[serde(default)]
  455. pub all: bool,
  456. }
  457. impl Allowlist for NotificationAllowlistConfig {
  458. fn to_features(&self) -> Vec<&str> {
  459. if self.all {
  460. vec!["notification-all"]
  461. } else {
  462. vec![]
  463. }
  464. }
  465. }
  466. #[derive(Debug, Default, PartialEq, Clone, Deserialize, Serialize, JsonSchema)]
  467. #[serde(rename_all = "camelCase", deny_unknown_fields)]
  468. pub struct GlobalShortcutAllowlistConfig {
  469. #[serde(default)]
  470. pub all: bool,
  471. }
  472. impl Allowlist for GlobalShortcutAllowlistConfig {
  473. fn to_features(&self) -> Vec<&str> {
  474. if self.all {
  475. vec!["global-shortcut-all"]
  476. } else {
  477. vec![]
  478. }
  479. }
  480. }
  481. #[derive(Debug, Default, PartialEq, Clone, Deserialize, Serialize, JsonSchema)]
  482. #[serde(rename_all = "camelCase", deny_unknown_fields)]
  483. pub struct AllowlistConfig {
  484. #[serde(default)]
  485. pub all: bool,
  486. #[serde(default)]
  487. pub fs: FsAllowlistConfig,
  488. #[serde(default)]
  489. pub window: WindowAllowlistConfig,
  490. #[serde(default)]
  491. pub shell: ShellAllowlistConfig,
  492. #[serde(default)]
  493. pub dialog: DialogAllowlistConfig,
  494. #[serde(default)]
  495. pub http: HttpAllowlistConfig,
  496. #[serde(default)]
  497. pub notification: NotificationAllowlistConfig,
  498. #[serde(default)]
  499. pub global_shortcut: GlobalShortcutAllowlistConfig,
  500. }
  501. impl Allowlist for AllowlistConfig {
  502. fn to_features(&self) -> Vec<&str> {
  503. if self.all {
  504. vec!["api-all"]
  505. } else {
  506. let mut features = Vec::new();
  507. features.extend(self.fs.to_features());
  508. features.extend(self.window.to_features());
  509. features.extend(self.shell.to_features());
  510. features.extend(self.dialog.to_features());
  511. features.extend(self.http.to_features());
  512. features.extend(self.notification.to_features());
  513. features.extend(self.global_shortcut.to_features());
  514. features
  515. }
  516. }
  517. }
  518. /// The Tauri configuration object.
  519. #[skip_serializing_none]
  520. #[derive(Debug, Default, PartialEq, Clone, Deserialize, Serialize, JsonSchema)]
  521. #[serde(rename_all = "camelCase", deny_unknown_fields)]
  522. pub struct TauriConfig {
  523. /// The windows configuration.
  524. #[serde(default)]
  525. pub windows: Vec<WindowConfig>,
  526. /// The CLI configuration.
  527. pub cli: Option<CliConfig>,
  528. /// The bundler configuration.
  529. #[serde(default)]
  530. pub bundle: BundleConfig,
  531. #[serde(default)]
  532. allowlist: AllowlistConfig,
  533. pub security: Option<SecurityConfig>,
  534. /// The updater configuration.
  535. #[serde(default = "default_updater")]
  536. pub updater: UpdaterConfig,
  537. /// Configuration for app system tray.
  538. pub system_tray: Option<SystemTrayConfig>,
  539. }
  540. impl TauriConfig {
  541. #[allow(dead_code)]
  542. pub fn features(&self) -> Vec<&str> {
  543. self.allowlist.to_features()
  544. }
  545. }
  546. #[skip_serializing_none]
  547. #[derive(Debug, Default, PartialEq, Clone, Deserialize, Serialize, JsonSchema)]
  548. #[serde(rename_all = "camelCase", deny_unknown_fields)]
  549. pub struct UpdaterConfig {
  550. /// Whether the updater is active or not.
  551. #[serde(default)]
  552. pub active: bool,
  553. /// Display built-in dialog or use event system if disabled.
  554. #[serde(default = "default_dialog")]
  555. pub dialog: Option<bool>,
  556. /// The updater endpoints.
  557. pub endpoints: Option<Vec<String>>,
  558. /// Optional pubkey.
  559. pub pubkey: Option<String>,
  560. }
  561. #[skip_serializing_none]
  562. #[derive(Debug, Default, PartialEq, Clone, Deserialize, Serialize, JsonSchema)]
  563. #[serde(rename_all = "camelCase", deny_unknown_fields)]
  564. pub struct SystemTrayConfig {
  565. /// Path to the icon to use on the system tray.
  566. ///
  567. /// It is forced to be a `.png` file on Linux and macOS, and a `.ico` file on Windows.
  568. pub icon_path: PathBuf,
  569. }
  570. // We enable the unnecessary_wraps because we need
  571. // to use an Option for dialog otherwise the CLI schema will mark
  572. // the dialog as a required field which is not as we default it to true.
  573. #[allow(clippy::unnecessary_wraps)]
  574. fn default_dialog() -> Option<bool> {
  575. Some(true)
  576. }
  577. /// The `dev_path` and `dist_dir` options.
  578. #[derive(Debug, PartialEq, Clone, Deserialize, Serialize, JsonSchema)]
  579. #[serde(untagged, deny_unknown_fields)]
  580. pub enum AppUrl {
  581. /// The app's external URL, or the path to the directory containing the app assets.
  582. Url(String),
  583. /// An array of files to embed on the app.
  584. Files(Vec<PathBuf>),
  585. }
  586. impl std::fmt::Display for AppUrl {
  587. fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
  588. match self {
  589. Self::Url(url) => write!(f, "{}", url),
  590. Self::Files(files) => write!(f, "{}", serde_json::to_string(files).unwrap()),
  591. }
  592. }
  593. }
  594. /// The Build configuration object.
  595. #[skip_serializing_none]
  596. #[derive(Debug, PartialEq, Clone, Deserialize, Serialize, JsonSchema)]
  597. #[serde(rename_all = "camelCase", deny_unknown_fields)]
  598. pub struct BuildConfig {
  599. /// The binary used to build and run the application.
  600. pub runner: Option<String>,
  601. /// The path or URL to use on development.
  602. #[serde(default = "default_dev_path")]
  603. pub dev_path: AppUrl,
  604. /// the path to the app's dist dir. This path must contain your index.html file.
  605. #[serde(default = "default_dist_dir")]
  606. pub dist_dir: AppUrl,
  607. /// a shell command to run before `tauri dev` kicks in
  608. pub before_dev_command: Option<String>,
  609. /// a shell command to run before `tauri build` kicks in
  610. pub before_build_command: Option<String>,
  611. /// features passed to `cargo` commands
  612. pub features: Option<Vec<String>>,
  613. /// Whether we should inject the Tauri API on `window.__TAURI__` or not.
  614. #[serde(default)]
  615. pub with_global_tauri: bool,
  616. }
  617. fn default_dev_path() -> AppUrl {
  618. AppUrl::Url("".to_string())
  619. }
  620. fn default_dist_dir() -> AppUrl {
  621. AppUrl::Url("../dist".to_string())
  622. }
  623. type JsonObject = HashMap<String, JsonValue>;
  624. /// The tauri.conf.json mapper.
  625. #[skip_serializing_none]
  626. #[derive(Debug, PartialEq, Clone, Deserialize, Serialize, JsonSchema)]
  627. #[serde(rename_all = "camelCase", deny_unknown_fields)]
  628. pub struct Config {
  629. /// Package settings.
  630. #[serde(default)]
  631. pub package: PackageConfig,
  632. /// The Tauri configuration.
  633. #[serde(default)]
  634. pub tauri: TauriConfig,
  635. /// The build configuration.
  636. #[serde(default = "default_build")]
  637. pub build: BuildConfig,
  638. /// The plugins config.
  639. #[serde(default)]
  640. pub plugins: HashMap<String, JsonObject>,
  641. }
  642. fn default_build() -> BuildConfig {
  643. BuildConfig {
  644. runner: None,
  645. dev_path: default_dev_path(),
  646. dist_dir: default_dist_dir(),
  647. before_dev_command: None,
  648. before_build_command: None,
  649. features: None,
  650. with_global_tauri: false,
  651. }
  652. }
  653. fn default_updater() -> UpdaterConfig {
  654. UpdaterConfig {
  655. active: false,
  656. dialog: Some(true),
  657. endpoints: None,
  658. pubkey: None,
  659. }
  660. }