process-ipc-message-fn.js 905 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. // Copyright 2019-2023 Tauri Programme within The Commons Conservancy
  2. // SPDX-License-Identifier: Apache-2.0
  3. // SPDX-License-Identifier: MIT
  4. // this is a function and not an iife so use it carefully
  5. (function (message) {
  6. if (
  7. message instanceof ArrayBuffer ||
  8. ArrayBuffer.isView(message) ||
  9. Array.isArray(message)
  10. ) {
  11. return {
  12. contentType: 'application/octet-stream',
  13. data: message
  14. }
  15. } else {
  16. const data = JSON.stringify(message, (_k, val) => {
  17. if (val instanceof Map) {
  18. let o = {}
  19. val.forEach((v, k) => (o[k] = v))
  20. return o
  21. } else if (
  22. val instanceof Object &&
  23. '__TAURI_CHANNEL_MARKER__' in val &&
  24. typeof val.id === 'number'
  25. ) {
  26. return `__CHANNEL__:${val.id}`
  27. } else {
  28. return val
  29. }
  30. })
  31. return {
  32. contentType: 'application/json',
  33. data
  34. }
  35. }
  36. })