| 76 | }; |
| 77 | |
| 78 | const createPluginMethod = (impl: any, prop: PropertyKey): ((...args: any[]) => any) => { |
| 79 | if (pluginHeader) { |
| 80 | const methodHeader = pluginHeader?.methods.find((m) => prop === m.name); |
| 81 | if (methodHeader) { |
| 82 | if (methodHeader.rtype === 'promise') { |
| 83 | return (options: any) => cap.nativePromise(pluginName, prop.toString(), options); |
| 84 | } else { |
| 85 | return (options: any, callback: any) => cap.nativeCallback(pluginName, prop.toString(), options, callback); |
| 86 | } |
| 87 | } else if (impl) { |
| 88 | return impl[prop]?.bind(impl); |
| 89 | } |
| 90 | } else if (impl) { |
| 91 | return impl[prop]?.bind(impl); |
| 92 | } else { |
| 93 | throw new CapacitorException( |
| 94 | `"${pluginName}" plugin is not implemented on ${platform}`, |
| 95 | ExceptionCode.Unimplemented, |
| 96 | ); |
| 97 | } |
| 98 | }; |
| 99 | |
| 100 | const createPluginMethodWrapper = (prop: PropertyKey) => { |
| 101 | let remove: (() => void) | undefined; |