Эх сурвалжийг харах

refactor!: remove `tauri::api` module (#7874)

* refactor!: remove `tauri::api` module

ref: https://github.com/tauri-apps/tauri/issues/7756

* change file

* fix builds
Amr Bashir 1 жил өмнө
parent
commit
092a561ca6

+ 5 - 0
.changes/tauri-api-removal.md

@@ -0,0 +1,5 @@
+---
+'tauri': 'major:breaking'
+---
+
+Removed `tauri::api` module as most apis have been moved to either a plugin or we recommend using other crates.

+ 0 - 15
core/tauri/src/api/error.rs

@@ -1,15 +0,0 @@
-// Copyright 2019-2023 Tauri Programme within The Commons Conservancy
-// SPDX-License-Identifier: Apache-2.0
-// SPDX-License-Identifier: MIT
-
-/// The result type of Tauri API module.
-pub type Result<T> = std::result::Result<T, Error>;
-
-/// The error type of Tauri API module.
-#[derive(thiserror::Error, Debug)]
-#[non_exhaustive]
-pub enum Error {
-  /// JSON error.
-  #[error(transparent)]
-  Json(#[from] serde_json::Error),
-}

+ 0 - 21
core/tauri/src/api/mod.rs

@@ -1,21 +0,0 @@
-// Copyright 2019-2023 Tauri Programme within The Commons Conservancy
-// SPDX-License-Identifier: Apache-2.0
-// SPDX-License-Identifier: MIT
-
-//! The Tauri API interface.
-
-mod error;
-
-pub use error::{Error, Result};
-// Not public API
-#[doc(hidden)]
-pub mod private {
-  pub use once_cell::sync::OnceCell;
-
-  pub trait AsTauriContext {
-    fn config() -> &'static crate::Config;
-    fn assets() -> &'static crate::utils::assets::EmbeddedAssets;
-    fn default_window_icon() -> Option<&'static [u8]>;
-    fn package_info() -> crate::PackageInfo;
-  }
-}

+ 0 - 10
core/tauri/src/api/os.rs

@@ -1,10 +0,0 @@
-// Copyright 2019-2023 Tauri Programme within The Commons Conservancy
-// SPDX-License-Identifier: Apache-2.0
-// SPDX-License-Identifier: MIT
-
-//! Types and functions related to operating system operations.
-
-/// Returns `Some(String)` with a `BCP-47` language tag inside. If the locale couldn’t be obtained, `None` is returned instead.
-pub fn locale() -> Option<String> {
-  sys_locale::get_locale()
-}

+ 0 - 3
core/tauri/src/error.rs

@@ -43,9 +43,6 @@ pub enum Error {
   /// Failed to serialize/deserialize.
   #[error("JSON error: {0}")]
   Json(#[from] serde_json::Error),
-  /// Failed to execute tauri API.
-  #[error("failed to execute API: {0}")]
-  FailedToExecuteApi(#[from] crate::api::Error),
   /// IO error.
   #[error("{0}")]
   Io(#[from] std::io::Error),

+ 4 - 4
core/tauri/src/ipc/format_callback.rs

@@ -44,7 +44,7 @@ fn serialize_js_with<T: Serialize, F: FnOnce(&str) -> String>(
   value: &T,
   options: serialize_to_javascript::Options,
   cb: F,
-) -> crate::api::Result<String> {
+) -> crate::Result<String> {
   // get a raw &str representation of a serialized json value.
   let string = serde_json::to_string(value)?;
   let raw = RawValue::from_string(string)?;
@@ -83,7 +83,7 @@ fn serialize_js_with<T: Serialize, F: FnOnce(&str) -> String>(
 /// but will serialize arrays and objects whose serialized JSON string is smaller than 1 GB and larger
 /// than 10 KiB with `JSON.parse('...')`.
 /// See [json-parse-benchmark](https://github.com/GoogleChromeLabs/json-parse-benchmark).
-pub fn format<T: Serialize>(function_name: CallbackFn, arg: &T) -> crate::api::Result<String> {
+pub fn format<T: Serialize>(function_name: CallbackFn, arg: &T) -> crate::Result<String> {
   serialize_js_with(arg, Default::default(), |arg| {
     format!(
       r#"
@@ -111,7 +111,7 @@ pub fn format_result<T: Serialize, E: Serialize>(
   result: Result<T, E>,
   success_callback: CallbackFn,
   error_callback: CallbackFn,
-) -> crate::api::Result<String> {
+) -> crate::Result<String> {
   match result {
     Ok(res) => format(success_callback, &res),
     Err(err) => format(error_callback, &err),
@@ -130,7 +130,7 @@ mod test {
     }
   }
 
-  fn serialize_js<T: Serialize>(value: &T) -> crate::api::Result<String> {
+  fn serialize_js<T: Serialize>(value: &T) -> crate::Result<String> {
     serialize_js_with(value, Default::default(), |v| v.into())
   }
 

+ 1 - 1
core/tauri/src/ipc/protocol.rs

@@ -228,7 +228,7 @@ fn handle_ipc_message<R: Runtime>(message: String, manager: &WindowManager<R>, l
             {
               fn responder_eval<R: Runtime>(
                 window: &crate::Window<R>,
-                js: crate::api::Result<String>,
+                js: crate::Result<String>,
                 error: CallbackFn,
               ) {
                 let eval_js = match js {

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

@@ -74,7 +74,6 @@ pub use swift_rs;
 pub use tauri_macros::mobile_entry_point;
 pub use tauri_macros::{command, generate_handler};
 
-pub mod api;
 pub(crate) mod app;
 pub mod async_runtime;
 pub mod command;

+ 2 - 1
examples/web/core/tauri/Cargo.toml

@@ -15,6 +15,7 @@ tauri-build = { path = "../../../../core/tauri-build", features = [] }
 [dependencies]
 api = { path = "../api" }
 tauri = { path = "../../../../core/tauri" }
+tauri-plugin-dialog = "2.0.0-alpha.2"
 
 [features]
-custom-protocol = [ "tauri/custom-protocol" ]
+custom-protocol = ["tauri/custom-protocol"]

+ 4 - 1
examples/web/core/tauri/src/main.rs

@@ -3,10 +3,13 @@
 // SPDX-License-Identifier: MIT
 
 #![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
+use tauri_plugin_dialog::DialogExt;
 
 #[tauri::command]
 fn greet(window: tauri::Window, name: String) {
-  tauri::api::dialog::message(Some(&window), "Tauri Example", api::greet(&name));
+  MessageDialogBuilder::new(window.dialog(), "Tauri Example")
+    .parent(&window)
+    .show();
 }
 
 fn main() {