process-ipc-message-fn.js 859 B

12345678910111213141516171819202122232425262728293031
  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 (message instanceof ArrayBuffer || ArrayBuffer.isView(message) || Array.isArray(message)) {
  7. return {
  8. contentType: 'application/octet-stream',
  9. data: message
  10. }
  11. } else {
  12. const data = JSON.stringify(message, (_k, val) => {
  13. if (val instanceof Map) {
  14. let o = {};
  15. val.forEach((v, k) => o[k] = v);
  16. return o;
  17. } else if (val instanceof Object && '__TAURI_CHANNEL_MARKER__' in val && typeof val.id === 'number') {
  18. return `__CHANNEL__:${val.id}`
  19. } else {
  20. return val;
  21. }
  22. })
  23. return {
  24. contentType: 'application/json',
  25. data
  26. }
  27. }
  28. })