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