Skip to content

Commit 092a561

Browse files
authored
refactor!: remove tauri::api module (#7874)
* refactor!: remove `tauri::api` module ref: #7756 * change file * fix builds
1 parent c3ac1f8 commit 092a561

File tree

10 files changed

+16
-57
lines changed

10 files changed

+16
-57
lines changed

.changes/tauri-api-removal.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'tauri': 'major:breaking'
3+
---
4+
5+
Removed `tauri::api` module as most apis have been moved to either a plugin or we recommend using other crates.

core/tauri/src/api/error.rs

Lines changed: 0 additions & 15 deletions
This file was deleted.

core/tauri/src/api/mod.rs

Lines changed: 0 additions & 21 deletions
This file was deleted.

core/tauri/src/api/os.rs

Lines changed: 0 additions & 10 deletions
This file was deleted.

core/tauri/src/error.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,6 @@ pub enum Error {
4343
/// Failed to serialize/deserialize.
4444
#[error("JSON error: {0}")]
4545
Json(#[from] serde_json::Error),
46-
/// Failed to execute tauri API.
47-
#[error("failed to execute API: {0}")]
48-
FailedToExecuteApi(#[from] crate::api::Error),
4946
/// IO error.
5047
#[error("{0}")]
5148
Io(#[from] std::io::Error),

core/tauri/src/ipc/format_callback.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ fn serialize_js_with<T: Serialize, F: FnOnce(&str) -> String>(
4444
value: &T,
4545
options: serialize_to_javascript::Options,
4646
cb: F,
47-
) -> crate::api::Result<String> {
47+
) -> crate::Result<String> {
4848
// get a raw &str representation of a serialized json value.
4949
let string = serde_json::to_string(value)?;
5050
let raw = RawValue::from_string(string)?;
@@ -83,7 +83,7 @@ fn serialize_js_with<T: Serialize, F: FnOnce(&str) -> String>(
8383
/// but will serialize arrays and objects whose serialized JSON string is smaller than 1 GB and larger
8484
/// than 10 KiB with `JSON.parse('...')`.
8585
/// See [json-parse-benchmark](https://github.com/GoogleChromeLabs/json-parse-benchmark).
86-
pub fn format<T: Serialize>(function_name: CallbackFn, arg: &T) -> crate::api::Result<String> {
86+
pub fn format<T: Serialize>(function_name: CallbackFn, arg: &T) -> crate::Result<String> {
8787
serialize_js_with(arg, Default::default(), |arg| {
8888
format!(
8989
r#"
@@ -111,7 +111,7 @@ pub fn format_result<T: Serialize, E: Serialize>(
111111
result: Result<T, E>,
112112
success_callback: CallbackFn,
113113
error_callback: CallbackFn,
114-
) -> crate::api::Result<String> {
114+
) -> crate::Result<String> {
115115
match result {
116116
Ok(res) => format(success_callback, &res),
117117
Err(err) => format(error_callback, &err),
@@ -130,7 +130,7 @@ mod test {
130130
}
131131
}
132132

133-
fn serialize_js<T: Serialize>(value: &T) -> crate::api::Result<String> {
133+
fn serialize_js<T: Serialize>(value: &T) -> crate::Result<String> {
134134
serialize_js_with(value, Default::default(), |v| v.into())
135135
}
136136

core/tauri/src/ipc/protocol.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ fn handle_ipc_message<R: Runtime>(message: String, manager: &WindowManager<R>, l
228228
{
229229
fn responder_eval<R: Runtime>(
230230
window: &crate::Window<R>,
231-
js: crate::api::Result<String>,
231+
js: crate::Result<String>,
232232
error: CallbackFn,
233233
) {
234234
let eval_js = match js {

core/tauri/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ pub use swift_rs;
7474
pub use tauri_macros::mobile_entry_point;
7575
pub use tauri_macros::{command, generate_handler};
7676

77-
pub mod api;
7877
pub(crate) mod app;
7978
pub mod async_runtime;
8079
pub mod command;

examples/web/core/tauri/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ tauri-build = { path = "../../../../core/tauri-build", features = [] }
1515
[dependencies]
1616
api = { path = "../api" }
1717
tauri = { path = "../../../../core/tauri" }
18+
tauri-plugin-dialog = "2.0.0-alpha.2"
1819

1920
[features]
20-
custom-protocol = [ "tauri/custom-protocol" ]
21+
custom-protocol = ["tauri/custom-protocol"]

examples/web/core/tauri/src/main.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,13 @@
33
// SPDX-License-Identifier: MIT
44

55
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
6+
use tauri_plugin_dialog::DialogExt;
67

78
#[tauri::command]
89
fn greet(window: tauri::Window, name: String) {
9-
tauri::api::dialog::message(Some(&window), "Tauri Example", api::greet(&name));
10+
MessageDialogBuilder::new(window.dialog(), "Tauri Example")
11+
.parent(&window)
12+
.show();
1013
}
1114

1215
fn main() {

0 commit comments

Comments
 (0)