mirror of
https://github.com/danielsogl/awesome-cordova-plugins.git
synced 2025-02-22 01:19:36 +08:00
chore(): replace try/catch with better approach (#956)
* chore(): replace try/catch with better approach * optimize last commit
This commit is contained in:
parent
77d6308bca
commit
5981622f3a
@ -108,7 +108,7 @@ function callCordovaPlugin(pluginObj: any, methodName: string, args: any[], opts
|
|||||||
|
|
||||||
let pluginInstance = getPlugin(pluginObj.pluginRef);
|
let pluginInstance = getPlugin(pluginObj.pluginRef);
|
||||||
|
|
||||||
if (!pluginInstance) {
|
if (!pluginInstance || !pluginInstance.hasOwnProperty(methodName)) {
|
||||||
// Do this check in here in the case that the Web API for this plugin is available (for example, Geolocation).
|
// Do this check in here in the case that the Web API for this plugin is available (for example, Geolocation).
|
||||||
if (!window.cordova) {
|
if (!window.cordova) {
|
||||||
cordovaWarn(pluginObj.pluginName, methodName);
|
cordovaWarn(pluginObj.pluginName, methodName);
|
||||||
@ -123,16 +123,7 @@ function callCordovaPlugin(pluginObj: any, methodName: string, args: any[], opts
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Illegal invocation needs window context
|
return pluginInstance[methodName].apply(pluginInstance, args);
|
||||||
let value;
|
|
||||||
try {
|
|
||||||
value = get(window, pluginObj.pluginRef)[methodName].apply(pluginInstance, args);
|
|
||||||
} catch (e) {
|
|
||||||
value = {
|
|
||||||
error: 'cordova_not_available'
|
|
||||||
};
|
|
||||||
}
|
|
||||||
return value;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user