mirror of
https://github.com/danielsogl/awesome-cordova-plugins.git
synced 2025-05-06 02:12:57 +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 {PluginConfig} from './plugin-config'
|
||||||
import {promisifyCordova} from './cordova';
|
import {promisifyCordova} from './cordova';
|
||||||
|
|
||||||
let Wrapped = {
|
let wrappedPlugins = {}
|
||||||
}
|
|
||||||
|
|
||||||
let promised;
|
let promised;
|
||||||
|
|
||||||
|
// Go through each registered plugin
|
||||||
for(let plugin of PluginConfig) {
|
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) {
|
for(let method of promised) {
|
||||||
let p = promisifyCordova(plugin.id, method)
|
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 = [
|
export var PluginConfig = [
|
||||||
{
|
{
|
||||||
'id': 'camera',
|
id: 'camera',
|
||||||
'className': 'Camera',
|
className: 'Camera',
|
||||||
'plugin': 'cordova-plugin-camera',
|
plugin: 'cordova-plugin-camera',
|
||||||
'promise': ['takePicture'],
|
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);
|
console.log(window.Native);
|
||||||
|
|
||||||
|
|
||||||
|
if(Native.Camera.installed()) {
|
||||||
|
console.log('Camera installed');
|
||||||
|
} else {
|
||||||
|
console.log('Camera not installed');
|
||||||
|
}
|
||||||
Native.Camera.takePicture().then(function(resp) {
|
Native.Camera.takePicture().then(function(resp) {
|
||||||
console.log('Got picture');
|
console.log('Got picture');
|
||||||
}, function(err) {
|
}, function(err) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user