浏览代码

refactor: IPC handler [TRI-019] (#9)

Co-authored-by: Lucas Nogueira <lucas@tauri.studio>
Lucas Nogueira 3 年之前
父节点
当前提交
3420aa5031

+ 5 - 0
.changes/rpc-mod-refactor.md

@@ -0,0 +1,5 @@
+---
+"tauri": patch
+---
+
+**Breaking change:** Renamed the `rpc` module to `ipc`.

+ 6 - 0
.changes/runtime-ipc.md

@@ -0,0 +1,6 @@
+---
+"tauri-runtime": minor
+"tauri-runtime-wry": minor
+---
+
+**Breaking change:** Renamed the `RPC` interface to `IPC`.

+ 5 - 5
core/tauri/src/api/rpc.rs → core/tauri/src/api/ipc.rs

@@ -2,7 +2,7 @@
 // SPDX-License-Identifier: Apache-2.0
 // SPDX-License-Identifier: MIT
 
-//! Types and functions related to Remote Procedure Call(RPC).
+//! Types and functions related to Inter Procedure Call(IPC).
 //!
 //! This module includes utilities to send messages to the JS layer of the webview.
 
@@ -68,7 +68,7 @@ fn escape_json_parse(json: &RawValue) -> String {
 /// # Examples
 /// - With string literals:
 /// ```
-/// use tauri::api::rpc::format_callback;
+/// use tauri::api::ipc::format_callback;
 /// // callback with a string argument
 /// let cb = format_callback("callback-function-name", &"the string response").unwrap();
 /// assert!(cb.contains(r#"window["callback-function-name"]("the string response")"#));
@@ -76,7 +76,7 @@ fn escape_json_parse(json: &RawValue) -> String {
 ///
 /// - With types implement [`serde::Serialize`]:
 /// ```
-/// use tauri::api::rpc::format_callback;
+/// use tauri::api::ipc::format_callback;
 /// use serde::Serialize;
 ///
 /// // callback with large JSON argument
@@ -157,7 +157,7 @@ pub fn format_callback<T: Serialize, S: AsRef<str>>(
 ///
 /// # Examples
 /// ```
-/// use tauri::api::rpc::format_callback_result;
+/// use tauri::api::ipc::format_callback_result;
 /// let res: Result<u8, &str> = Ok(5);
 /// let cb = format_callback_result(res, "success_cb", "error_cb").expect("failed to format");
 /// assert!(cb.contains(r#"window["success_cb"](5)"#));
@@ -180,7 +180,7 @@ pub fn format_callback_result<T: Serialize, E: Serialize>(
 
 #[cfg(test)]
 mod test {
-  use crate::api::rpc::*;
+  use crate::api::ipc::*;
   use quickcheck_macros::quickcheck;
 
   #[test]

+ 1 - 1
core/tauri/src/api/mod.rs

@@ -10,9 +10,9 @@ pub mod dialog;
 pub mod dir;
 pub mod file;
 pub mod http;
+pub mod ipc;
 pub mod path;
 pub mod process;
-pub mod rpc;
 #[cfg(shell_open)]
 pub mod shell;
 pub mod version;

+ 1 - 1
core/tauri/src/endpoints/global_shortcut.rs

@@ -37,7 +37,7 @@ fn register_shortcut<R: Runtime>(
 ) -> crate::Result<()> {
   let accelerator = shortcut.clone();
   manager.register(&shortcut, move || {
-    let callback_string = crate::api::rpc::format_callback(&handler, &accelerator)
+    let callback_string = crate::api::ipc::format_callback(&handler, &accelerator)
       .expect("unable to serialize shortcut string to json");
     let _ = window.eval(callback_string.as_str());
   })?;

+ 1 - 1
core/tauri/src/endpoints/shell.rs

@@ -107,7 +107,7 @@ impl Cmd {
               if matches!(event, crate::api::process::CommandEvent::Terminated(_)) {
                 command_childs().lock().unwrap().remove(&pid);
               }
-              let js = crate::api::rpc::format_callback(on_event_fn.clone(), &event)
+              let js = crate::api::ipc::format_callback(on_event_fn.clone(), &event)
                 .expect("unable to serialize CommandEvent");
 
               let _ = window.eval(js.as_str());

+ 2 - 2
core/tauri/src/hooks.rs

@@ -3,7 +3,7 @@
 // SPDX-License-Identifier: MIT
 
 use crate::{
-  api::rpc::{format_callback, format_callback_result},
+  api::ipc::{format_callback, format_callback_result},
   app::App,
   runtime::Runtime,
   StateManager, Window,
@@ -228,7 +228,7 @@ pub struct InvokeMessage<R: Runtime> {
   pub(crate) window: Window<R>,
   /// Application managed state.
   pub(crate) state: Arc<StateManager>,
-  /// The RPC command.
+  /// The IPC command.
   pub(crate) command: String,
   /// The JSON argument passed on the invoke message.
   pub(crate) payload: JsonValue,

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

@@ -467,6 +467,7 @@ impl<R: Runtime> WindowManager<R> {
     let manager = self.clone();
     Box::new(move |window, request| {
       let window = Window::new(manager.clone(), window, app_handle.clone());
+
       match serde_json::from_str::<InvokePayload>(&request) {
         Ok(message) => {
           let _ = window.on_message(message);

文件差异内容过多而无法显示
+ 0 - 28
tooling/cli.rs/templates/plugin/with-api/webview-dist/index.js


部分文件因为文件数量过多而无法显示