synapse.mjs 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. function s(t) {
  2. t.CapacitorUtils.Synapse = new Proxy(
  3. {},
  4. {
  5. get(e, o) {
  6. return new Proxy({}, {
  7. get(w, r) {
  8. return (c, p, n) => {
  9. const i = t.Capacitor.Plugins[o];
  10. if (i === void 0) {
  11. n(new Error(`Capacitor plugin ${o} not found`));
  12. return;
  13. }
  14. if (typeof i[r] != "function") {
  15. n(new Error(`Method ${r} not found in Capacitor plugin ${o}`));
  16. return;
  17. }
  18. (async () => {
  19. try {
  20. const a = await i[r](c);
  21. p(a);
  22. } catch (a) {
  23. n(a);
  24. }
  25. })();
  26. };
  27. }
  28. });
  29. }
  30. }
  31. );
  32. }
  33. function u(t) {
  34. t.CapacitorUtils.Synapse = new Proxy(
  35. {},
  36. {
  37. get(e, o) {
  38. return t.cordova.plugins[o];
  39. }
  40. }
  41. );
  42. }
  43. function y(t = !1) {
  44. window.CapacitorUtils = window.CapacitorUtils || {}, window.Capacitor !== void 0 && !t ? s(window) : window.cordova !== void 0 && u(window);
  45. }
  46. export {
  47. y as exposeSynapse
  48. };