config_definition.rs 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880
  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. #[cfg(target_os = "linux")]
  6. use heck::KebabCase;
  7. use schemars::JsonSchema;
  8. use serde::{Deserialize, Serialize};
  9. use serde_json::Value as JsonValue;
  10. use serde_with::skip_serializing_none;
  11. use std::{collections::HashMap, path::PathBuf};
  12. #[derive(Debug, PartialEq, Clone, Deserialize, Serialize, JsonSchema)]
  13. #[serde(untagged)]
  14. pub enum BundleTarget {
  15. All(Vec<String>),
  16. One(String),
  17. }
  18. impl BundleTarget {
  19. #[allow(dead_code)]
  20. pub fn to_vec(&self) -> Vec<String> {
  21. match self {
  22. Self::All(list) => list.clone(),
  23. Self::One(i) => vec![i.clone()],
  24. }
  25. }
  26. }
  27. #[skip_serializing_none]
  28. #[derive(Debug, Default, PartialEq, Clone, Deserialize, Serialize, JsonSchema)]
  29. #[serde(rename_all = "camelCase", deny_unknown_fields)]
  30. pub struct DebConfig {
  31. /// The list of deb dependencies your application relies on.
  32. pub depends: Option<Vec<String>>,
  33. /// Enable the boostrapper script.
  34. #[serde(default)]
  35. pub use_bootstrapper: bool,
  36. /// The files to include on the package.
  37. #[serde(default)]
  38. pub files: HashMap<PathBuf, PathBuf>,
  39. }
  40. #[skip_serializing_none]
  41. #[derive(Debug, Default, PartialEq, Clone, Deserialize, Serialize, JsonSchema)]
  42. #[serde(rename_all = "camelCase", deny_unknown_fields)]
  43. pub struct MacConfig {
  44. /// A list of strings indicating any macOS X frameworks that need to be bundled with the application.
  45. ///
  46. /// If a name is used, ".framework" must be omitted and it will look for standard install locations. You may also use a path to a specific framework.
  47. pub frameworks: Option<Vec<String>>,
  48. /// A version string indicating the minimum macOS X version that the bundled application supports.
  49. pub minimum_system_version: Option<String>,
  50. /// Allows your application to communicate with the outside world.
  51. /// It should be a lowercase, without port and protocol domain name.
  52. pub exception_domain: Option<String>,
  53. /// The path to the license file to add to the DMG bundle.
  54. pub license: Option<String>,
  55. /// Enable the boostrapper script.
  56. #[serde(default)]
  57. pub use_bootstrapper: bool,
  58. /// Identity to use for code signing.
  59. pub signing_identity: Option<String>,
  60. /// Path to the entitlements file.
  61. pub entitlements: Option<String>,
  62. }
  63. fn default_language() -> String {
  64. "en-US".into()
  65. }
  66. #[derive(Debug, Default, PartialEq, Clone, Deserialize, Serialize, JsonSchema)]
  67. #[serde(rename_all = "camelCase", deny_unknown_fields)]
  68. pub struct WixConfig {
  69. /// The installer language. See https://docs.microsoft.com/en-us/windows/win32/msi/localizing-the-error-and-actiontext-tables.
  70. #[serde(default = "default_language")]
  71. pub language: String,
  72. /// A custom .wxs template to use.
  73. pub template: Option<PathBuf>,
  74. /// A list of paths to .wxs files with WiX fragments to use.
  75. #[serde(default)]
  76. pub fragment_paths: Vec<PathBuf>,
  77. /// The ComponentGroup element ids you want to reference from the fragments.
  78. #[serde(default)]
  79. pub component_group_refs: Vec<String>,
  80. /// The Component element ids you want to reference from the fragments.
  81. #[serde(default)]
  82. pub component_refs: Vec<String>,
  83. /// The FeatureGroup element ids you want to reference from the fragments.
  84. #[serde(default)]
  85. pub feature_group_refs: Vec<String>,
  86. /// The Feature element ids you want to reference from the fragments.
  87. #[serde(default)]
  88. pub feature_refs: Vec<String>,
  89. /// The Merge element ids you want to reference from the fragments.
  90. #[serde(default)]
  91. pub merge_refs: Vec<String>,
  92. /// Disables the Webview2 runtime installation after app install.
  93. #[serde(default)]
  94. pub skip_webview_install: bool,
  95. /// The path to the license file to render on the installer.
  96. ///
  97. /// Must be an RTF file, so if a different extension is provided, we convert it to the RTF format.
  98. pub license: Option<PathBuf>,
  99. #[serde(default)]
  100. pub enable_elevated_update_task: bool,
  101. /// Path to a bitmap file to use as the installation user interface banner.
  102. /// This bitmap will appear at the top of all but the first page of the installer.
  103. ///
  104. /// The required dimensions are 493px × 58px.
  105. pub banner_path: Option<PathBuf>,
  106. /// Path to a bitmap file to use on the installation user interface dialogs.
  107. /// It is used on the welcome and completion dialogs.
  108. /// The required dimensions are 493px × 312px.
  109. pub dialog_image_path: Option<PathBuf>,
  110. }
  111. #[derive(Debug, Default, PartialEq, Clone, Deserialize, Serialize, JsonSchema)]
  112. #[serde(rename_all = "camelCase", deny_unknown_fields)]
  113. pub struct WindowsConfig {
  114. /// Specifies the file digest algorithm to use for creating file signatures.
  115. /// Required for code signing. SHA-256 is recommended.
  116. pub digest_algorithm: Option<String>,
  117. /// Specifies the SHA1 hash of the signing certificate.
  118. pub certificate_thumbprint: Option<String>,
  119. /// Server to use during timestamping.
  120. pub timestamp_url: Option<String>,
  121. /// Configuration for the MSI generated with WiX.
  122. pub wix: Option<WixConfig>,
  123. }
  124. #[skip_serializing_none]
  125. #[derive(Debug, Default, PartialEq, Clone, Deserialize, Serialize, JsonSchema)]
  126. #[serde(rename_all = "camelCase", deny_unknown_fields)]
  127. pub struct PackageConfig {
  128. /// Application name. Automatically converted to kebab-case on Linux.
  129. pub product_name: Option<String>,
  130. /// Application version.
  131. pub version: Option<String>,
  132. }
  133. impl PackageConfig {
  134. #[allow(dead_code)]
  135. pub fn binary_name(&self) -> Option<String> {
  136. #[cfg(target_os = "linux")]
  137. {
  138. self.product_name.as_ref().map(|n| n.to_kebab_case())
  139. }
  140. #[cfg(not(target_os = "linux"))]
  141. {
  142. self.product_name.clone()
  143. }
  144. }
  145. }
  146. #[skip_serializing_none]
  147. #[derive(Debug, Default, PartialEq, Clone, Deserialize, Serialize, JsonSchema)]
  148. #[serde(rename_all = "camelCase", deny_unknown_fields)]
  149. pub struct BundleConfig {
  150. /// Whether we should build your app with tauri-bundler or plain `cargo build`
  151. #[serde(default)]
  152. pub active: bool,
  153. /// The bundle targets, currently supports ["deb", "app", "msi", "appimage", "dmg"] or "all"
  154. pub targets: Option<BundleTarget>,
  155. /// The app's identifier
  156. pub identifier: Option<String>,
  157. /// The app's icons
  158. pub icon: Option<Vec<String>>,
  159. /// App resources to bundle.
  160. /// Each resource is a path to a file or directory.
  161. /// Glob patterns are supported.
  162. pub resources: Option<Vec<String>>,
  163. /// A copyright string associated with your application.
  164. pub copyright: Option<String>,
  165. /// The application kind.
  166. pub category: Option<String>,
  167. /// A short description of your application.
  168. pub short_description: Option<String>,
  169. /// A longer, multi-line description of the application.
  170. pub long_description: Option<String>,
  171. /// Configuration for the Debian bundle.
  172. #[serde(default)]
  173. pub deb: DebConfig,
  174. /// Configuration for the macOS bundles.
  175. #[serde(rename = "macOS", default)]
  176. pub macos: MacConfig,
  177. /// A list of—either absolute or relative—paths to binaries to embed with your application.
  178. ///
  179. /// Note that Tauri will look for system-specific binaries following the pattern "binary-name{-target-triple}{.system-extension}".
  180. ///
  181. /// E.g. for the external binary "my-binary", Tauri looks for:
  182. ///
  183. /// - "my-binary-x86_64-pc-windows-msvc.exe" for Windows
  184. /// - "my-binary-x86_64-apple-darwin" for macOS
  185. /// - "my-binary-x86_64-unknown-linux-gnu" for Linux
  186. ///
  187. /// so don't forget to provide binaries for all targeted platforms.
  188. pub external_bin: Option<Vec<String>>,
  189. /// Configuration for the Windows bundle.
  190. #[serde(default)]
  191. pub windows: WindowsConfig,
  192. }
  193. /// A CLI argument definition
  194. #[skip_serializing_none]
  195. #[derive(Debug, PartialEq, Clone, Deserialize, Serialize, JsonSchema)]
  196. #[serde(rename_all = "camelCase", deny_unknown_fields)]
  197. pub struct CliArg {
  198. /// The short version of the argument, without the preceding -.
  199. ///
  200. /// NOTE: Any leading - characters will be stripped, and only the first non - character will be used as the short version.
  201. pub short: Option<char>,
  202. /// The unique argument name
  203. pub name: String,
  204. /// The argument description which will be shown on the help information.
  205. /// Typically, this is a short (one line) description of the arg.
  206. pub description: Option<String>,
  207. /// The argument long description which will be shown on the help information.
  208. /// Typically this a more detailed (multi-line) message that describes the argument.
  209. pub long_description: Option<String>,
  210. /// Specifies that the argument takes a value at run time.
  211. ///
  212. /// NOTE: values for arguments may be specified in any of the following methods
  213. /// - Using a space such as -o value or --option value
  214. /// - Using an equals and no space such as -o=value or --option=value
  215. /// - Use a short and no space such as -ovalue
  216. pub takes_value: Option<bool>,
  217. /// Specifies that the argument may appear more than once.
  218. ///
  219. /// - For flags, this results in the number of occurrences of the flag being recorded.
  220. /// For example -ddd or -d -d -d would count as three occurrences.
  221. /// - For options there is a distinct difference in multiple occurrences vs multiple values.
  222. /// For example, --opt val1 val2 is one occurrence, but two values. Whereas --opt val1 --opt val2 is two occurrences.
  223. pub multiple: Option<bool>,
  224. /// specifies that the argument may appear more than once.
  225. pub multiple_occurrences: Option<bool>,
  226. ///
  227. pub number_of_values: Option<u64>,
  228. /// Specifies a list of possible values for this argument.
  229. /// At runtime, the CLI verifies that only one of the specified values was used, or fails with an error message.
  230. pub possible_values: Option<Vec<String>>,
  231. /// Specifies the minimum number of values for this argument.
  232. /// For example, if you had a -f <file> argument where you wanted at least 2 'files',
  233. /// you would set `minValues: 2`, and this argument would be satisfied if the user provided, 2 or more values.
  234. pub min_values: Option<u64>,
  235. /// Specifies the maximum number of values are for this argument.
  236. /// For example, if you had a -f <file> argument where you wanted up to 3 'files',
  237. /// you would set .max_values(3), and this argument would be satisfied if the user provided, 1, 2, or 3 values.
  238. pub max_values: Option<u64>,
  239. /// Sets whether or not the argument is required by default.
  240. ///
  241. /// - Required by default means it is required, when no other conflicting rules have been evaluated
  242. /// - Conflicting rules take precedence over being required.
  243. pub required: Option<bool>,
  244. /// Sets an arg that override this arg's required setting
  245. /// i.e. this arg will be required unless this other argument is present.
  246. pub required_unless_present: Option<String>,
  247. /// Sets args that override this arg's required setting
  248. /// i.e. this arg will be required unless all these other arguments are present.
  249. pub required_unless_present_all: Option<Vec<String>>,
  250. /// Sets args that override this arg's required setting
  251. /// i.e. this arg will be required unless at least one of these other arguments are present.
  252. pub required_unless_present_any: Option<Vec<String>>,
  253. /// Sets a conflicting argument by name
  254. /// i.e. when using this argument, the following argument can't be present and vice versa.
  255. pub conflicts_with: Option<String>,
  256. /// The same as conflictsWith but allows specifying multiple two-way conflicts per argument.
  257. pub conflicts_with_all: Option<Vec<String>>,
  258. /// Tets an argument by name that is required when this one is present
  259. /// i.e. when using this argument, the following argument must be present.
  260. pub requires: Option<String>,
  261. /// Sts multiple arguments by names that are required when this one is present
  262. /// i.e. when using this argument, the following arguments must be present.
  263. pub requires_all: Option<Vec<String>>,
  264. /// Allows a conditional requirement with the signature [arg, value]
  265. /// the requirement will only become valid if `arg`'s value equals `${value}`.
  266. pub requires_if: Option<Vec<String>>,
  267. /// Allows specifying that an argument is required conditionally with the signature [arg, value]
  268. /// the requirement will only become valid if the `arg`'s value equals `${value}`.
  269. pub required_if_eq: Option<Vec<String>>,
  270. /// Requires that options use the --option=val syntax
  271. /// i.e. an equals between the option and associated value.
  272. pub require_equals: Option<bool>,
  273. /// The positional argument index, starting at 1.
  274. ///
  275. /// The index refers to position according to other positional argument.
  276. /// It does not define position in the argument list as a whole. When utilized with multiple=true,
  277. /// only the last positional argument may be defined as multiple (i.e. the one with the highest index).
  278. pub index: Option<u64>,
  279. }
  280. /// describes a CLI configuration
  281. #[skip_serializing_none]
  282. #[derive(Debug, PartialEq, Clone, Deserialize, Serialize, JsonSchema)]
  283. #[serde(rename_all = "camelCase", deny_unknown_fields)]
  284. pub struct CliConfig {
  285. /// command description which will be shown on the help information
  286. description: Option<String>,
  287. /// command long description which will be shown on the help information
  288. long_description: Option<String>,
  289. /// adds additional help information to be displayed in addition to auto-generated help
  290. /// this information is displayed before the auto-generated help information.
  291. /// this is often used for header information
  292. before_help: Option<String>,
  293. /// adds additional help information to be displayed in addition to auto-generated help
  294. /// this information is displayed after the auto-generated help information
  295. /// this is often used to describe how to use the arguments, or caveats to be noted.
  296. after_help: Option<String>,
  297. /// list of args for the command
  298. args: Option<Vec<CliArg>>,
  299. /// list of subcommands of this command.
  300. ///
  301. /// subcommands are effectively sub-apps, because they can contain their own arguments, subcommands, usage, etc.
  302. /// they also function just like the app command, in that they get their own auto generated help and usage
  303. subcommands: Option<HashMap<String, CliConfig>>,
  304. }
  305. #[derive(Debug, PartialEq, Clone, Deserialize, Serialize, JsonSchema)]
  306. #[serde(untagged)]
  307. pub enum Port {
  308. /// Port with a numeric value.
  309. Value(u16),
  310. /// Random port.
  311. Random,
  312. }
  313. /// The window configuration object.
  314. #[skip_serializing_none]
  315. #[derive(Debug, Default, PartialEq, Clone, Deserialize, Serialize, JsonSchema)]
  316. #[serde(rename_all = "camelCase", deny_unknown_fields)]
  317. pub struct WindowConfig {
  318. /// The window identifier.
  319. pub label: Option<String>,
  320. /// The window webview URL.
  321. pub url: Option<String>,
  322. /// Whether the file drop is enabled or not on the webview. By default it is enabled.
  323. ///
  324. /// Disabling it is required to use drag and drop on the frontend on Windows.
  325. #[serde(default = "default_file_drop_enabled")]
  326. pub file_drop_enabled: bool,
  327. /// Whether or not the window starts centered or not.
  328. #[serde(default)]
  329. pub center: bool,
  330. /// The horizontal position of the window's top left corner
  331. pub x: Option<f64>,
  332. /// The vertical position of the window's top left corner
  333. pub y: Option<f64>,
  334. /// The window width.
  335. pub width: Option<f64>,
  336. /// The window height.
  337. pub height: Option<f64>,
  338. /// The min window width.
  339. pub min_width: Option<f64>,
  340. /// The min window height.
  341. pub min_height: Option<f64>,
  342. /// The max window width.
  343. pub max_width: Option<f64>,
  344. /// The max window height.
  345. pub max_height: Option<f64>,
  346. /// Whether the window is resizable or not.
  347. #[serde(default)]
  348. pub resizable: bool,
  349. /// The window title.
  350. pub title: Option<String>,
  351. /// Whether the window starts as fullscreen or not.
  352. #[serde(default)]
  353. pub fullscreen: bool,
  354. /// Whether the window will be initially hidden or focused.
  355. #[serde(default = "default_focus")]
  356. pub focus: bool,
  357. /// Whether the window is transparent or not.
  358. #[serde(default)]
  359. pub transparent: bool,
  360. /// Whether the window is maximized or not.
  361. #[serde(default)]
  362. pub maximized: bool,
  363. /// Whether the window is visible or not.
  364. #[serde(default = "default_visible")]
  365. pub visible: bool,
  366. /// Whether the window should have borders and bars.
  367. #[serde(default = "default_decorations")]
  368. pub decorations: bool,
  369. /// Whether the window should always be on top of other windows.
  370. #[serde(default)]
  371. pub always_on_top: bool,
  372. /// Whether or not the window icon should be added to the taskbar.
  373. #[serde(default)]
  374. pub skip_taskbar: bool,
  375. }
  376. fn default_focus() -> bool {
  377. true
  378. }
  379. fn default_visible() -> bool {
  380. true
  381. }
  382. fn default_decorations() -> bool {
  383. true
  384. }
  385. fn default_file_drop_enabled() -> bool {
  386. true
  387. }
  388. #[skip_serializing_none]
  389. #[derive(Debug, Default, PartialEq, Clone, Deserialize, Serialize, JsonSchema)]
  390. #[serde(rename_all = "camelCase", deny_unknown_fields)]
  391. pub struct SecurityConfig {
  392. /// The Content Security Policy that will be injected on all HTML files.
  393. ///
  394. /// This is a really important part of the configuration since it helps you ensure your WebView is secured.
  395. /// See https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP.
  396. pub csp: Option<String>,
  397. }
  398. pub trait Allowlist {
  399. fn to_features(&self) -> Vec<&str>;
  400. }
  401. macro_rules! check_feature {
  402. ($self:ident, $features:ident, $flag:ident, $feature_name: expr) => {
  403. if $self.$flag {
  404. $features.push($feature_name)
  405. }
  406. };
  407. }
  408. #[derive(Debug, Default, PartialEq, Clone, Deserialize, Serialize, JsonSchema)]
  409. #[serde(rename_all = "camelCase", deny_unknown_fields)]
  410. pub struct FsAllowlistConfig {
  411. /// Use this flag to enable all file system API features.
  412. #[serde(default)]
  413. pub all: bool,
  414. /// Read text file from local filesystem.
  415. #[serde(default)]
  416. pub read_text_file: bool,
  417. /// Read binary file from local filesystem.
  418. #[serde(default)]
  419. pub read_binary_file: bool,
  420. /// Write text file to local filesystem.
  421. #[serde(default)]
  422. pub write_file: bool,
  423. /// Write binary file to local filesystem.
  424. #[serde(default)]
  425. pub write_binary_file: bool,
  426. /// Read directory from local filesystem.
  427. #[serde(default)]
  428. pub read_dir: bool,
  429. /// Copy file from local filesystem.
  430. #[serde(default)]
  431. pub copy_file: bool,
  432. /// Create directory from local filesystem.
  433. #[serde(default)]
  434. pub create_dir: bool,
  435. /// Remove directory from local filesystem.
  436. #[serde(default)]
  437. pub remove_dir: bool,
  438. /// Remove file from local filesystem.
  439. #[serde(default)]
  440. pub remove_file: bool,
  441. /// Rename file from local filesystem.
  442. #[serde(default)]
  443. pub rename_file: bool,
  444. }
  445. impl Allowlist for FsAllowlistConfig {
  446. fn to_features(&self) -> Vec<&str> {
  447. if self.all {
  448. vec!["fs-all"]
  449. } else {
  450. let mut features = Vec::new();
  451. check_feature!(self, features, read_text_file, "fs-read-text-file");
  452. check_feature!(self, features, read_binary_file, "fs-read-binary-file");
  453. check_feature!(self, features, write_file, "fs-write-file");
  454. check_feature!(self, features, write_binary_file, "fs-write-binary-file");
  455. check_feature!(self, features, read_dir, "fs-read-dir");
  456. check_feature!(self, features, copy_file, "fs-copy-file");
  457. check_feature!(self, features, create_dir, "fs-create-dir");
  458. check_feature!(self, features, remove_dir, "fs-remove-dir");
  459. check_feature!(self, features, remove_file, "fs-remove-file");
  460. check_feature!(self, features, rename_file, "fs-rename-file");
  461. features
  462. }
  463. }
  464. }
  465. #[derive(Debug, Default, PartialEq, Clone, Deserialize, Serialize, JsonSchema)]
  466. #[serde(rename_all = "camelCase", deny_unknown_fields)]
  467. pub struct WindowAllowlistConfig {
  468. /// Use this flag to enable all window API features.
  469. #[serde(default)]
  470. pub all: bool,
  471. /// Allows dynamic window creation.
  472. #[serde(default)]
  473. pub create: bool,
  474. }
  475. impl Allowlist for WindowAllowlistConfig {
  476. fn to_features(&self) -> Vec<&str> {
  477. if self.all {
  478. vec!["window-all"]
  479. } else {
  480. let mut features = Vec::new();
  481. check_feature!(self, features, create, "window-create");
  482. features
  483. }
  484. }
  485. }
  486. #[derive(Debug, Default, PartialEq, Clone, Deserialize, Serialize, JsonSchema)]
  487. #[serde(rename_all = "camelCase", deny_unknown_fields)]
  488. pub struct ShellAllowlistConfig {
  489. /// Use this flag to enable all shell API features.
  490. #[serde(default)]
  491. pub all: bool,
  492. /// Enable binary execution.
  493. #[serde(default)]
  494. pub execute: bool,
  495. /// Open URL with the user's default application.
  496. #[serde(default)]
  497. pub open: bool,
  498. }
  499. impl Allowlist for ShellAllowlistConfig {
  500. fn to_features(&self) -> Vec<&str> {
  501. if self.all {
  502. vec!["shell-all"]
  503. } else {
  504. let mut features = Vec::new();
  505. check_feature!(self, features, execute, "shell-execute");
  506. check_feature!(self, features, open, "shell-open");
  507. features
  508. }
  509. }
  510. }
  511. #[derive(Debug, Default, PartialEq, Clone, Deserialize, Serialize, JsonSchema)]
  512. #[serde(rename_all = "camelCase", deny_unknown_fields)]
  513. pub struct DialogAllowlistConfig {
  514. /// Use this flag to enable all dialog API features.
  515. #[serde(default)]
  516. pub all: bool,
  517. /// Open dialog window to pick files.
  518. #[serde(default)]
  519. pub open: bool,
  520. /// Open dialog window to pick where to save files.
  521. #[serde(default)]
  522. pub save: bool,
  523. }
  524. impl Allowlist for DialogAllowlistConfig {
  525. fn to_features(&self) -> Vec<&str> {
  526. if self.all {
  527. vec!["dialog-all"]
  528. } else {
  529. let mut features = Vec::new();
  530. check_feature!(self, features, open, "dialog-open");
  531. check_feature!(self, features, save, "dialog-save");
  532. features
  533. }
  534. }
  535. }
  536. #[derive(Debug, Default, PartialEq, Clone, Deserialize, Serialize, JsonSchema)]
  537. #[serde(rename_all = "camelCase", deny_unknown_fields)]
  538. pub struct HttpAllowlistConfig {
  539. /// Use this flag to enable all HTTP API features.
  540. #[serde(default)]
  541. pub all: bool,
  542. /// Allows making HTTP requests.
  543. #[serde(default)]
  544. pub request: bool,
  545. }
  546. impl Allowlist for HttpAllowlistConfig {
  547. fn to_features(&self) -> Vec<&str> {
  548. if self.all {
  549. vec!["http-all"]
  550. } else {
  551. let mut features = Vec::new();
  552. check_feature!(self, features, request, "http-request");
  553. features
  554. }
  555. }
  556. }
  557. #[derive(Debug, Default, PartialEq, Clone, Deserialize, Serialize, JsonSchema)]
  558. #[serde(rename_all = "camelCase", deny_unknown_fields)]
  559. pub struct NotificationAllowlistConfig {
  560. /// Use this flag to enable all notification API features.
  561. #[serde(default)]
  562. pub all: bool,
  563. }
  564. impl Allowlist for NotificationAllowlistConfig {
  565. fn to_features(&self) -> Vec<&str> {
  566. if self.all {
  567. vec!["notification-all"]
  568. } else {
  569. vec![]
  570. }
  571. }
  572. }
  573. #[derive(Debug, Default, PartialEq, Clone, Deserialize, Serialize, JsonSchema)]
  574. #[serde(rename_all = "camelCase", deny_unknown_fields)]
  575. pub struct GlobalShortcutAllowlistConfig {
  576. /// Use this flag to enable all global shortcut API features.
  577. #[serde(default)]
  578. pub all: bool,
  579. }
  580. impl Allowlist for GlobalShortcutAllowlistConfig {
  581. fn to_features(&self) -> Vec<&str> {
  582. if self.all {
  583. vec!["global-shortcut-all"]
  584. } else {
  585. vec![]
  586. }
  587. }
  588. }
  589. #[derive(Debug, Default, PartialEq, Clone, Deserialize, Serialize, JsonSchema)]
  590. #[serde(rename_all = "camelCase", deny_unknown_fields)]
  591. pub struct OsAllowlistConfig {
  592. /// Use this flag to enable all OS API features.
  593. #[serde(default)]
  594. pub all: bool,
  595. }
  596. impl Allowlist for OsAllowlistConfig {
  597. fn to_features(&self) -> Vec<&str> {
  598. if self.all {
  599. vec!["os-all"]
  600. } else {
  601. vec![]
  602. }
  603. }
  604. }
  605. #[derive(Debug, Default, PartialEq, Clone, Deserialize, Serialize, JsonSchema)]
  606. #[serde(rename_all = "camelCase", deny_unknown_fields)]
  607. pub struct PathAllowlistConfig {
  608. /// Use this flag to enable all path API features.
  609. #[serde(default)]
  610. pub all: bool,
  611. }
  612. impl Allowlist for PathAllowlistConfig {
  613. fn to_features(&self) -> Vec<&str> {
  614. if self.all {
  615. vec!["path-all"]
  616. } else {
  617. vec![]
  618. }
  619. }
  620. }
  621. #[derive(Debug, Default, PartialEq, Clone, Deserialize, Serialize, JsonSchema)]
  622. #[serde(rename_all = "camelCase", deny_unknown_fields)]
  623. pub struct AllowlistConfig {
  624. /// Use this flag to enable all API features.
  625. #[serde(default)]
  626. pub all: bool,
  627. /// File system API allowlist.
  628. #[serde(default)]
  629. pub fs: FsAllowlistConfig,
  630. /// Window API allowlist.
  631. #[serde(default)]
  632. pub window: WindowAllowlistConfig,
  633. /// Shell API allowlist.
  634. #[serde(default)]
  635. pub shell: ShellAllowlistConfig,
  636. /// Dialog API allowlist.
  637. #[serde(default)]
  638. pub dialog: DialogAllowlistConfig,
  639. /// HTTP API allowlist.
  640. #[serde(default)]
  641. pub http: HttpAllowlistConfig,
  642. /// Notification API allowlist.
  643. #[serde(default)]
  644. pub notification: NotificationAllowlistConfig,
  645. /// Global shortcut API allowlist.
  646. #[serde(default)]
  647. pub global_shortcut: GlobalShortcutAllowlistConfig,
  648. /// OS allowlist.
  649. #[serde(default)]
  650. pub os: OsAllowlistConfig,
  651. /// Path API allowlist.
  652. #[serde(default)]
  653. pub path: PathAllowlistConfig,
  654. }
  655. impl Allowlist for AllowlistConfig {
  656. fn to_features(&self) -> Vec<&str> {
  657. if self.all {
  658. vec!["api-all"]
  659. } else {
  660. let mut features = Vec::new();
  661. features.extend(self.fs.to_features());
  662. features.extend(self.window.to_features());
  663. features.extend(self.shell.to_features());
  664. features.extend(self.dialog.to_features());
  665. features.extend(self.http.to_features());
  666. features.extend(self.notification.to_features());
  667. features.extend(self.global_shortcut.to_features());
  668. features.extend(self.os.to_features());
  669. features.extend(self.path.to_features());
  670. features
  671. }
  672. }
  673. }
  674. /// The Tauri configuration object.
  675. #[skip_serializing_none]
  676. #[derive(Debug, Default, PartialEq, Clone, Deserialize, Serialize, JsonSchema)]
  677. #[serde(rename_all = "camelCase", deny_unknown_fields)]
  678. pub struct TauriConfig {
  679. /// The windows configuration.
  680. #[serde(default)]
  681. pub windows: Vec<WindowConfig>,
  682. /// The CLI configuration.
  683. pub cli: Option<CliConfig>,
  684. /// The bundler configuration.
  685. #[serde(default)]
  686. pub bundle: BundleConfig,
  687. /// The allowlist configuration.
  688. #[serde(default)]
  689. allowlist: AllowlistConfig,
  690. /// Security configuration.
  691. pub security: Option<SecurityConfig>,
  692. /// The updater configuration.
  693. #[serde(default = "default_updater")]
  694. pub updater: UpdaterConfig,
  695. /// Configuration for app system tray.
  696. pub system_tray: Option<SystemTrayConfig>,
  697. }
  698. impl TauriConfig {
  699. #[allow(dead_code)]
  700. pub fn features(&self) -> Vec<&str> {
  701. self.allowlist.to_features()
  702. }
  703. }
  704. #[skip_serializing_none]
  705. #[derive(Debug, Default, PartialEq, Clone, Deserialize, Serialize, JsonSchema)]
  706. #[serde(rename_all = "camelCase", deny_unknown_fields)]
  707. pub struct UpdaterConfig {
  708. /// Whether the updater is active or not.
  709. #[serde(default)]
  710. pub active: bool,
  711. /// Display built-in dialog or use event system if disabled.
  712. #[serde(default = "default_dialog")]
  713. pub dialog: Option<bool>,
  714. /// The updater endpoints.
  715. pub endpoints: Option<Vec<String>>,
  716. /// Optional pubkey.
  717. pub pubkey: Option<String>,
  718. }
  719. #[skip_serializing_none]
  720. #[derive(Debug, Default, PartialEq, Clone, Deserialize, Serialize, JsonSchema)]
  721. #[serde(rename_all = "camelCase", deny_unknown_fields)]
  722. pub struct SystemTrayConfig {
  723. /// Path to the icon to use on the system tray.
  724. ///
  725. /// It is forced to be a `.png` file on Linux and macOS, and a `.ico` file on Windows.
  726. pub icon_path: PathBuf,
  727. /// A Boolean value that determines whether the image represents a [template](https://developer.apple.com/documentation/appkit/nsimage/1520017-template?language=objc) image on macOS.
  728. #[serde(default)]
  729. pub icon_as_template: bool,
  730. }
  731. // We enable the unnecessary_wraps because we need
  732. // to use an Option for dialog otherwise the CLI schema will mark
  733. // the dialog as a required field which is not as we default it to true.
  734. #[allow(clippy::unnecessary_wraps)]
  735. fn default_dialog() -> Option<bool> {
  736. Some(true)
  737. }
  738. /// The `dev_path` and `dist_dir` options.
  739. #[derive(Debug, PartialEq, Clone, Deserialize, Serialize, JsonSchema)]
  740. #[serde(untagged, deny_unknown_fields)]
  741. pub enum AppUrl {
  742. /// The app's external URL, or the path to the directory containing the app assets.
  743. Url(String),
  744. /// An array of files to embed on the app.
  745. Files(Vec<PathBuf>),
  746. }
  747. impl std::fmt::Display for AppUrl {
  748. fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
  749. match self {
  750. Self::Url(url) => write!(f, "{}", url),
  751. Self::Files(files) => write!(f, "{}", serde_json::to_string(files).unwrap()),
  752. }
  753. }
  754. }
  755. /// The Build configuration object.
  756. #[skip_serializing_none]
  757. #[derive(Debug, PartialEq, Clone, Deserialize, Serialize, JsonSchema)]
  758. #[serde(rename_all = "camelCase", deny_unknown_fields)]
  759. pub struct BuildConfig {
  760. /// The binary used to build and run the application.
  761. pub runner: Option<String>,
  762. /// The path or URL to use on development.
  763. #[serde(default = "default_dev_path")]
  764. pub dev_path: AppUrl,
  765. /// the path to the app's dist dir. This path must contain your index.html file.
  766. #[serde(default = "default_dist_dir")]
  767. pub dist_dir: AppUrl,
  768. /// a shell command to run before `tauri dev` kicks in
  769. pub before_dev_command: Option<String>,
  770. /// a shell command to run before `tauri build` kicks in
  771. pub before_build_command: Option<String>,
  772. /// features passed to `cargo` commands
  773. pub features: Option<Vec<String>>,
  774. /// Whether we should inject the Tauri API on `window.__TAURI__` or not.
  775. #[serde(default)]
  776. pub with_global_tauri: bool,
  777. }
  778. fn default_dev_path() -> AppUrl {
  779. AppUrl::Url("".to_string())
  780. }
  781. fn default_dist_dir() -> AppUrl {
  782. AppUrl::Url("../dist".to_string())
  783. }
  784. type JsonObject = HashMap<String, JsonValue>;
  785. /// The tauri.conf.json mapper.
  786. #[skip_serializing_none]
  787. #[derive(Debug, PartialEq, Clone, Deserialize, Serialize, JsonSchema)]
  788. #[serde(rename_all = "camelCase", deny_unknown_fields)]
  789. pub struct Config {
  790. /// Package settings.
  791. #[serde(default)]
  792. pub package: PackageConfig,
  793. /// The Tauri configuration.
  794. #[serde(default)]
  795. pub tauri: TauriConfig,
  796. /// The build configuration.
  797. #[serde(default = "default_build")]
  798. pub build: BuildConfig,
  799. /// The plugins config.
  800. #[serde(default)]
  801. pub plugins: HashMap<String, JsonObject>,
  802. }
  803. fn default_build() -> BuildConfig {
  804. BuildConfig {
  805. runner: None,
  806. dev_path: default_dev_path(),
  807. dist_dir: default_dist_dir(),
  808. before_dev_command: None,
  809. before_build_command: None,
  810. features: None,
  811. with_global_tauri: false,
  812. }
  813. }
  814. fn default_updater() -> UpdaterConfig {
  815. UpdaterConfig {
  816. active: false,
  817. dialog: Some(true),
  818. endpoints: None,
  819. pubkey: None,
  820. }
  821. }