refactoring

This commit is contained in:
Max Lynch 2015-11-29 19:54:45 -06:00
parent 9d54bfcd0b
commit dfef6dcfe8
42 changed files with 719 additions and 185 deletions

View File

@ -1,4 +1,4 @@
export declare class ActionSheet {
static show: any;
static hide: any;
static show(options: any): void;
static hide(options: any): void;
}

View File

@ -10,18 +10,18 @@ var plugin_1 = require('./plugin');
var ActionSheet = (function () {
function ActionSheet() {
}
__decorate([
plugin_1.Cordova({
successIndex: 1,
errIndex: 2
})
], ActionSheet, "show");
__decorate([
plugin_1.Cordova({
successIndex: 1,
errIndex: 2
})
], ActionSheet, "hide");
ActionSheet.show = function (options) { };
;
ActionSheet.hide = function (options) { };
;
Object.defineProperty(ActionSheet, "show",
__decorate([
plugin_1.Cordova()
], ActionSheet, "show", Object.getOwnPropertyDescriptor(ActionSheet, "show")));
Object.defineProperty(ActionSheet, "hide",
__decorate([
plugin_1.Cordova()
], ActionSheet, "hide", Object.getOwnPropertyDescriptor(ActionSheet, "hide")));
ActionSheet = __decorate([
plugin_1.Plugin({
name: 'ActionSheet',

7
dist/plugins/ble.d.ts vendored Normal file
View File

@ -0,0 +1,7 @@
export declare class BLE {
static scan(services: any[], seconds: number): void;
static startScan: any;
static stopScan: any;
static connect: any;
static disconnect: any;
}

55
dist/plugins/ble.js vendored Normal file
View File

@ -0,0 +1,55 @@
if (typeof __decorate !== "function") __decorate = function (decorators, target, key, desc) {
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") return Reflect.decorate(decorators, target, key, desc);
switch (arguments.length) {
case 2: return decorators.reduceRight(function(o, d) { return (d && d(o)) || o; }, target);
case 3: return decorators.reduceRight(function(o, d) { return (d && d(target, key)), void 0; }, void 0);
case 4: return decorators.reduceRight(function(o, d) { return (d && d(target, key, o)) || o; }, desc);
}
};
var plugin_1 = require('./plugin');
var BLE = (function () {
function BLE() {
}
BLE.scan = function (services, seconds) { };
Object.defineProperty(BLE, "scan",
__decorate([
plugin_1.Cordova({
successIndex: 2,
errIndex: 3
})
], BLE, "scan", Object.getOwnPropertyDescriptor(BLE, "scan")));
__decorate([
plugin_1.Cordova({
successIndex: 1,
errIndex: 2
})
], BLE, "startScan");
__decorate([
plugin_1.Cordova({
successIndex: 0,
errIndex: 1
})
], BLE, "stopScan");
__decorate([
plugin_1.Cordova({
successIndex: 1,
errIndex: 2
})
], BLE, "connect");
__decorate([
plugin_1.Cordova({
successIndex: 1,
errIndex: 2
})
], BLE, "disconnect");
BLE = __decorate([
plugin_1.Plugin({
name: 'BluetoothLowEnergy',
plugin: 'cordova-plugin-ble-central',
pluginRef: 'ble',
pluginRepo: 'https://github.com/don/cordova-plugin-ble-central'
})
], BLE);
return BLE;
})();
exports.BLE = BLE;

View File

@ -1,4 +1,4 @@
export declare class Camera {
static getPicture: any;
static cleanup: any;
static getPicture(options: any): void;
static cleanup(): void;
}

View File

@ -10,18 +10,21 @@ var plugin_1 = require('./plugin');
var Camera = (function () {
function Camera() {
}
__decorate([
plugin_1.Cordova({
successIndex: 0,
errIndex: 1
})
], Camera, "getPicture");
__decorate([
plugin_1.Cordova({
successIndex: 0,
errIndex: 1
})
], Camera, "cleanup");
Camera.getPicture = function (options) { };
;
Camera.cleanup = function () { };
;
Object.defineProperty(Camera, "getPicture",
__decorate([
plugin_1.Cordova({
// Not sure why this plugin has the success/err come first...
callbackOrder: 'reverse'
})
], Camera, "getPicture", Object.getOwnPropertyDescriptor(Camera, "getPicture")));
Object.defineProperty(Camera, "cleanup",
__decorate([
plugin_1.Cordova()
], Camera, "cleanup", Object.getOwnPropertyDescriptor(Camera, "cleanup")));
Camera = __decorate([
plugin_1.Plugin({
name: 'Camera',

2
dist/plugins/file.d.ts vendored Normal file
View File

@ -0,0 +1,2 @@
export declare class File {
}

22
dist/plugins/file.js vendored Normal file
View File

@ -0,0 +1,22 @@
if (typeof __decorate !== "function") __decorate = function (decorators, target, key, desc) {
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") return Reflect.decorate(decorators, target, key, desc);
switch (arguments.length) {
case 2: return decorators.reduceRight(function(o, d) { return (d && d(o)) || o; }, target);
case 3: return decorators.reduceRight(function(o, d) { return (d && d(target, key)), void 0; }, void 0);
case 4: return decorators.reduceRight(function(o, d) { return (d && d(target, key, o)) || o; }, desc);
}
};
var plugin_1 = require('./plugin');
var File = (function () {
function File() {
}
File = __decorate([
plugin_1.Plugin({
name: 'File',
plugin: 'cordova-plugin-file',
pluginRef: 'cordova.file'
})
], File);
return File;
})();
exports.File = File;

3
dist/plugins/geolocation.d.ts vendored Normal file
View File

@ -0,0 +1,3 @@
export declare class Device {
static getCurrentPosition: any;
}

25
dist/plugins/geolocation.js vendored Normal file
View File

@ -0,0 +1,25 @@
if (typeof __decorate !== "function") __decorate = function (decorators, target, key, desc) {
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") return Reflect.decorate(decorators, target, key, desc);
switch (arguments.length) {
case 2: return decorators.reduceRight(function(o, d) { return (d && d(o)) || o; }, target);
case 3: return decorators.reduceRight(function(o, d) { return (d && d(target, key)), void 0; }, void 0);
case 4: return decorators.reduceRight(function(o, d) { return (d && d(target, key, o)) || o; }, desc);
}
};
var plugin_1 = require('./plugin');
var Device = (function () {
function Device() {
}
__decorate([
plugin_1.Cordova()
], Device, "getCurrentPosition");
Device = __decorate([
plugin_1.Plugin({
name: 'Geolocation',
plugin: 'cordova-plugin-geolocation',
pluginRef: 'navigator.geolocation'
})
], Device);
return Device;
})();
exports.Device = Device;

View File

@ -3,6 +3,18 @@ export declare const isInstalled: (pluginRef: string) => boolean;
export declare const pluginWarn: (pluginName: string, method: string, plugin: string) => void;
export declare const cordovaWarn: (pluginName: string, method: string) => void;
export declare const wrap: (pluginObj: any, methodName: any, opts?: any) => (...args: any[]) => any;
/**
* Class decorator specifying Plugin metadata. Required for all plugins.
*/
export declare function Plugin(config: any): (cls: any) => any;
export declare function Cordova(opts?: any): (obj: any, methodName: any) => void;
/**
* Wrap a stub function in a call to a Cordova plugin, checking if both Cordova
* and the required plugin are installed.
*/
export declare function Cordova(opts?: any): (target: Object, methodName: string, descriptor: TypedPropertyDescriptor<any>) => {
value: (...args: any[]) => any;
};
/**
* Before calling the original method, ensure Cordova and the plugin are installed.
*/
export declare function RequiresPlugin(target: Function, key: string, descriptor: TypedPropertyDescriptor<any>): TypedPropertyDescriptor<any>;

View File

@ -38,12 +38,24 @@ exports.wrap = function (pluginObj, methodName, opts) {
});
return;
}
if (typeof opts.successIndex !== 'undefined') {
args[opts.successIndex] = resolve;
// Try to figure out where the success/error callbacks need to be bound
// to our promise resolve/reject handlers.
// If the plugin method expects myMethod(success, err, options)
if (opts.callbackOrder == 'reverse') {
args[0] = resolve;
args[1] = reject;
}
if (typeof opts.errorIndex !== 'undefined') {
else if (typeof opts.successIndex !== 'undefined' || typeof opts.errorIndex !== 'undefined') {
// If we've specified a success/error index
args[opts.successIndex] = resolve;
args[opts.errorIndex] = reject;
}
else {
// Otherwise, let's tack them on to the end of the argument list
// which is 90% of cases
args.push(resolve);
args.push(reject);
}
var pluginInstance = exports.getPlugin(pluginObj.pluginRef);
if (!pluginInstance) {
exports.pluginWarn(pluginObj.name, methodName, pluginObj.name);
@ -56,6 +68,9 @@ exports.wrap = function (pluginObj, methodName, opts) {
});
};
};
/**
* Class decorator specifying Plugin metadata. Required for all plugins.
*/
function Plugin(config) {
return function (cls) {
// Add these fields to the class
@ -66,16 +81,29 @@ function Plugin(config) {
};
}
exports.Plugin = Plugin;
/**
* Wrap a stub function in a call to a Cordova plugin, checking if both Cordova
* and the required plugin are installed.
*/
function Cordova(opts) {
if (opts === void 0) { opts = {}; }
return function (obj, methodName) {
if (opts.promise) {
console.log('TODO: Promise');
}
obj[methodName] = exports.wrap(obj, methodName, opts).bind(obj);
return function (target, methodName, descriptor) {
var originalMethod = descriptor.value;
return {
value: function () {
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i - 0] = arguments[_i];
}
return exports.wrap(this, methodName, opts)();
}
};
};
}
exports.Cordova = Cordova;
/**
* Before calling the original method, ensure Cordova and the plugin are installed.
*/
function RequiresPlugin(target, key, descriptor) {
var originalMethod = descriptor.value;
descriptor.value = function () {

View File

@ -1,11 +1,11 @@
export declare class StatusBar {
static overlaysWebView: any;
static styleDefault: any;
static styleLightContent: any;
static styleBlackTranslucent: any;
static styleBlackOpaque: any;
static backgroundColorByName: any;
static backgroundColorByHexString: any;
static hide: any;
static show: any;
static overlaysWebView(doOverlay: boolean): void;
static styleDefault(): void;
static styleLightContent(): void;
static styleBlackTranslucent(): void;
static styleBlackOpaque(): void;
static backgroundColorByName(colorName: string): void;
static backgroundColorByHexString(hexString: string): void;
static hide(): void;
static show(): void;
}

View File

@ -10,33 +10,60 @@ var plugin_1 = require('./plugin');
var StatusBar = (function () {
function StatusBar() {
}
__decorate([
plugin_1.Cordova()
], StatusBar, "overlaysWebView");
__decorate([
plugin_1.Cordova()
], StatusBar, "styleDefault");
__decorate([
plugin_1.Cordova()
], StatusBar, "styleLightContent");
__decorate([
plugin_1.Cordova()
], StatusBar, "styleBlackTranslucent");
__decorate([
plugin_1.Cordova()
], StatusBar, "styleBlackOpaque");
__decorate([
plugin_1.Cordova()
], StatusBar, "backgroundColorByName");
__decorate([
plugin_1.Cordova()
], StatusBar, "backgroundColorByHexString");
__decorate([
plugin_1.Cordova()
], StatusBar, "hide");
__decorate([
plugin_1.Cordova()
], StatusBar, "show");
StatusBar.overlaysWebView = function (doOverlay) { };
;
StatusBar.styleDefault = function () { };
;
StatusBar.styleLightContent = function () { };
;
StatusBar.styleBlackTranslucent = function () { };
;
StatusBar.styleBlackOpaque = function () { };
;
StatusBar.backgroundColorByName = function (colorName) { };
;
StatusBar.backgroundColorByHexString = function (hexString) { };
;
StatusBar.hide = function () { };
;
StatusBar.show = function () { };
;
Object.defineProperty(StatusBar, "overlaysWebView",
__decorate([
plugin_1.Cordova()
], StatusBar, "overlaysWebView", Object.getOwnPropertyDescriptor(StatusBar, "overlaysWebView")));
Object.defineProperty(StatusBar, "styleDefault",
__decorate([
plugin_1.Cordova()
], StatusBar, "styleDefault", Object.getOwnPropertyDescriptor(StatusBar, "styleDefault")));
Object.defineProperty(StatusBar, "styleLightContent",
__decorate([
plugin_1.Cordova()
], StatusBar, "styleLightContent", Object.getOwnPropertyDescriptor(StatusBar, "styleLightContent")));
Object.defineProperty(StatusBar, "styleBlackTranslucent",
__decorate([
plugin_1.Cordova()
], StatusBar, "styleBlackTranslucent", Object.getOwnPropertyDescriptor(StatusBar, "styleBlackTranslucent")));
Object.defineProperty(StatusBar, "styleBlackOpaque",
__decorate([
plugin_1.Cordova()
], StatusBar, "styleBlackOpaque", Object.getOwnPropertyDescriptor(StatusBar, "styleBlackOpaque")));
Object.defineProperty(StatusBar, "backgroundColorByName",
__decorate([
plugin_1.Cordova()
], StatusBar, "backgroundColorByName", Object.getOwnPropertyDescriptor(StatusBar, "backgroundColorByName")));
Object.defineProperty(StatusBar, "backgroundColorByHexString",
__decorate([
plugin_1.Cordova()
], StatusBar, "backgroundColorByHexString", Object.getOwnPropertyDescriptor(StatusBar, "backgroundColorByHexString")));
Object.defineProperty(StatusBar, "hide",
__decorate([
plugin_1.Cordova()
], StatusBar, "hide", Object.getOwnPropertyDescriptor(StatusBar, "hide")));
Object.defineProperty(StatusBar, "show",
__decorate([
plugin_1.Cordova()
], StatusBar, "show", Object.getOwnPropertyDescriptor(StatusBar, "show")));
StatusBar = __decorate([
plugin_1.Plugin({
name: 'StatusBar',

View File

@ -1,4 +1,4 @@
export declare class Toast {
static hide: any;
static showWithOptions: any;
static hide(): void;
static showWithOptions(options: any): void;
}

30
dist/plugins/toast.js vendored
View File

@ -10,18 +10,24 @@ var plugin_1 = require('./plugin');
var Toast = (function () {
function Toast() {
}
__decorate([
plugin_1.Cordova({
successIndex: 0,
errIndex: 1
})
], Toast, "hide");
__decorate([
plugin_1.Cordova({
successIndex: 1,
errIndex: 2
})
], Toast, "showWithOptions");
Toast.hide = function () { };
;
Toast.showWithOptions = function (options) { };
;
Object.defineProperty(Toast, "hide",
__decorate([
plugin_1.Cordova({
successIndex: 0,
errIndex: 1
})
], Toast, "hide", Object.getOwnPropertyDescriptor(Toast, "hide")));
Object.defineProperty(Toast, "showWithOptions",
__decorate([
plugin_1.Cordova({
successIndex: 1,
errIndex: 2
})
], Toast, "showWithOptions", Object.getOwnPropertyDescriptor(Toast, "showWithOptions")));
Toast = __decorate([
plugin_1.Plugin({
name: 'Toast',

4
dist/src/plugins/actionsheet.d.ts vendored Normal file
View File

@ -0,0 +1,4 @@
export declare class ActionSheet {
static show(options: any): void;
static hide(options: any): void;
}

41
dist/src/plugins/actionsheet.js vendored Normal file
View File

@ -0,0 +1,41 @@
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
var plugin_1 = require('./plugin');
var ActionSheet = (function () {
function ActionSheet() {
}
ActionSheet.show = function (options) { };
;
ActionSheet.hide = function (options) { };
;
__decorate([
plugin_1.Cordova(),
__metadata('design:type', Function),
__metadata('design:paramtypes', [Object]),
__metadata('design:returntype', void 0)
], ActionSheet, "show", null);
__decorate([
plugin_1.Cordova(),
__metadata('design:type', Function),
__metadata('design:paramtypes', [Object]),
__metadata('design:returntype', void 0)
], ActionSheet, "hide", null);
ActionSheet = __decorate([
plugin_1.Plugin({
name: 'ActionSheet',
plugin: 'cordova-plugin-actionsheet',
pluginRef: 'plugins.actionsheet',
repo: 'https://github.com/EddyVerbruggen/cordova-plugin-actionsheet'
}),
__metadata('design:paramtypes', [])
], ActionSheet);
return ActionSheet;
})();
exports.ActionSheet = ActionSheet;

10
dist/src/plugins/ble.d.ts vendored Normal file
View File

@ -0,0 +1,10 @@
export declare class BLE {
static scan(services: any[], seconds: number): void;
static startScan(services: any[]): void;
static stopScan(): void;
static connect(deviceId: string): void;
static disconnect(deviceId: string): void;
static read(deviceId: string, serviceUUID: string, characteristicUUID: string): void;
static write(deviceId: string, serviceUUID: string, characteristicUUID: string, value: ArrayBuffer): void;
static writeWithoutResponse(deviceId: string, serviceUUID: string, characteristicUUID: string, value: ArrayBuffer): void;
}

91
dist/src/plugins/ble.js vendored Normal file
View File

@ -0,0 +1,91 @@
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
var plugin_1 = require('./plugin');
var BLE = (function () {
function BLE() {
}
BLE.scan = function (services, seconds) { };
BLE.startScan = function (services) { };
;
BLE.stopScan = function () { };
;
BLE.connect = function (deviceId) { };
;
BLE.disconnect = function (deviceId) { };
;
BLE.read = function (deviceId, serviceUUID, characteristicUUID) { };
;
BLE.write = function (deviceId, serviceUUID, characteristicUUID, value) { };
;
BLE.writeWithoutResponse = function (deviceId, serviceUUID, characteristicUUID, value) { };
;
__decorate([
plugin_1.Cordova({
successIndex: 2,
errIndex: 3
}),
__metadata('design:type', Function),
__metadata('design:paramtypes', [Array, Number]),
__metadata('design:returntype', void 0)
], BLE, "scan", null);
__decorate([
plugin_1.Cordova(),
__metadata('design:type', Function),
__metadata('design:paramtypes', [Array]),
__metadata('design:returntype', void 0)
], BLE, "startScan", null);
__decorate([
plugin_1.Cordova(),
__metadata('design:type', Function),
__metadata('design:paramtypes', []),
__metadata('design:returntype', void 0)
], BLE, "stopScan", null);
__decorate([
plugin_1.Cordova(),
__metadata('design:type', Function),
__metadata('design:paramtypes', [String]),
__metadata('design:returntype', void 0)
], BLE, "connect", null);
__decorate([
plugin_1.Cordova(),
__metadata('design:type', Function),
__metadata('design:paramtypes', [String]),
__metadata('design:returntype', void 0)
], BLE, "disconnect", null);
__decorate([
plugin_1.Cordova(),
__metadata('design:type', Function),
__metadata('design:paramtypes', [String, String, String]),
__metadata('design:returntype', void 0)
], BLE, "read", null);
__decorate([
plugin_1.Cordova(),
__metadata('design:type', Function),
__metadata('design:paramtypes', [String, String, String, ArrayBuffer]),
__metadata('design:returntype', void 0)
], BLE, "write", null);
__decorate([
plugin_1.Cordova(),
__metadata('design:type', Function),
__metadata('design:paramtypes', [String, String, String, ArrayBuffer]),
__metadata('design:returntype', void 0)
], BLE, "writeWithoutResponse", null);
BLE = __decorate([
plugin_1.Plugin({
name: 'BluetoothLowEnergy',
plugin: 'cordova-plugin-ble-central',
pluginRef: 'ble',
pluginRepo: 'https://github.com/don/cordova-plugin-ble-central'
}),
__metadata('design:paramtypes', [])
], BLE);
return BLE;
})();
exports.BLE = BLE;

View File

@ -1,4 +1,4 @@
export declare class Camera {
static getPicture: any;
static cleanup: any;
static getPicture(options: any): void;
static cleanup(): void;
}

View File

@ -11,20 +11,24 @@ var plugin_1 = require('./plugin');
var Camera = (function () {
function Camera() {
}
Camera.getPicture = function (options) { };
;
Camera.cleanup = function () { };
;
__decorate([
plugin_1.Cordova({
successIndex: 0,
errIndex: 1
callbackOrder: 'reverse'
}),
__metadata('design:type', Object)
], Camera, "getPicture", void 0);
__metadata('design:type', Function),
__metadata('design:paramtypes', [Object]),
__metadata('design:returntype', void 0)
], Camera, "getPicture", null);
__decorate([
plugin_1.Cordova({
successIndex: 0,
errIndex: 1
}),
__metadata('design:type', Object)
], Camera, "cleanup", void 0);
plugin_1.Cordova(),
__metadata('design:type', Function),
__metadata('design:paramtypes', []),
__metadata('design:returntype', void 0)
], Camera, "cleanup", null);
Camera = __decorate([
plugin_1.Plugin({
name: 'Camera',

2
dist/src/plugins/file.d.ts vendored Normal file
View File

@ -0,0 +1,2 @@
export declare class File {
}

24
dist/src/plugins/file.js vendored Normal file
View File

@ -0,0 +1,24 @@
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
var plugin_1 = require('./plugin');
var File = (function () {
function File() {
}
File = __decorate([
plugin_1.Plugin({
name: 'File',
plugin: 'cordova-plugin-file',
pluginRef: 'cordova.file'
}),
__metadata('design:paramtypes', [])
], File);
return File;
})();
exports.File = File;

3
dist/src/plugins/geolocation.d.ts vendored Normal file
View File

@ -0,0 +1,3 @@
export declare class Device {
static getCurrentPosition(options: any): void;
}

32
dist/src/plugins/geolocation.js vendored Normal file
View File

@ -0,0 +1,32 @@
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
var plugin_1 = require('./plugin');
var Device = (function () {
function Device() {
}
Device.getCurrentPosition = function (options) { };
;
__decorate([
plugin_1.Cordova(),
__metadata('design:type', Function),
__metadata('design:paramtypes', [Object]),
__metadata('design:returntype', void 0)
], Device, "getCurrentPosition", null);
Device = __decorate([
plugin_1.Plugin({
name: 'Geolocation',
plugin: 'cordova-plugin-geolocation',
pluginRef: 'navigator.geolocation'
}),
__metadata('design:paramtypes', [])
], Device);
return Device;
})();
exports.Device = Device;

View File

@ -4,5 +4,7 @@ export declare const pluginWarn: (pluginName: string, method: string, plugin: st
export declare const cordovaWarn: (pluginName: string, method: string) => void;
export declare const wrap: (pluginObj: any, methodName: any, opts?: any) => (...args: any[]) => any;
export declare function Plugin(config: any): (cls: any) => any;
export declare function Cordova(opts?: any): (obj: any, methodName: any) => void;
export declare function Cordova(opts?: any): (target: Object, methodName: string, descriptor: TypedPropertyDescriptor<any>) => {
value: (...args: any[]) => any;
};
export declare function RequiresPlugin(target: Function, key: string, descriptor: TypedPropertyDescriptor<any>): TypedPropertyDescriptor<any>;

View File

@ -38,12 +38,18 @@ exports.wrap = function (pluginObj, methodName, opts) {
});
return;
}
if (typeof opts.successIndex !== 'undefined') {
args[opts.successIndex] = resolve;
if (opts.callbackOrder == 'reverse') {
args[0] = resolve;
args[1] = reject;
}
if (typeof opts.errorIndex !== 'undefined') {
else if (typeof opts.successIndex !== 'undefined' || typeof opts.errorIndex !== 'undefined') {
args[opts.successIndex] = resolve;
args[opts.errorIndex] = reject;
}
else {
args.push(resolve);
args.push(reject);
}
var pluginInstance = exports.getPlugin(pluginObj.pluginRef);
if (!pluginInstance) {
exports.pluginWarn(pluginObj.name, methodName, pluginObj.name);
@ -67,11 +73,17 @@ function Plugin(config) {
exports.Plugin = Plugin;
function Cordova(opts) {
if (opts === void 0) { opts = {}; }
return function (obj, methodName) {
if (opts.promise) {
console.log('TODO: Promise');
}
obj[methodName] = exports.wrap(obj, methodName, opts).bind(obj);
return function (target, methodName, descriptor) {
var originalMethod = descriptor.value;
return {
value: function () {
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i - 0] = arguments[_i];
}
return exports.wrap(this, methodName, opts)();
}
};
};
}
exports.Cordova = Cordova;

View File

@ -1,11 +1,11 @@
export declare class StatusBar {
static overlaysWebView: any;
static styleDefault: any;
static styleLightContent: any;
static styleBlackTranslucent: any;
static styleBlackOpaque: any;
static backgroundColorByName: any;
static backgroundColorByHexString: any;
static hide: any;
static show: any;
static overlaysWebView(doOverlay: boolean): void;
static styleDefault(): void;
static styleLightContent(): void;
static styleBlackTranslucent(): void;
static styleBlackOpaque(): void;
static backgroundColorByName(colorName: string): void;
static backgroundColorByHexString(hexString: string): void;
static hide(): void;
static show(): void;
}

View File

@ -11,42 +11,78 @@ var plugin_1 = require('./plugin');
var StatusBar = (function () {
function StatusBar() {
}
StatusBar.overlaysWebView = function (doOverlay) { };
;
StatusBar.styleDefault = function () { };
;
StatusBar.styleLightContent = function () { };
;
StatusBar.styleBlackTranslucent = function () { };
;
StatusBar.styleBlackOpaque = function () { };
;
StatusBar.backgroundColorByName = function (colorName) { };
;
StatusBar.backgroundColorByHexString = function (hexString) { };
;
StatusBar.hide = function () { };
;
StatusBar.show = function () { };
;
__decorate([
plugin_1.Cordova(),
__metadata('design:type', Object)
], StatusBar, "overlaysWebView", void 0);
__metadata('design:type', Function),
__metadata('design:paramtypes', [Boolean]),
__metadata('design:returntype', void 0)
], StatusBar, "overlaysWebView", null);
__decorate([
plugin_1.Cordova(),
__metadata('design:type', Object)
], StatusBar, "styleDefault", void 0);
__metadata('design:type', Function),
__metadata('design:paramtypes', []),
__metadata('design:returntype', void 0)
], StatusBar, "styleDefault", null);
__decorate([
plugin_1.Cordova(),
__metadata('design:type', Object)
], StatusBar, "styleLightContent", void 0);
__metadata('design:type', Function),
__metadata('design:paramtypes', []),
__metadata('design:returntype', void 0)
], StatusBar, "styleLightContent", null);
__decorate([
plugin_1.Cordova(),
__metadata('design:type', Object)
], StatusBar, "styleBlackTranslucent", void 0);
__metadata('design:type', Function),
__metadata('design:paramtypes', []),
__metadata('design:returntype', void 0)
], StatusBar, "styleBlackTranslucent", null);
__decorate([
plugin_1.Cordova(),
__metadata('design:type', Object)
], StatusBar, "styleBlackOpaque", void 0);
__metadata('design:type', Function),
__metadata('design:paramtypes', []),
__metadata('design:returntype', void 0)
], StatusBar, "styleBlackOpaque", null);
__decorate([
plugin_1.Cordova(),
__metadata('design:type', Object)
], StatusBar, "backgroundColorByName", void 0);
__metadata('design:type', Function),
__metadata('design:paramtypes', [String]),
__metadata('design:returntype', void 0)
], StatusBar, "backgroundColorByName", null);
__decorate([
plugin_1.Cordova(),
__metadata('design:type', Object)
], StatusBar, "backgroundColorByHexString", void 0);
__metadata('design:type', Function),
__metadata('design:paramtypes', [String]),
__metadata('design:returntype', void 0)
], StatusBar, "backgroundColorByHexString", null);
__decorate([
plugin_1.Cordova(),
__metadata('design:type', Object)
], StatusBar, "hide", void 0);
__metadata('design:type', Function),
__metadata('design:paramtypes', []),
__metadata('design:returntype', void 0)
], StatusBar, "hide", null);
__decorate([
plugin_1.Cordova(),
__metadata('design:type', Object)
], StatusBar, "show", void 0);
__metadata('design:type', Function),
__metadata('design:paramtypes', []),
__metadata('design:returntype', void 0)
], StatusBar, "show", null);
StatusBar = __decorate([
plugin_1.Plugin({
name: 'StatusBar',

View File

@ -1,4 +1,4 @@
export declare class Toast {
static hide: any;
static showWithOptions: any;
static hide(): void;
static showWithOptions(options: any): void;
}

View File

@ -11,20 +11,28 @@ var plugin_1 = require('./plugin');
var Toast = (function () {
function Toast() {
}
Toast.hide = function () { };
;
Toast.showWithOptions = function (options) { };
;
__decorate([
plugin_1.Cordova({
successIndex: 0,
errIndex: 1
}),
__metadata('design:type', Object)
], Toast, "hide", void 0);
__metadata('design:type', Function),
__metadata('design:paramtypes', []),
__metadata('design:returntype', void 0)
], Toast, "hide", null);
__decorate([
plugin_1.Cordova({
successIndex: 1,
errIndex: 2
}),
__metadata('design:type', Object)
], Toast, "showWithOptions", void 0);
__metadata('design:type', Function),
__metadata('design:paramtypes', [Object]),
__metadata('design:returntype', void 0)
], Toast, "showWithOptions", null);
Toast = __decorate([
plugin_1.Plugin({
name: 'Toast',

View File

@ -6,6 +6,9 @@
"directories": {
"test": "test"
},
"dependencies": {
"@reactivex/rxjs": "^5.0.0-alpha.7"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"build": "rm -rf dist && tsc"

View File

@ -7,15 +7,9 @@ import {Plugin, Cordova} from './plugin';
repo: 'https://github.com/EddyVerbruggen/cordova-plugin-actionsheet'
})
export class ActionSheet {
@Cordova({
successIndex: 1,
errIndex: 2
})
static show;
@Cordova()
static show(options:any){};
@Cordova({
successIndex: 1,
errIndex: 2
})
static hide;
@Cordova()
static hide(options:any){};
}

36
src/plugins/ble.ts Normal file
View File

@ -0,0 +1,36 @@
import {Plugin, Cordova} from './plugin';
@Plugin({
name: 'BluetoothLowEnergy',
plugin: 'cordova-plugin-ble-central',
pluginRef: 'ble',
pluginRepo: 'https://github.com/don/cordova-plugin-ble-central'
})
export class BLE {
@Cordova({
successIndex: 2,
errIndex: 3
})
static scan(services:any[], seconds:number) {}
@Cordova()
static startScan(services:any[]){};
@Cordova()
static stopScan(){};
@Cordova()
static connect(deviceId:string){};
@Cordova()
static disconnect(deviceId:string){};
@Cordova()
static read(deviceId:string, serviceUUID:string, characteristicUUID:string){};
@Cordova()
static write(deviceId:string, serviceUUID:string, characteristicUUID:string, value:ArrayBuffer){};
@Cordova()
static writeWithoutResponse(deviceId:string, serviceUUID:string, characteristicUUID:string, value:ArrayBuffer){};
}

View File

@ -7,14 +7,11 @@ import {Plugin, Cordova} from './plugin';
})
export class Camera {
@Cordova({
successIndex: 0,
errIndex: 1
// Not sure why this plugin has the success/err come first...
callbackOrder: 'reverse'
})
static getPicture;
static getPicture(options:any){};
@Cordova({
successIndex: 0,
errIndex: 1
})
static cleanup;
@Cordova()
static cleanup(){};
}

11
src/plugins/file.ts Normal file
View File

@ -0,0 +1,11 @@
import {Plugin, Cordova} from './plugin';
declare var window;
@Plugin({
name: 'File',
plugin: 'cordova-plugin-file',
pluginRef: 'cordova.file'
})
export class File {
}

View File

@ -0,0 +1,18 @@
import {Plugin, Cordova} from './plugin';
declare var window;
@Plugin({
name: 'Geolocation',
plugin: 'cordova-plugin-geolocation',
pluginRef: 'navigator.geolocation'
})
export class Device {
@Cordova()
static getCurrentPosition(options:any){};
// Do this with observables
// @Cordova()
// static watchPosition;
}

View File

@ -39,11 +39,22 @@ export const wrap = function(pluginObj, methodName, opts: any = {}) {
return;
}
if(typeof opts.successIndex !== 'undefined') {
// Try to figure out where the success/error callbacks need to be bound
// to our promise resolve/reject handlers.
// If the plugin method expects myMethod(success, err, options)
if(opts.callbackOrder == 'reverse') {
args[0] = resolve;
args[1] = reject;
} else if(typeof opts.successIndex !== 'undefined' || typeof opts.errorIndex !== 'undefined') {
// If we've specified a success/error index
args[opts.successIndex] = resolve;
}
if(typeof opts.errorIndex !== 'undefined') {
args[opts.errorIndex] = reject;
} else {
// Otherwise, let's tack them on to the end of the argument list
// which is 90% of cases
args.push(resolve);
args.push(reject);
}
let pluginInstance = getPlugin(pluginObj.pluginRef);
@ -61,6 +72,9 @@ export const wrap = function(pluginObj, methodName, opts: any = {}) {
}
}
/**
* Class decorator specifying Plugin metadata. Required for all plugins.
*/
export function Plugin(config) {
return function(cls) {
@ -73,15 +87,25 @@ export function Plugin(config) {
}
}
/**
* Wrap a stub function in a call to a Cordova plugin, checking if both Cordova
* and the required plugin are installed.
*/
export function Cordova(opts:any = {}) {
return function(obj, methodName) {
if(opts.promise) {
console.log('TODO: Promise');
return (target: Object, methodName: string, descriptor: TypedPropertyDescriptor<any>) => {
let originalMethod = descriptor.value;
return {
value: function(...args: any[]) {
return wrap(this, methodName, opts)();
}
}
obj[methodName] = wrap(obj, methodName, opts).bind(obj);
}
}
/**
* Before calling the original method, ensure Cordova and the plugin are installed.
*/
export function RequiresPlugin(target: Function, key: string, descriptor: TypedPropertyDescriptor<any>) {
let originalMethod = descriptor.value;

View File

@ -7,21 +7,21 @@ import {Plugin, Cordova} from './plugin';
})
export class StatusBar {
@Cordova()
static overlaysWebView;
static overlaysWebView(doOverlay:boolean){};
@Cordova()
static styleDefault;
static styleDefault(){};
@Cordova()
static styleLightContent;
static styleLightContent(){};
@Cordova()
static styleBlackTranslucent;
static styleBlackTranslucent(){};
@Cordova()
static styleBlackOpaque;
static styleBlackOpaque(){};
@Cordova()
static backgroundColorByName;
static backgroundColorByName(colorName:string){};
@Cordova()
static backgroundColorByHexString;
static backgroundColorByHexString(hexString:string){};
@Cordova()
static hide;
static hide(){};
@Cordova()
static show;
static show(){};
}

View File

@ -11,11 +11,11 @@ export class Toast {
successIndex: 0,
errIndex: 1
})
static hide;
static hide(){};
@Cordova({
successIndex: 1,
errIndex: 2
})
static showWithOptions;
static showWithOptions(options:any){};
}

View File

@ -8,20 +8,12 @@
"sourceMap": false,
"declaration": true
},
"filesGlob": [
"src/**/*.ts"
],
"exclude": [
"node_modules"
],
"files": [
"src/index.ts",
"src/plugin-config.ts",
"src/plugins/actionsheet.ts",
"src/plugins/camera.ts",
"src/plugins/device.ts",
"src/plugins/plugin.ts",
"src/plugins/statusbar.ts",
"src/plugins/toast.ts",
"src/util.ts"
],