From ec21c97c38663498e26c4da88b7755e1534848ec Mon Sep 17 00:00:00 2001 From: jcesarmobile Date: Mon, 26 Apr 2021 13:23:35 +0200 Subject: [PATCH 1/4] fix(core): Call native implementation before web implementation --- core/src/runtime.ts | 33 +++++++++++++++------------------ 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/core/src/runtime.ts b/core/src/runtime.ts index cf6cad9fb7..daee4bea54 100644 --- a/core/src/runtime.ts +++ b/core/src/runtime.ts @@ -116,25 +116,22 @@ export const createCapacitor = (win: WindowCapacitor): CapacitorInstance => { impl: any, prop: PropertyKey, ): ((...args: any[]) => any) => { - if (impl) { - return impl[prop]?.bind(impl); - } else if (pluginHeader) { - const methodHeader = pluginHeader.methods.find(m => prop === m.name); - - if (methodHeader) { - if (methodHeader.rtype === 'promise') { - return (options: any) => - cap.nativePromise(pluginName, prop.toString(), options); - } else { - return (options: any, callback: any) => - cap.nativeCallback( - pluginName, - prop.toString(), - options, - callback, - ); - } + const methodHeader = pluginHeader.methods.find(m => prop === m.name); + if (pluginHeader && methodHeader) { + if (methodHeader.rtype === 'promise') { + return (options: any) => + cap.nativePromise(pluginName, prop.toString(), options); + } else { + return (options: any, callback: any) => + cap.nativeCallback( + pluginName, + prop.toString(), + options, + callback, + ); } + } else if (impl) { + return impl[prop]?.bind(impl); } else { throw new CapacitorException( `"${pluginName}" plugin is not implemented on ${platform}`, From f28a79c74ce45c54a35bc1bacf03251ed5caff5c Mon Sep 17 00:00:00 2001 From: jcesarmobile Date: Mon, 26 Apr 2021 13:35:50 +0200 Subject: [PATCH 2/4] fmt --- core/src/runtime.ts | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/core/src/runtime.ts b/core/src/runtime.ts index daee4bea54..1c355755f2 100644 --- a/core/src/runtime.ts +++ b/core/src/runtime.ts @@ -123,12 +123,7 @@ export const createCapacitor = (win: WindowCapacitor): CapacitorInstance => { cap.nativePromise(pluginName, prop.toString(), options); } else { return (options: any, callback: any) => - cap.nativeCallback( - pluginName, - prop.toString(), - options, - callback, - ); + cap.nativeCallback(pluginName, prop.toString(), options, callback); } } else if (impl) { return impl[prop]?.bind(impl); From 2a0b5b2a09fd431371367fc2479703ae42f783f9 Mon Sep 17 00:00:00 2001 From: jcesarmobile Date: Mon, 26 Apr 2021 16:32:46 +0200 Subject: [PATCH 3/4] don't throw plugin not implemented if it's just a method --- core/src/runtime.ts | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/core/src/runtime.ts b/core/src/runtime.ts index 1c355755f2..fe3665075e 100644 --- a/core/src/runtime.ts +++ b/core/src/runtime.ts @@ -116,14 +116,18 @@ export const createCapacitor = (win: WindowCapacitor): CapacitorInstance => { impl: any, prop: PropertyKey, ): ((...args: any[]) => any) => { - const methodHeader = pluginHeader.methods.find(m => prop === m.name); - if (pluginHeader && methodHeader) { - if (methodHeader.rtype === 'promise') { - return (options: any) => - cap.nativePromise(pluginName, prop.toString(), options); - } else { - return (options: any, callback: any) => - cap.nativeCallback(pluginName, prop.toString(), options, callback); + if (pluginHeader) { + const methodHeader = pluginHeader?.methods.find(m => prop === m.name); + if (methodHeader) { + if (methodHeader.rtype === 'promise') { + return (options: any) => + cap.nativePromise(pluginName, prop.toString(), options); + } else { + return (options: any, callback: any) => + cap.nativeCallback(pluginName, prop.toString(), options, callback); + } + } else if (impl) { + return impl[prop]?.bind(impl); } } else if (impl) { return impl[prop]?.bind(impl); From c6a3dccc2e2c6fc521e9b5d331bb59bc038cf1ee Mon Sep 17 00:00:00 2001 From: jcesarmobile Date: Mon, 26 Apr 2021 16:33:18 +0200 Subject: [PATCH 4/4] fmt --- core/src/runtime.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/core/src/runtime.ts b/core/src/runtime.ts index fe3665075e..17a4eadf76 100644 --- a/core/src/runtime.ts +++ b/core/src/runtime.ts @@ -124,7 +124,12 @@ export const createCapacitor = (win: WindowCapacitor): CapacitorInstance => { cap.nativePromise(pluginName, prop.toString(), options); } else { return (options: any, callback: any) => - cap.nativeCallback(pluginName, prop.toString(), options, callback); + cap.nativeCallback( + pluginName, + prop.toString(), + options, + callback, + ); } } else if (impl) { return impl[prop]?.bind(impl);