mirror of
https://github.com/danielsogl/awesome-cordova-plugins.git
synced 2025-02-21 00:23:00 +08:00
Plugin installed
This commit is contained in:
parent
b9bc5fd8e7
commit
ded5bd5444
32
src/index.js
32
src/index.js
@ -2,24 +2,40 @@ import {Plugins} from './plugins';
|
||||
import {PluginConfig} from './plugin-config'
|
||||
import {promisifyCordova} from './cordova';
|
||||
|
||||
let Wrapped = {
|
||||
}
|
||||
let wrappedPlugins = {}
|
||||
|
||||
let promised;
|
||||
|
||||
// Go through each registered plugin
|
||||
for(let plugin of PluginConfig) {
|
||||
console.log('Plugin', plugin.name, plugin);
|
||||
console.log('Plugin', plugin.className, plugin);
|
||||
|
||||
Wrapped[plugin.className] = {};
|
||||
// Create the wrapped class
|
||||
let cls = newPluginClass(plugin);
|
||||
|
||||
promised = plugin.promise;
|
||||
promised = plugin.promise || [];
|
||||
|
||||
for(let method of promised) {
|
||||
let p = promisifyCordova(plugin.id, method)
|
||||
Wrapped[plugin.className][method] = p;
|
||||
cls[method] = p;
|
||||
}
|
||||
|
||||
// Save the plugin object
|
||||
wrappedPlugins[plugin.className] = cls;
|
||||
}
|
||||
|
||||
export {Wrapped};
|
||||
function newPluginClass(config) {
|
||||
let obj = {
|
||||
installed: () => {
|
||||
return obj.pluginCheck();
|
||||
}
|
||||
}
|
||||
|
||||
window.Native = Wrapped;
|
||||
obj.pluginCheck = config.pluginCheck || function() { return false; };
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
||||
export {wrappedPlugins};
|
||||
|
||||
window.Native = wrappedPlugins;
|
||||
|
@ -1,8 +1,19 @@
|
||||
export var PluginConfig = [
|
||||
{
|
||||
'id': 'camera',
|
||||
'className': 'Camera',
|
||||
'plugin': 'cordova-plugin-camera',
|
||||
'promise': ['takePicture'],
|
||||
id: 'camera',
|
||||
className: 'Camera',
|
||||
plugin: 'cordova-plugin-camera',
|
||||
promise: ['takePicture'],
|
||||
pluginCheck: () => {
|
||||
return !!navigator.camera;
|
||||
}
|
||||
},
|
||||
{
|
||||
id: 'device',
|
||||
className: 'Device',
|
||||
plugin: 'cordova-plugin-device',
|
||||
pluginCheck: () => {
|
||||
return !!window.device;
|
||||
}
|
||||
}
|
||||
]
|
||||
|
@ -1,5 +1,11 @@
|
||||
console.log(window.Native);
|
||||
|
||||
|
||||
if(Native.Camera.installed()) {
|
||||
console.log('Camera installed');
|
||||
} else {
|
||||
console.log('Camera not installed');
|
||||
}
|
||||
Native.Camera.takePicture().then(function(resp) {
|
||||
console.log('Got picture');
|
||||
}, function(err) {
|
||||
|
Loading…
Reference in New Issue
Block a user