config_definition.rs 32 KB

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