mirror of
https://github.com/danielsogl/awesome-cordova-plugins.git
synced 2025-01-19 08:32:52 +08:00
Better existence check
This commit is contained in:
parent
ded5bd5444
commit
975535e563
24
src/index.js
24
src/index.js
@ -6,6 +6,18 @@ let wrappedPlugins = {}
|
||||
|
||||
let promised;
|
||||
|
||||
function newPluginClass(config) {
|
||||
let obj = {
|
||||
installed: () => {
|
||||
return config.pluginRef && window.hasOwnProperty(config.pluginRef);
|
||||
}
|
||||
}
|
||||
|
||||
obj.pluginCheck = config.pluginCheck || function() { return false; };
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
||||
// Go through each registered plugin
|
||||
for(let plugin of PluginConfig) {
|
||||
console.log('Plugin', plugin.className, plugin);
|
||||
@ -24,18 +36,6 @@ for(let plugin of PluginConfig) {
|
||||
wrappedPlugins[plugin.className] = cls;
|
||||
}
|
||||
|
||||
function newPluginClass(config) {
|
||||
let obj = {
|
||||
installed: () => {
|
||||
return obj.pluginCheck();
|
||||
}
|
||||
}
|
||||
|
||||
obj.pluginCheck = config.pluginCheck || function() { return false; };
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
||||
export {wrappedPlugins};
|
||||
|
||||
window.Native = wrappedPlugins;
|
||||
|
@ -4,16 +4,12 @@ export var PluginConfig = [
|
||||
className: 'Camera',
|
||||
plugin: 'cordova-plugin-camera',
|
||||
promise: ['takePicture'],
|
||||
pluginCheck: () => {
|
||||
return !!navigator.camera;
|
||||
}
|
||||
pluginRef: 'navigator.camera'
|
||||
},
|
||||
{
|
||||
id: 'device',
|
||||
className: 'Device',
|
||||
plugin: 'cordova-plugin-device',
|
||||
pluginCheck: () => {
|
||||
return !!window.device;
|
||||
}
|
||||
pluginRef: 'device'
|
||||
}
|
||||
]
|
||||
|
Loading…
Reference in New Issue
Block a user