ソースを参照

Limit pub exposure in 2.x (#10158)

* hide `Invoke` from documentation

* make `Asset` non-exhaustive

* make `InvokeRequest` non-exhaustive

* mark `tauri_utils::platform::Target` non-exhaustive

* mark the runtime crates as unstable API

* Revert "mark the runtime crates as unstable API" [skip ci]

This reverts commit b8377222e374ac016f90a3ef47d8ec2a639edfcd.

* mark the runtime crates as unstable API

* Revert "mark the runtime crates as unstable API" [skip ci]

This reverts commit 9284897644b9213a6803da0906d954a856bd5a29.

* mark the runtime crates as unstable API

* mark tauri_utils::TitleBarStyle as `#[non_exhaustive]`

* mark `InvokeRequest` as non_exhaustive unless `unstable` feature

* mark config and acl items as unstable
chip 1 年間 前
コミット
eaec5fe9c1

+ 2 - 0
core/tauri-runtime-wry/README.md

@@ -24,6 +24,8 @@ Tauri apps can have custom menus and have tray-type interfaces. They can be upda
 ## This module
 
 This crate opens up direct systems-level interactions specifically for WRY, such as printing, monitor detection, and other windowing related tasks. `tauri-runtime` implementation for WRY.
+None of the exposed API of this crate is stable, and it may break semver
+compatibility in the future. The major version only signifies the intended Tauri version.
 
 To learn more about the details of how all of these pieces fit together, please consult this [ARCHITECTURE.md](https://github.com/tauri-apps/tauri/blob/dev/ARCHITECTURE.md) document.
 

+ 17 - 0
core/tauri-runtime-wry/src/lib.rs

@@ -5,6 +5,9 @@
 //! [![](https://github.com/tauri-apps/tauri/raw/dev/.github/splash.png)](https://tauri.app)
 //!
 //! The [`wry`] Tauri [`Runtime`].
+//!
+//! None of the exposed API of this crate is stable, and it may break semver
+//! compatibility in the future. The major version only signifies the intended Tauri version.
 
 #![doc(
   html_logo_url = "https://github.com/tauri-apps/tauri/raw/dev/app-icon.png",
@@ -1004,6 +1007,13 @@ impl WindowBuilder for WindowBuilderWrapper {
         self.inner = self.inner.with_titlebar_transparent(true);
         self.inner = self.inner.with_fullsize_content_view(true);
       }
+      unknown => {
+        #[cfg(feature = "tracing")]
+        tracing::warn!("unknown title bar style applied: {unknown}");
+
+        #[cfg(not(feature = "tracing"))]
+        eprintln!("unknown title bar style applied: {unknown}");
+      }
     }
     self
   }
@@ -2955,6 +2965,13 @@ fn handle_user_message<T: UserEvent>(
                 window.set_titlebar_transparent(true);
                 window.set_fullsize_content_view(true);
               }
+              unknown => {
+                #[cfg(feature = "tracing")]
+                tracing::warn!("unknown title bar style applied: {unknown}");
+
+                #[cfg(not(feature = "tracing"))]
+                eprintln!("unknown title bar style applied: {unknown}");
+              }
             };
           }
         }

+ 2 - 0
core/tauri-runtime/README.md

@@ -24,6 +24,8 @@ Tauri apps can have custom menus and have tray-type interfaces. They can be upda
 ## This module
 
 This is the glue layer between tauri itself and lower level webview libraries.
+None of the exposed API of this crate is stable, and it may break semver
+compatibility in the future. The major version only signifies the intended Tauri version.
 
 To learn more about the details of how all of these pieces fit together, please consult this [ARCHITECTURE.md](https://github.com/tauri-apps/tauri/blob/dev/ARCHITECTURE.md) document.
 

+ 3 - 0
core/tauri-runtime/src/lib.rs

@@ -5,6 +5,9 @@
 //! [![](https://github.com/tauri-apps/tauri/raw/dev/.github/splash.png)](https://tauri.app)
 //!
 //! Internal runtime between Tauri and the underlying webview runtime.
+//!
+//! None of the exposed API of this crate is stable, and it may break semver
+//! compatibility in the future. The major version only signifies the intended Tauri version.
 
 #![doc(
   html_logo_url = "https://github.com/tauri-apps/tauri/raw/dev/app-icon.png",

+ 17 - 0
core/tauri-utils/src/acl/mod.rs

@@ -3,6 +3,23 @@
 // SPDX-License-Identifier: MIT
 
 //! Access Control List types.
+//!
+//! # Stability
+//!
+//! This is a core functionality that is not considered part of the stable API.
+//! If you use it, note that it may include breaking changes in the future.
+//!
+//! These items are intended to be non-breaking from a de/serialization standpoint only.
+//! Using and modifying existing config values will try to avoid breaking changes, but they are
+//! free to add fields in the future - causing breaking changes for creating and full destructuring.
+//!
+//! To avoid this, [ignore unknown fields when destructuring] with the `{my, config, ..}` pattern.
+//! If you need to create the Rust config directly without deserializing, then create the struct
+//! the [Struct Update Syntax] with `..Default::default()`, which may need a
+//! `#[allow(clippy::needless_update)]` attribute if you are declaring all fields.
+//!
+//! [ignore unknown fields when destructuring]: https://doc.rust-lang.org/book/ch18-03-pattern-syntax.html#ignoring-remaining-parts-of-a-value-with-
+//! [Struct Update Syntax]: https://doc.rust-lang.org/book/ch05-01-defining-structs.html#creating-instances-from-other-instances-with-struct-update-syntax
 
 use serde::{Deserialize, Serialize};
 use std::{num::NonZeroU64, str::FromStr, sync::Arc};

+ 13 - 0
core/tauri-utils/src/config.rs

@@ -7,8 +7,21 @@
 //! It is pulled from a `tauri.conf.json` file and the [`Config`] struct is generated at compile time.
 //!
 //! # Stability
+//!
 //! This is a core functionality that is not considered part of the stable API.
 //! If you use it, note that it may include breaking changes in the future.
+//!
+//! These items are intended to be non-breaking from a de/serialization standpoint only.
+//! Using and modifying existing config values will try to avoid breaking changes, but they are
+//! free to add fields in the future - causing breaking changes for creating and full destructuring.
+//!
+//! To avoid this, [ignore unknown fields when destructuring] with the `{my, config, ..}` pattern.
+//! If you need to create the Rust config directly without deserializing, then create the struct
+//! the [Struct Update Syntax] with `..Default::default()`, which may need a
+//! `#[allow(clippy::needless_update)]` attribute if you are declaring all fields.
+//!
+//! [ignore unknown fields when destructuring]: https://doc.rust-lang.org/book/ch18-03-pattern-syntax.html#ignoring-remaining-parts-of-a-value-with-
+//! [Struct Update Syntax]: https://doc.rust-lang.org/book/ch05-01-defining-structs.html#creating-instances-from-other-instances-with-struct-update-syntax
 
 #[cfg(feature = "schema")]
 use schemars::JsonSchema;

+ 1 - 0
core/tauri-utils/src/lib.rs

@@ -159,6 +159,7 @@ pub use window_effects::{WindowEffect, WindowEffectState};
 /// How the window title bar should be displayed on macOS.
 #[derive(Debug, Clone, PartialEq, Eq, Copy)]
 #[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
+#[non_exhaustive]
 pub enum TitleBarStyle {
   /// A normal title bar.
   Visible,

+ 1 - 0
core/tauri-utils/src/platform.rs

@@ -19,6 +19,7 @@ mod starting_binary;
 #[derive(PartialEq, Eq, Copy, Debug, Clone, Serialize, Deserialize)]
 #[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
 #[serde(rename_all = "camelCase")]
+#[non_exhaustive]
 pub enum Target {
   /// MacOS.
   #[serde(rename = "macOS")]

+ 3 - 0
core/tauri/src/ipc/mod.rs

@@ -160,6 +160,9 @@ impl Response {
 }
 
 /// The message and resolver given to a custom command.
+///
+/// This struct is used internally by macros and is explicitly **NOT** stable.
+#[doc(hidden)]
 #[default_runtime(crate::Wry, wry)]
 pub struct Invoke<R: Runtime> {
   /// The message passed.

+ 18 - 0
core/tauri/src/manager/mod.rs

@@ -156,6 +156,7 @@ fn replace_csp_nonce(
 }
 
 /// A resolved asset.
+#[non_exhaustive]
 pub struct Asset {
   /// The asset bytes.
   pub bytes: Vec<u8>,
@@ -165,6 +166,23 @@ pub struct Asset {
   pub csp_header: Option<String>,
 }
 
+impl Asset {
+  /// The asset bytes.
+  pub fn bytes(&self) -> &[u8] {
+    &self.bytes
+  }
+
+  /// The asset's mime type.
+  pub fn mime_type(&self) -> &str {
+    &self.mime_type
+  }
+
+  /// The `Content-Security-Policy` header value.
+  pub fn csp_header(&self) -> Option<&str> {
+    self.csp_header.as_deref()
+  }
+}
+
 #[default_runtime(crate::Wry, wry)]
 pub struct AppManager<R: Runtime> {
   pub runtime_authority: Mutex<RuntimeAuthority>,

+ 7 - 0
core/tauri/src/webview/mod.rs

@@ -111,7 +111,14 @@ impl<'a> PageLoadPayload<'a> {
 }
 
 /// The IPC invoke request.
+///
+/// # Stability
+///
+/// This struct is **NOT** part of the public stable API and is only meant to be used
+/// by internal code and external testing/fuzzing tools. If not used with feature `unstable`, this
+/// struct is marked `#[non_exhaustive]` and is non-constructable externally.
 #[derive(Debug)]
+#[cfg_attr(not(feature = "unstable"), non_exhaustive)]
 pub struct InvokeRequest {
   /// The invoke command.
   pub cmd: String,