瀏覽代碼

rename ToIPCKey to SERIALIZE_TO_IPC_FN

Lucas Nogueira 9 月之前
父節點
當前提交
6e79d484b5

File diff suppressed because it is too large
+ 0 - 0
crates/tauri/scripts/bundle.global.js


+ 7 - 7
crates/tauri/scripts/ipc.js

@@ -92,22 +92,22 @@
     // unlike `JSON.stringify`, we can't extend a type with a method similar to `toJSON`
     // so that `structuredClone` would use, so until https://github.com/whatwg/html/issues/7428
     // we manually call `toIPC`
-    function processToIPCKey(data) {
+    function serializeIpcPayload(data) {
       // if this value changes, make sure to update it in:
       // 1. process-ipc-message-fn.js
       // 2. core.ts
-      const ToIPCKey = '__TAURI_TO_IPC_KEY__'
+      const SERIALIZE_TO_IPC_FN = '__TAURI_TO_IPC_KEY__'
 
       if (
         typeof data === 'object' &&
         'constructor' in data &&
         data.constructor === Array
       ) {
-        return data.map((v) => processToIPCKey(v))
+        return data.map((v) => serializeIpcPayload(v))
       }
 
-      if (typeof data === 'object' && ToIPCKey in data) {
-        return data[ToIPCKey]()
+      if (typeof data === 'object' && SERIALIZE_TO_IPC_FN in data) {
+        return data[SERIALIZE_TO_IPC_FN]()
       }
 
       if (
@@ -117,7 +117,7 @@
       ) {
         const acc = {}
         Object.entries(data).forEach(([k, v]) => {
-          acc[k] = processToIPCKey(v)
+          acc[k] = serializeIpcPayload(v)
         })
         return acc
       }
@@ -125,7 +125,7 @@
       return data
     }
 
-    data.payload = processToIPCKey(data.payload)
+    data.payload = serializeIpcPayload(data.payload)
 
     isolation.frame.contentWindow.postMessage(
       data,

+ 3 - 3
crates/tauri/scripts/process-ipc-message-fn.js

@@ -19,7 +19,7 @@
       // if this value changes, make sure to update it in:
       // 1. ipc.js
       // 2. core.ts
-      const ToIPCKey = '__TAURI_TO_IPC_KEY__'
+      const SERIALIZE_TO_IPC_FN = '__TAURI_TO_IPC_KEY__'
 
       if (val instanceof Map) {
         return Object.fromEntries(val.entries())
@@ -33,8 +33,8 @@
         typeof val.id === 'number'
       ) {
         return `__CHANNEL__:${val.id}`
-      } else if (typeof val === "object" && ToIPCKey in val) {
-        return val[ToIPCKey]()
+      } else if (typeof val === "object" && SERIALIZE_TO_IPC_FN in val) {
+        return val[SERIALIZE_TO_IPC_FN]()
       } else {
         return val
       }

+ 4 - 4
packages/api/src/core.ts

@@ -274,7 +274,7 @@ export class Resource {
  * `UserId::String("id")` would be serialized into `{ String: "id" }`
  * and so we need to pass the same structure back to Rust
  * ```ts
- * import { ToIPCKey } from "@tauri-apps/api/core"
+ * import { SERIALIZE_TO_IPC_FN } from "@tauri-apps/api/core"
  *
  * class UserIdString {
  *   id
@@ -282,7 +282,7 @@ export class Resource {
  *     this.id = id
  *   }
  *
- *   [ToIPCKey]() {
+ *   [SERIALIZE_TO_IPC_FN]() {
  *     return { String: this.id }
  *   }
  * }
@@ -293,7 +293,7 @@ export class Resource {
  *     this.id = id
  *   }
  *
- *   [ToIPCKey]() {
+ *   [SERIALIZE_TO_IPC_FN]() {
  *     return { Number: this.id }
  *   }
  * }
@@ -306,7 +306,7 @@ export class Resource {
 // if this value changes, make sure to update it in:
 // 1. ipc.js
 // 2. process-ipc-message-fn.js
-export const ToIPCKey = '__TAURI_TO_IPC_KEY__'
+export const SERIALIZE_TO_IPC_FN = '__TAURI_TO_IPC_KEY__'
 
 function isTauri(): boolean {
   return 'isTauri' in window && !!window.isTauri

+ 9 - 9
packages/api/src/dpi.ts

@@ -2,7 +2,7 @@
 // SPDX-License-Identifier: Apache-2.0
 // SPDX-License-Identifier: MIT
 
-import { ToIPCKey } from './core'
+import { SERIALIZE_TO_IPC_FN } from './core'
 
 /**
  * A size represented in logical pixels.
@@ -70,7 +70,7 @@ class LogicalSize {
    *
    * @since 2.0.0
    */
-  [ToIPCKey]() {
+  [SERIALIZE_TO_IPC_FN]() {
     return {
       Logical: {
         width: this.width,
@@ -94,7 +94,7 @@ class LogicalSize {
    * @since 2.0.0
    */
   toJSON() {
-    return this[ToIPCKey]()
+    return this[SERIALIZE_TO_IPC_FN]()
   }
 }
 
@@ -160,7 +160,7 @@ class PhysicalSize {
    *
    * @since 2.0.0
    */
-  [ToIPCKey]() {
+  [SERIALIZE_TO_IPC_FN]() {
     return {
       Physical: {
         width: this.width,
@@ -184,7 +184,7 @@ class PhysicalSize {
    * @since 2.0.0
    */
   toJSON() {
-    return this[ToIPCKey]()
+    return this[SERIALIZE_TO_IPC_FN]()
   }
 }
 
@@ -254,7 +254,7 @@ class LogicalPosition {
    *
    * @since 2.0.0
    */
-  [ToIPCKey]() {
+  [SERIALIZE_TO_IPC_FN]() {
     return {
       Logical: {
         x: this.x,
@@ -278,7 +278,7 @@ class LogicalPosition {
    * @since 2.0.0
    */
   toJSON() {
-    return this[ToIPCKey]()
+    return this[SERIALIZE_TO_IPC_FN]()
   }
 }
 
@@ -329,7 +329,7 @@ class PhysicalPosition {
    *
    * @since 2.0.0
    */
-  [ToIPCKey]() {
+  [SERIALIZE_TO_IPC_FN]() {
     return {
       Physical: {
         x: this.x,
@@ -353,7 +353,7 @@ class PhysicalPosition {
    * @since 2.0.0
    */
   toJSON() {
-    return this[ToIPCKey]()
+    return this[SERIALIZE_TO_IPC_FN]()
   }
 }
 

Some files were not shown because too many files changed in this diff