mirror of
https://github.com/danielsogl/awesome-cordova-plugins.git
synced 2025-03-05 00:42:58 +08:00
Shit
This commit is contained in:
parent
eb0b857b96
commit
d934853b01
@ -1,2 +1,2 @@
|
||||
# ionic-native
|
||||
# Cordova Wrap
|
||||
Native plugins to replace ngCordova
|
||||
|
@ -13,14 +13,14 @@ function compile(watch) {
|
||||
var bundler = watchify(browserify()
|
||||
.require('./src/index.js', {
|
||||
entry: true,
|
||||
expose: 'ionic-native'
|
||||
expose: 'cordova-wrap'
|
||||
})
|
||||
.transform(babel, {presets: ['es2015']}));
|
||||
|
||||
function rebundle() {
|
||||
bundler.bundle()
|
||||
.on('error', function(err) { console.error(err); this.emit('end'); })
|
||||
.pipe(source('ionic-native.js'))
|
||||
.pipe(source('cordova-wrap.js'))
|
||||
.pipe(buffer())
|
||||
.pipe(sourcemaps.init({ loadMaps: true }))
|
||||
.pipe(sourcemaps.write('./'))
|
||||
|
10
package.json
10
package.json
@ -2,23 +2,25 @@
|
||||
"name": "ionic-native",
|
||||
"version": "1.0.0",
|
||||
"description": "Native plugins to replace ngCordova",
|
||||
"main": "gulpfile.js",
|
||||
"main": "dist/cordova-wrap.js",
|
||||
"directories": {
|
||||
"test": "test"
|
||||
},
|
||||
"dependencies": {
|
||||
"babel-polyfill": "^6.2.0",
|
||||
"babel-preset-es2015": "^6.1.18",
|
||||
"babelify": "^7.2.0",
|
||||
"browserify": "^12.0.1",
|
||||
"es6-promise": "^3.0.2",
|
||||
"gulp": "^3.9.0",
|
||||
"gulp-babel": "^6.1.0",
|
||||
"gulp-concat": "^2.6.0",
|
||||
"gulp-connect": "^2.2.0",
|
||||
"gulp-serve": "^1.2.0",
|
||||
"gulp-sourcemaps": "^1.6.0",
|
||||
"vinyl-buffer": "^1.0.0",
|
||||
"vinyl-source-stream": "^1.1.0",
|
||||
"watchify": "^3.6.1",
|
||||
"gulp-babel": "^6.1.0",
|
||||
"gulp-serve": "^1.2.0"
|
||||
"watchify": "^3.6.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"babel-preset-stage-0": "^6.1.18"
|
||||
|
3
src/cordova.js
vendored
3
src/cordova.js
vendored
@ -1,3 +1,6 @@
|
||||
import {Promise} from 'es6-promise';
|
||||
|
||||
|
||||
const promisifyCordova = (pluginObj, pluginName, methodName) => {
|
||||
return (...args) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
|
16
src/index.js
16
src/index.js
@ -10,25 +10,31 @@ let promised;
|
||||
function newPluginClass(config) {
|
||||
let obj = {
|
||||
installed: () => {
|
||||
return config.pluginRef && get(window, config.pluginRef);
|
||||
return !!obj.plugin();
|
||||
},
|
||||
|
||||
plugin: config.plugin
|
||||
// Get the plugin by checking the plugin ref path on window
|
||||
plugin: () => {
|
||||
return get(window, config.pluginRef)
|
||||
},
|
||||
|
||||
pluginName: config.plugin
|
||||
};
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
||||
// Go through each registered plugin
|
||||
for(let plugin of PluginConfig) {
|
||||
console.log('Plugin', plugin.className, plugin);
|
||||
for(let i = 0; i < PluginConfig.length; i++) {
|
||||
let plugin = PluginConfig[i];
|
||||
|
||||
// Create the wrapped class
|
||||
let cls = newPluginClass(plugin);
|
||||
|
||||
promised = plugin.promise || [];
|
||||
|
||||
for(let method of promised) {
|
||||
for(let j = 0; j < promised.length; j++) {
|
||||
let method = promised[j];
|
||||
let p = promisifyCordova(cls, plugin.id, method)
|
||||
cls[method] = p;
|
||||
}
|
||||
|
@ -12,10 +12,32 @@ export var PluginConfig = [
|
||||
promise: ['takePicture'],
|
||||
pluginRef: 'navigator.camera'
|
||||
},
|
||||
{
|
||||
id: 'statusbar',
|
||||
className: 'StatusBar',
|
||||
plugin: 'cordova-plugin-statusbar',
|
||||
pluginRef: 'StatusBar',
|
||||
promise: ['show', 'hide', 'styleDefault', 'styleLightContent', 'styleBlackTranslucent', 'styleBlackOpaque']
|
||||
},
|
||||
{
|
||||
id: 'applinks',
|
||||
className: 'AppLinks',
|
||||
plugin: 'com.lampa.startapp',
|
||||
pluginRef: 'navigator.startApp'
|
||||
pluginRef: 'navigator.startApp',
|
||||
promise: ['start', 'check']
|
||||
},
|
||||
{
|
||||
id: 'barcode',
|
||||
className: 'Barcode',
|
||||
plugin: 'phonegap-plugin-barcodescanner',
|
||||
pluginRef: 'cordova.plugins.barcodeScanner',
|
||||
promise: ['scan', 'encode']
|
||||
},
|
||||
{
|
||||
id: 'camera-roll',
|
||||
className: 'CameraRoll',
|
||||
plugin: 'cordova-plugin-camera-roll',
|
||||
pluginRef: 'CameraRoll',
|
||||
promise: ['saveToCameraRoll', 'getPhotos']
|
||||
},
|
||||
]
|
||||
|
@ -1,13 +1,35 @@
|
||||
console.log(window.Native);
|
||||
|
||||
document.addEventListener('deviceready', function() {
|
||||
|
||||
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) {
|
||||
console.log('ERROR');
|
||||
});
|
||||
console.log(window.Native);
|
||||
|
||||
alert('in here!');
|
||||
|
||||
if(Native.Camera.installed()) {
|
||||
alert('here!');
|
||||
console.log('Camera installed');
|
||||
} else {
|
||||
alert('No cam');
|
||||
console.log('Camera not installed');
|
||||
}
|
||||
Native.Camera.takePicture().then(function(resp) {
|
||||
console.log('Got picture');
|
||||
}, function(err) {
|
||||
console.log('ERROR');
|
||||
});
|
||||
|
||||
if(Native.AppLinks.installed()) {
|
||||
console.log('AppLinks installed');
|
||||
} else {
|
||||
console.log('AppLinks not installed');
|
||||
}
|
||||
|
||||
if(Native.StatusBar.installed()) {
|
||||
console.log('StatusBar installed');
|
||||
Native.StatusBar.styleBlackTranslucent();
|
||||
} else {
|
||||
alert('No statusbar');
|
||||
console.log('StatusBar not installed');
|
||||
}
|
||||
|
||||
})
|
||||
|
@ -1,7 +1,7 @@
|
||||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<script src="../../dist/ionic-native.js"></script>
|
||||
<script src="../../dist/cordova-wrap.js"></script>
|
||||
<script src="app.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
|
Loading…
Reference in New Issue
Block a user