Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor!: remove tauri::api module #7874

Merged
merged 3 commits into from
Sep 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changes/tauri-api-removal.md
Original file line number Diff line number Diff line change
@@ -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.
15 changes: 0 additions & 15 deletions core/tauri/src/api/error.rs

This file was deleted.

21 changes: 0 additions & 21 deletions core/tauri/src/api/mod.rs

This file was deleted.

10 changes: 0 additions & 10 deletions core/tauri/src/api/os.rs

This file was deleted.

3 changes: 0 additions & 3 deletions core/tauri/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
8 changes: 4 additions & 4 deletions core/tauri/src/ipc/format_callback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)?;
Expand Down Expand Up @@ -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#"
Expand Down Expand Up @@ -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),
Expand All @@ -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())
}

Expand Down
2 changes: 1 addition & 1 deletion core/tauri/src/ipc/protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,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 {
Expand Down
1 change: 0 additions & 1 deletion core/tauri/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion examples/web/core/tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
5 changes: 4 additions & 1 deletion examples/web/core/tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down