diff --git a/dist/plugins/actionsheet.d.ts b/dist/plugins/actionsheet.d.ts index 75514c1bc..7faea1795 100644 --- a/dist/plugins/actionsheet.d.ts +++ b/dist/plugins/actionsheet.d.ts @@ -1,4 +1,4 @@ export declare class ActionSheet { - static show: any; - static hide: any; + static show(options: any): void; + static hide(options: any): void; } diff --git a/dist/plugins/actionsheet.js b/dist/plugins/actionsheet.js index d7bdeb9b2..b1548060e 100644 --- a/dist/plugins/actionsheet.js +++ b/dist/plugins/actionsheet.js @@ -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', diff --git a/dist/plugins/ble.d.ts b/dist/plugins/ble.d.ts new file mode 100644 index 000000000..9a0884050 --- /dev/null +++ b/dist/plugins/ble.d.ts @@ -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; +} diff --git a/dist/plugins/ble.js b/dist/plugins/ble.js new file mode 100644 index 000000000..3d6b411ee --- /dev/null +++ b/dist/plugins/ble.js @@ -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; diff --git a/dist/plugins/camera.d.ts b/dist/plugins/camera.d.ts index f7245474b..f433acec7 100644 --- a/dist/plugins/camera.d.ts +++ b/dist/plugins/camera.d.ts @@ -1,4 +1,4 @@ export declare class Camera { - static getPicture: any; - static cleanup: any; + static getPicture(options: any): void; + static cleanup(): void; } diff --git a/dist/plugins/camera.js b/dist/plugins/camera.js index f6cef97d7..0d6a22a88 100644 --- a/dist/plugins/camera.js +++ b/dist/plugins/camera.js @@ -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', diff --git a/dist/plugins/file.d.ts b/dist/plugins/file.d.ts new file mode 100644 index 000000000..91f33a7fa --- /dev/null +++ b/dist/plugins/file.d.ts @@ -0,0 +1,2 @@ +export declare class File { +} diff --git a/dist/plugins/file.js b/dist/plugins/file.js new file mode 100644 index 000000000..92e626560 --- /dev/null +++ b/dist/plugins/file.js @@ -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; diff --git a/dist/plugins/geolocation.d.ts b/dist/plugins/geolocation.d.ts new file mode 100644 index 000000000..46bb0efb7 --- /dev/null +++ b/dist/plugins/geolocation.d.ts @@ -0,0 +1,3 @@ +export declare class Device { + static getCurrentPosition: any; +} diff --git a/dist/plugins/geolocation.js b/dist/plugins/geolocation.js new file mode 100644 index 000000000..481cb9434 --- /dev/null +++ b/dist/plugins/geolocation.js @@ -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; diff --git a/dist/plugins/plugin.d.ts b/dist/plugins/plugin.d.ts index 69a89a259..2327bbbfa 100644 --- a/dist/plugins/plugin.d.ts +++ b/dist/plugins/plugin.d.ts @@ -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) => { + 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): TypedPropertyDescriptor; diff --git a/dist/plugins/plugin.js b/dist/plugins/plugin.js index 88ef6bd91..432348bc6 100644 --- a/dist/plugins/plugin.js +++ b/dist/plugins/plugin.js @@ -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 () { diff --git a/dist/plugins/statusbar.d.ts b/dist/plugins/statusbar.d.ts index 8cb7185bb..dad04fa79 100644 --- a/dist/plugins/statusbar.d.ts +++ b/dist/plugins/statusbar.d.ts @@ -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; } diff --git a/dist/plugins/statusbar.js b/dist/plugins/statusbar.js index 10281f518..a33adc45a 100644 --- a/dist/plugins/statusbar.js +++ b/dist/plugins/statusbar.js @@ -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', diff --git a/dist/plugins/toast.d.ts b/dist/plugins/toast.d.ts index ea51f7008..d8404f1e9 100644 --- a/dist/plugins/toast.d.ts +++ b/dist/plugins/toast.d.ts @@ -1,4 +1,4 @@ export declare class Toast { - static hide: any; - static showWithOptions: any; + static hide(): void; + static showWithOptions(options: any): void; } diff --git a/dist/plugins/toast.js b/dist/plugins/toast.js index 21d1198ed..aa523a4db 100644 --- a/dist/plugins/toast.js +++ b/dist/plugins/toast.js @@ -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', diff --git a/dist/src/plugins/actionsheet.d.ts b/dist/src/plugins/actionsheet.d.ts new file mode 100644 index 000000000..67513518b --- /dev/null +++ b/dist/src/plugins/actionsheet.d.ts @@ -0,0 +1,4 @@ +export declare class ActionSheet { + static show(options: any): void; + static hide(options: any): void; +} diff --git a/dist/src/plugins/actionsheet.js b/dist/src/plugins/actionsheet.js new file mode 100644 index 000000000..eedd4ac90 --- /dev/null +++ b/dist/src/plugins/actionsheet.js @@ -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; diff --git a/dist/src/plugins/ble.d.ts b/dist/src/plugins/ble.d.ts new file mode 100644 index 000000000..b9f10ceef --- /dev/null +++ b/dist/src/plugins/ble.d.ts @@ -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; +} diff --git a/dist/src/plugins/ble.js b/dist/src/plugins/ble.js new file mode 100644 index 000000000..bb540223b --- /dev/null +++ b/dist/src/plugins/ble.js @@ -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; diff --git a/dist/src/plugins/camera.d.ts b/dist/src/plugins/camera.d.ts index b32b57ec2..ca6de50ed 100644 --- a/dist/src/plugins/camera.d.ts +++ b/dist/src/plugins/camera.d.ts @@ -1,4 +1,4 @@ export declare class Camera { - static getPicture: any; - static cleanup: any; + static getPicture(options: any): void; + static cleanup(): void; } diff --git a/dist/src/plugins/camera.js b/dist/src/plugins/camera.js index 9352207a3..6b8449021 100644 --- a/dist/src/plugins/camera.js +++ b/dist/src/plugins/camera.js @@ -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', diff --git a/dist/src/plugins/file.d.ts b/dist/src/plugins/file.d.ts new file mode 100644 index 000000000..b92f0bb13 --- /dev/null +++ b/dist/src/plugins/file.d.ts @@ -0,0 +1,2 @@ +export declare class File { +} diff --git a/dist/src/plugins/file.js b/dist/src/plugins/file.js new file mode 100644 index 000000000..a15049cfc --- /dev/null +++ b/dist/src/plugins/file.js @@ -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; diff --git a/dist/src/plugins/geolocation.d.ts b/dist/src/plugins/geolocation.d.ts new file mode 100644 index 000000000..528e36a87 --- /dev/null +++ b/dist/src/plugins/geolocation.d.ts @@ -0,0 +1,3 @@ +export declare class Device { + static getCurrentPosition(options: any): void; +} diff --git a/dist/src/plugins/geolocation.js b/dist/src/plugins/geolocation.js new file mode 100644 index 000000000..5ac286954 --- /dev/null +++ b/dist/src/plugins/geolocation.js @@ -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; diff --git a/dist/src/plugins/plugin.d.ts b/dist/src/plugins/plugin.d.ts index 329a12ec2..567a89ff2 100644 --- a/dist/src/plugins/plugin.d.ts +++ b/dist/src/plugins/plugin.d.ts @@ -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) => { + value: (...args: any[]) => any; +}; export declare function RequiresPlugin(target: Function, key: string, descriptor: TypedPropertyDescriptor): TypedPropertyDescriptor; diff --git a/dist/src/plugins/plugin.js b/dist/src/plugins/plugin.js index dc7513bf3..6f4432e5c 100644 --- a/dist/src/plugins/plugin.js +++ b/dist/src/plugins/plugin.js @@ -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; diff --git a/dist/src/plugins/statusbar.d.ts b/dist/src/plugins/statusbar.d.ts index 3aec00fdd..2f16d9879 100644 --- a/dist/src/plugins/statusbar.d.ts +++ b/dist/src/plugins/statusbar.d.ts @@ -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; } diff --git a/dist/src/plugins/statusbar.js b/dist/src/plugins/statusbar.js index d1d60207f..28b953805 100644 --- a/dist/src/plugins/statusbar.js +++ b/dist/src/plugins/statusbar.js @@ -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', diff --git a/dist/src/plugins/toast.d.ts b/dist/src/plugins/toast.d.ts index 9c44128a9..fe6ffc540 100644 --- a/dist/src/plugins/toast.d.ts +++ b/dist/src/plugins/toast.d.ts @@ -1,4 +1,4 @@ export declare class Toast { - static hide: any; - static showWithOptions: any; + static hide(): void; + static showWithOptions(options: any): void; } diff --git a/dist/src/plugins/toast.js b/dist/src/plugins/toast.js index 41b886823..7c8894838 100644 --- a/dist/src/plugins/toast.js +++ b/dist/src/plugins/toast.js @@ -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', diff --git a/package.json b/package.json index 587e0939a..6b3d4a9ea 100644 --- a/package.json +++ b/package.json @@ -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" diff --git a/src/plugins/actionsheet.ts b/src/plugins/actionsheet.ts index a8eff7c6f..a3555cae2 100644 --- a/src/plugins/actionsheet.ts +++ b/src/plugins/actionsheet.ts @@ -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){}; } diff --git a/src/plugins/ble.ts b/src/plugins/ble.ts new file mode 100644 index 000000000..8ee3f7caa --- /dev/null +++ b/src/plugins/ble.ts @@ -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){}; +} diff --git a/src/plugins/camera.ts b/src/plugins/camera.ts index 97c59eca3..a79c76f60 100644 --- a/src/plugins/camera.ts +++ b/src/plugins/camera.ts @@ -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(){}; } diff --git a/src/plugins/file.ts b/src/plugins/file.ts new file mode 100644 index 000000000..be060a55d --- /dev/null +++ b/src/plugins/file.ts @@ -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 { +} diff --git a/src/plugins/geolocation.ts b/src/plugins/geolocation.ts new file mode 100644 index 000000000..d54749965 --- /dev/null +++ b/src/plugins/geolocation.ts @@ -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; +} diff --git a/src/plugins/plugin.ts b/src/plugins/plugin.ts index d07dd7d38..ee840f72f 100644 --- a/src/plugins/plugin.ts +++ b/src/plugins/plugin.ts @@ -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) => { + 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) { let originalMethod = descriptor.value; diff --git a/src/plugins/statusbar.ts b/src/plugins/statusbar.ts index e1c1c2dd8..c1a2154d3 100644 --- a/src/plugins/statusbar.ts +++ b/src/plugins/statusbar.ts @@ -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(){}; } diff --git a/src/plugins/toast.ts b/src/plugins/toast.ts index 41970a3f4..36cdd5535 100644 --- a/src/plugins/toast.ts +++ b/src/plugins/toast.ts @@ -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){}; } diff --git a/tsconfig.json b/tsconfig.json index 6372caf55..7dc9584ff 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -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" ],