Bläddra i källkod

docs(tauri): document all feature flags, add test (#3947)

Lucas Fernandes Nogueira 3 år sedan
förälder
incheckning
582bdfccbc

+ 1 - 0
core/tauri/Cargo.toml

@@ -116,6 +116,7 @@ serde_json = "1.0"
 tauri = { path = ".", default-features = false, features = [ "wry" ] }
 tokio-test = "0.4.2"
 tokio = { version = "1.16", features = [ "full" ] }
+cargo_toml = "0.11"
 
 [features]
 default = [ "wry", "compression", "objc-exception", "ayatana-tray" ]

+ 0 - 1
core/tauri/build.rs

@@ -97,7 +97,6 @@ fn main() {
     // process
     process_all: { any(api_all, feature = "process-all") },
     process_relaunch: { any(protocol_all, feature = "process-relaunch") },
-    process_relaunch_dangerous_allow_symlink_macos: { feature = "process-relaunch-dangerous-allow-symlink-macos" },
     process_exit: { any(protocol_all, feature = "process-exit") },
 
     // clipboard

+ 38 - 1
core/tauri/src/lib.rs

@@ -11,20 +11,32 @@
 //! The following are a list of [Cargo features](https://doc.rust-lang.org/stable/cargo/reference/manifest.html#the-features-section) that can be enabled or disabled:
 //!
 //! - **wry** *(enabled by default)*: Enables the [wry](https://github.com/tauri-apps/wry) runtime. Only disable it if you want a custom runtime.
+//! - **dox**: Internal feature to generate Rust documentation without linking on Linux.
+//! - **objc-exception**: Wrap each msg_send! in a @try/@catch and panics if an exception is caught, preventing Objective-C from unwinding into Rust.
 //! - **isolation**: Enables the isolation pattern. Enabled by default if the `tauri > pattern > use` config option is set to `isolation` on the `tauri.conf.json` file.
 //! - **custom-protocol**: Feature managed by the Tauri CLI. When enabled, Tauri assumes a production environment instead of a development one.
 //! - **updater**: Enables the application auto updater. Enabled by default if the `updater` config is defined on the `tauri.conf.json` file.
 //! - **devtools**: Enables the developer tools (Web inspector) and [`Window::open_devtools`]. Enabled by default on debug builds.
 //! On macOS it uses private APIs, so you can't enable it if your app will be published to the App Store.
+//! - **shell-open-api**: Enables the [`api::shell`] module.
 //! - **http-api**: Enables the [`api::http`] module.
+//! - **http-multipart**: Adds support to `multipart/form-data` requests.
 //! - **reqwest-client**: Uses `reqwest` as HTTP client on the `http` APIs. Improves performance, but increases the bundle size.
-//! - **command**: Enables the [`api::process::Command`] APIs.
+//! - **process-command-api**: Enables the [`api::process::Command`] APIs.
+//! - **process-relaunch-dangerous-allow-symlink-macos**: Allows the [`api::process::current_binary`] function to allow symlinks on macOS (this is dangerous, see the Security section in the documentation website).
 //! - **dialog**: Enables the [`api::dialog`] module.
 //! - **notification**: Enables the [`api::notification`] module.
+//! - **fs-extract-api**: Enabled the `tauri::api::file::Extract` API.
 //! - **cli**: Enables usage of `clap` for CLI argument parsing. Enabled by default if the `cli` config is defined on the `tauri.conf.json` file.
 //! - **system-tray**: Enables application system tray API. Enabled by default if the `systemTray` config is defined on the `tauri.conf.json` file.
+//! - **ayatana-tray** *(enabled by default)*: Use libayatana-appindicator for system tray on Linux.
+//! - **gtk-tray**: Use libappindicator3-1 for system tray on Linux. To enable this, you need to disable the default features.
 //! - **macos-private-api**: Enables features only available in **macOS**'s private APIs, currently the `transparent` window functionality and the `fullScreenEnabled` preference setting to `true`. Enabled by default if the `tauri > macosPrivateApi` config flag is set to `true` on the `tauri.conf.json` file.
 //! - **window-data-url**: Enables usage of data URLs on the webview.
+//! - **compression** *(enabled by default): Enables asset compression. You should only disable this if you want faster compile times in release builds - it produces larger binaries.
+//! - **config-json5**: Adds support to JSON5 format for `tauri.conf.json`.
+//! - **icon-ico**: Adds support to set `.ico` window icons. Enables [`Icon::File`] and [`Icon::Raw`] variants.
+//! - **icon-png**: Adds support to set `.png` window icons. Enables [`Icon::File`] and [`Icon::Raw`] variants.
 //!
 //! ## Cargo allowlist features
 //!
@@ -124,6 +136,10 @@
 //! - **window-set-focus**: Enables the [`setFocus` API](https://tauri.studio/en/docs/api/js/classes/window.WebviewWindow#setfocus).
 //! - **window-set-icon**: Enables the [`setIcon` API](https://tauri.studio/en/docs/api/js/classes/window.WebviewWindow#seticon).
 //! - **window-set-skip-taskbar**: Enables the [`setSkipTaskbar` API](https://tauri.studio/en/docs/api/js/classes/window.WebviewWindow#setskiptaskbar).
+//! - **window-set-cursor-grab**: Enables the [`setCursorGrab` API](https://tauri.studio/en/docs/api/js/classes/window.WebviewWindow#setcursorgrab).
+//! - **window-set-cursor-visible**: Enables the [`setCursorVisible` API](https://tauri.studio/en/docs/api/js/classes/window.WebviewWindow#setcursorvisible).
+//! - **window-set-cursor-icon**: Enables the [`setCursorIcon` API](https://tauri.studio/en/docs/api/js/classes/window.WebviewWindow#setcursoricon).
+//! - **window-set-cursor-position**: Enables the [`setCursorPosition` API](https://tauri.studio/en/docs/api/js/classes/window.WebviewWindow#setcursorposition).
 //! - **window-start-dragging**: Enables the [`startDragging` API](https://tauri.studio/en/docs/api/js/classes/window.WebviewWindow#startdragging).
 //! - **window-print**: Enables the [`print` API](https://tauri.studio/en/docs/api/js/classes/window.WebviewWindow#print).
 
@@ -783,6 +799,27 @@ pub(crate) mod sealed {
 #[cfg(test)]
 pub mod test;
 
+#[cfg(test)]
+mod tests {
+  #[test]
+  fn features_are_documented() {
+    use cargo_toml::Manifest;
+    use std::{env::var, fs::read_to_string, path::PathBuf};
+    // this env var is always set by Cargo
+    let manifest_dir = PathBuf::from(var("CARGO_MANIFEST_DIR").unwrap());
+    let manifest =
+      Manifest::from_path(manifest_dir.join("Cargo.toml")).expect("failed to parse Cargo manifest");
+
+    let lib_code = read_to_string(manifest_dir.join("src/lib.rs")).expect("failed to read lib.rs");
+
+    for (f, _) in manifest.features {
+      if !(f.starts_with("__") || f == "default" || lib_code.contains(&format!("*{}**", f))) {
+        panic!("Feature {} is not documented", f);
+      }
+    }
+  }
+}
+
 #[cfg(test)]
 mod test_utils {
   use proptest::prelude::*;

Filskillnaden har hållts tillbaka eftersom den är för stor
+ 0 - 0
examples/api/dist/assets/index.js


Filskillnaden har hållts tillbaka eftersom den är för stor
+ 0 - 0
examples/api/dist/assets/vendor.js


+ 1 - 1
examples/api/src-tauri/Cargo.toml

@@ -12,7 +12,7 @@ tauri-build = { path = "../../../core/tauri-build", features = ["isolation"] }
 [dependencies]
 serde_json = "1.0"
 serde = { version = "1.0", features = [ "derive" ] }
-tauri = { path = "../../../core/tauri", default-features = false, features = ["api-all", "http-multipart", "reqwest-client", "cli", "compression", "icon-ico", "icon-png", "isolation", "macos-private-api", "objc-exception", "system-tray", "updater", "wry"] }
+tauri = { path = "../../../core/tauri", default-features = false, features = ["api-all", "cli", "compression", "http-multipart", "icon-ico", "icon-png", "isolation", "macos-private-api", "objc-exception", "reqwest-client", "system-tray", "updater", "wry"] }
 tiny_http = "0.11"
 
 [features]

+ 6 - 6
examples/api/yarn.lock

@@ -23,9 +23,9 @@
     svelte-hmr "^0.14.7"
 
 "@tauri-apps/api@../../tooling/api/dist":
-  version "1.0.0-rc.0"
+  version "1.0.0-rc.3"
   dependencies:
-    type-fest "2.11.2"
+    type-fest "2.12.2"
 
 "@zerodevx/svelte-json-view@0.2.0":
   version "0.2.0"
@@ -267,10 +267,10 @@ svelte@3.35.0:
   resolved "https://registry.yarnpkg.com/svelte/-/svelte-3.35.0.tgz#e0d0ba60c4852181c2b4fd851194be6fda493e65"
   integrity sha512-gknlZkR2sXheu/X+B7dDImwANVvK1R0QGQLd8CNIfxxGPeXBmePnxfzb6fWwTQRsYQG7lYkZXvpXJvxvpsoB7g==
 
-type-fest@2.11.2:
-  version "2.11.2"
-  resolved "https://registry.yarnpkg.com/type-fest/-/type-fest-2.11.2.tgz#5534a919858bc517492cd3a53a673835a76d2e71"
-  integrity sha512-reW2Y2Mpn0QNA/5fvtm5doROLwDPu2zOm5RtY7xQQS05Q7xgC8MOZ3yPNaP9m/s/sNjjFQtHo7VCNqYW2iI+Ig==
+type-fest@2.12.2:
+  version "2.12.2"
+  resolved "https://registry.yarnpkg.com/type-fest/-/type-fest-2.12.2.tgz#80a53614e6b9b475eb9077472fb7498dc7aa51d0"
+  integrity sha512-qt6ylCGpLjZ7AaODxbpyBZSs9fCI9SkL3Z9q2oxMBQhs/uyY+VD8jHA8ULCGmWQJlBgqvO3EJeAngOHD8zQCrQ==
 
 vite@^2.6.4:
   version "2.6.14"

+ 12 - 0
tooling/api/src/window.ts

@@ -1142,6 +1142,11 @@ class WindowManager extends WebviewWindowHandle {
    * There's no guarantee that the cursor will be hidden. You should
    * hide it by yourself if you want so.
    *
+   * #### Platform-specific
+   *
+   * - **Linux:** Unsupported.
+   * - **macOS:** This locks the cursor in a fixed location, which looks visually awkward.
+   *
    * @param grab `true` to grab the cursor icon, `false` to release it.
    * @returns A promise indicating the success or failure of the operation.
    */
@@ -1164,6 +1169,13 @@ class WindowManager extends WebviewWindowHandle {
   /**
    * Modifies the cursor's visibility.
    *
+   * #### Platform-specific
+   *
+   * - **Linux:** Unsupported.
+   * - **Windows:** The cursor is only hidden within the confines of the window.
+   * - **macOS:** The cursor is hidden as long as the window has input focus, even if the cursor is
+   *   outside of the window.
+   *
    * @param visible If `false`, this will hide the cursor. If `true`, this will show the cursor.
    * @returns A promise indicating the success or failure of the operation.
    */

Vissa filer visades inte eftersom för många filer har ändrats