This commit is contained in:
Max Lynch
2015-11-28 16:17:04 -06:00
parent f7f1acb1b6
commit 33b56579b0
84 changed files with 691 additions and 80 deletions
+5 -2
View File
@@ -1,2 +1,5 @@
declare const promisifyCordova: (pluginObj: any, pluginName: any, methodName: any) => (...args: any[]) => any;
export { promisifyCordova };
export declare class Cordova {
static hasPlugin(pluginRef: string): boolean;
static plugin(pluginRef: string): any;
static promisify(pluginRef: any, pluginName: any, methodName: any, successIndex: any, errorIndex: any): (...args: any[]) => any;
}
+41 -26
View File
@@ -1,27 +1,42 @@
var promisifyCordova = function (pluginObj, pluginName, methodName) {
return function () {
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i - 0] = arguments[_i];
}
return new Promise(function (resolve, reject) {
if (!cordova) {
console.warn('Cordova: tried calling', '"' + pluginName + '.' + methodName + '"', 'but Cordova is not defined. Please make sure you have cordova.js included in your index.html file and you are running in a proper cordova environment');
reject({
error: 'cordova_not_available'
});
return;
}
if (!pluginObj.installed()) {
console.warn('Cordova: tried calling', '"' + pluginName + '.' + methodName + '"', 'but the ' + pluginObj.plugin + ' plugin is not installed.');
reject({
error: 'plugin_not_installed'
});
return;
}
console.log('Cordova: exec(' + pluginName + ', ' + methodName + ')');
cordova.exec(resolve, reject, pluginName, methodName, args);
});
var util_1 = require('./util');
var Cordova = (function () {
function Cordova() {
}
Cordova.hasPlugin = function (pluginRef) {
return !!this.plugin(pluginRef);
};
};
exports.promisifyCordova = promisifyCordova;
Cordova.plugin = function (pluginRef) {
return util_1.get(window, pluginRef);
};
Cordova.promisify = function (pluginRef, pluginName, methodName, successIndex, errorIndex) {
var _this = this;
return function () {
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i - 0] = arguments[_i];
}
return new Promise(function (resolve, reject) {
if (!window.cordova) {
console.warn('Cordova: tried calling', '"' + pluginName + '.' + methodName + '"', 'but Cordova is not defined. Please make sure you have cordova.js included in your index.html file and you are running in a proper cordova environment');
reject({
error: 'cordova_not_available'
});
return;
}
if (!_this.hasPlugin(pluginRef)) {
console.warn('Cordova: tried calling', '"' + pluginName + '.' + methodName + '"', 'but the ' + pluginName + ' plugin is not installed.');
reject({
error: 'plugin_not_installed'
});
return;
}
console.log('Cordova: exec(' + pluginName + ', ' + methodName + ')');
args[successIndex] = resolve;
args[errorIndex] = reject;
util_1.get(window, pluginRef)[methodName].apply(_this, args);
});
};
};
return Cordova;
})();
exports.Cordova = Cordova;
+1
View File
@@ -1 +1,2 @@
export * from './plugins/camera';
export * from './plugins/statusbar';
+1
View File
@@ -2,6 +2,7 @@ function __export(m) {
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
}
__export(require('./plugins/camera'));
__export(require('./plugins/statusbar'));
/*
let wrappedPlugins = {}
+6 -3
View File
@@ -1,3 +1,6 @@
export declare class Camera {
static getPicture: (...args: any[]) => any;
}
export declare var Camera: {
name: string;
plugin: string;
getPicture: (...args: any[]) => any;
cleanup: (...args: any[]) => any;
};
+8 -7
View File
@@ -1,9 +1,10 @@
var util_1 = require('../util');
var PLUGIN_REF = 'navigator.camera';
var Camera = (function () {
function Camera() {
}
Camera.getPicture = util_1.promisify(PLUGIN_REF, 'getPicture', 0, 1);
return Camera;
})();
exports.Camera = Camera;
exports.Camera = {
// Metadata
name: 'Camera',
plugin: 'cordova-plugin-camera',
// Methods
getPicture: util_1.promisify(PLUGIN_REF, 'getPicture', 0, 1),
cleanup: util_1.promisify(PLUGIN_REF, 'cleanup', 0, 1)
};
+13
View File
@@ -0,0 +1,13 @@
export declare var StatusBar: {
name: string;
plugin: string;
overlaysWebView: (...args: any[]) => any;
styleDefault: (...args: any[]) => any;
styleLightContent: (...args: any[]) => any;
styleBlackTranslucent: (...args: any[]) => any;
styleBlackOpaque: (...args: any[]) => any;
backgroundColorByName: (...args: any[]) => any;
backgroundColorByHexString: (...args: any[]) => any;
hide: (...args: any[]) => any;
show: (...args: any[]) => any;
};
+17
View File
@@ -0,0 +1,17 @@
var util_1 = require('../util');
var PLUGIN_REF = 'StatusBar';
exports.StatusBar = {
// Metadata
name: 'StatusBar',
plugin: 'cordova-plugin-statusbar',
// Methods
overlaysWebView: util_1.wrap(PLUGIN_REF, 'overlaysWebView'),
styleDefault: util_1.wrap(PLUGIN_REF, 'styleDefault'),
styleLightContent: util_1.wrap(PLUGIN_REF, 'styleLightContent'),
styleBlackTranslucent: util_1.wrap(PLUGIN_REF, 'styleBlackTranslucent'),
styleBlackOpaque: util_1.wrap(PLUGIN_REF, 'styleBlackOpaque'),
backgroundColorByName: util_1.wrap(PLUGIN_REF, 'backgroundColorByName'),
backgroundColorByHexString: util_1.wrap(PLUGIN_REF, 'backgroundColorByHexString'),
hide: util_1.wrap(PLUGIN_REF, 'hide'),
show: util_1.wrap(PLUGIN_REF, 'show')
};
+5
View File
@@ -0,0 +1,5 @@
export declare class Cordova {
static hasPlugin(pluginRef: string): boolean;
static plugin(pluginRef: string): any;
static promisify(pluginRef: any, pluginName: any, methodName: any, successIndex: any, errorIndex: any): (...args: any[]) => any;
}
+42
View File
@@ -0,0 +1,42 @@
var util_1 = require('./util');
var Cordova = (function () {
function Cordova() {
}
Cordova.hasPlugin = function (pluginRef) {
return !!this.plugin(pluginRef);
};
Cordova.plugin = function (pluginRef) {
return util_1.get(window, pluginRef);
};
Cordova.promisify = function (pluginRef, pluginName, methodName, successIndex, errorIndex) {
var _this = this;
return function () {
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i - 0] = arguments[_i];
}
return new Promise(function (resolve, reject) {
if (!window.cordova) {
console.warn('Cordova: tried calling', '"' + pluginName + '.' + methodName + '"', 'but Cordova is not defined. Please make sure you have cordova.js included in your index.html file and you are running in a proper cordova environment');
reject({
error: 'cordova_not_available'
});
return;
}
if (!_this.hasPlugin(pluginRef)) {
console.warn('Cordova: tried calling', '"' + pluginName + '.' + methodName + '"', 'but the ' + pluginName + ' plugin is not installed.');
reject({
error: 'plugin_not_installed'
});
return;
}
console.log('Cordova: exec(' + pluginName + ', ' + methodName + ')');
args[successIndex] = resolve;
args[errorIndex] = reject;
util_1.get(window, pluginRef)[methodName].apply(_this, args);
});
};
};
return Cordova;
})();
exports.Cordova = Cordova;
+2
View File
@@ -0,0 +1,2 @@
export * from './plugins/camera';
export * from './plugins/statusbar';
+5
View File
@@ -0,0 +1,5 @@
function __export(m) {
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
}
__export(require('./plugins/camera'));
__export(require('./plugins/statusbar'));
+6 -3
View File
@@ -1,3 +1,6 @@
export declare class Camera {
static getPicture: (...args: any[]) => any;
}
export declare var Camera: {
name: string;
plugin: string;
getPicture: (...args: any[]) => any;
cleanup: (...args: any[]) => any;
};
+6 -7
View File
@@ -1,9 +1,8 @@
var util_1 = require('../util');
var PLUGIN_REF = 'navigator.camera';
var Camera = (function () {
function Camera() {
}
Camera.getPicture = util_1.promisify(PLUGIN_REF, 'getPicture', 0, 1);
return Camera;
})();
exports.Camera = Camera;
exports.Camera = {
name: 'Camera',
plugin: 'cordova-plugin-camera',
getPicture: util_1.promisify(PLUGIN_REF, 'getPicture', 0, 1),
cleanup: util_1.promisify(PLUGIN_REF, 'cleanup', 0, 1)
};
+1
View File
@@ -1,2 +1,3 @@
export declare function get(obj: any, path: any): any;
export declare const promisify: (pluginRef: any, methodName: any, successIndex: any, errorIndex: any) => (...args: any[]) => any;
export declare const wrap: (pluginRef: any, methodName: any, successIndex?: any, errorIndex?: any) => (...args: any[]) => any;
+19
View File
@@ -20,3 +20,22 @@ exports.promisify = function (pluginRef, methodName, successIndex, errorIndex) {
});
};
};
exports.wrap = function (pluginRef, methodName, successIndex, errorIndex) {
if (successIndex === void 0) { successIndex = null; }
if (errorIndex === void 0) { errorIndex = null; }
return function () {
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i - 0] = arguments[_i];
}
return new Promise(function (resolve, reject) {
if (successIndex) {
args[successIndex] = resolve;
}
if (errorIndex) {
args[errorIndex] = reject;
}
get(window, pluginRef)[methodName].apply(_this, args);
});
};
};
+1
View File
@@ -1,2 +1,3 @@
export declare function get(obj: any, path: any): any;
export declare const promisify: (pluginRef: any, methodName: any, successIndex: any, errorIndex: any) => (...args: any[]) => any;
export declare const wrap: (pluginRef: any, methodName: any, successIndex?: any, errorIndex?: any) => (...args: any[]) => any;
+19
View File
@@ -20,3 +20,22 @@ exports.promisify = function (pluginRef, methodName, successIndex, errorIndex) {
});
};
};
exports.wrap = function (pluginRef, methodName, successIndex, errorIndex) {
if (successIndex === void 0) { successIndex = null; }
if (errorIndex === void 0) { errorIndex = null; }
return function () {
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i - 0] = arguments[_i];
}
return new Promise(function (resolve, reject) {
if (successIndex) {
args[successIndex] = resolve;
}
if (errorIndex) {
args[errorIndex] = reject;
}
get(window, pluginRef)[methodName].apply(_this, args);
});
};
};