From 118da948cbc21b58924da561411d94fc64e376d3 Mon Sep 17 00:00:00 2001 From: Max Lynch Date: Mon, 30 Nov 2015 13:27:25 -0600 Subject: [PATCH] awww yis --- demo/www/app/plugin/plugin.js | 9 ++ demo/www/index.html | 6 +- dist/index.js | 4 +- dist/index.js.map | 2 +- dist/plugins/geolocation.d.ts | 2 +- dist/plugins/geolocation.js | 25 ++--- dist/plugins/geolocation.js.map | 2 +- dist/plugins/plugin.js | 20 ++-- dist/plugins/plugin.js.map | 2 +- dist/src/index.d.ts | 8 ++ dist/src/index.js | 24 +++++ dist/src/index.js.map | 1 + dist/src/plugins/geolocation.d.ts | 4 + dist/src/plugins/geolocation.js | 45 +++++++++ dist/src/plugins/geolocation.js.map | 1 + dist/src/plugins/plugin.d.ts | 10 ++ dist/src/plugins/plugin.js | 137 ++++++++++++++++++++++++++++ dist/src/plugins/plugin.js.map | 1 + src/index.ts | 5 +- src/plugins/geolocation.ts | 3 +- src/plugins/plugin.ts | 18 +++- 21 files changed, 293 insertions(+), 36 deletions(-) create mode 100644 dist/src/index.d.ts create mode 100644 dist/src/index.js create mode 100644 dist/src/index.js.map create mode 100644 dist/src/plugins/geolocation.d.ts create mode 100644 dist/src/plugins/geolocation.js create mode 100644 dist/src/plugins/geolocation.js.map create mode 100644 dist/src/plugins/plugin.d.ts create mode 100644 dist/src/plugins/plugin.js create mode 100644 dist/src/plugins/plugin.js.map diff --git a/demo/www/app/plugin/plugin.js b/demo/www/app/plugin/plugin.js index 3e0465778..7dec9edde 100644 --- a/demo/www/app/plugin/plugin.js +++ b/demo/www/app/plugin/plugin.js @@ -69,6 +69,15 @@ export class Plugin { }); } else { console.log('Response: ', v); + + if(v.subscribe) { + console.log('Observable response, subscribing...'); + v.subscribe((val) => { + console.log('Observable val', val); + }, (err) => { + console.log('ERROR: Observable', err); + }); + } } } diff --git a/demo/www/index.html b/demo/www/index.html index a6826eef1..9ea67fe8f 100644 --- a/demo/www/index.html +++ b/demo/www/index.html @@ -8,10 +8,10 @@ - diff --git a/dist/index.js b/dist/index.js index 222b9b396..0f3c1863d 100644 --- a/dist/index.js +++ b/dist/index.js @@ -10,8 +10,10 @@ __export(require('./plugins/device')); __export(require('./plugins/geolocation')); __export(require('./plugins/statusbar')); __export(require('./plugins/toast')); +var before = +new Date; var didFireReady = false; -window.addEventListener('deviceready', function () { +document.addEventListener('deviceready', function () { + console.log('DEVICE READY FIRED AFTER', (+new Date - before), 'ms'); didFireReady = true; }); setTimeout(function () { diff --git a/dist/index.js.map b/dist/index.js.map index 56a89c895..6f5611fdb 100644 --- a/dist/index.js.map +++ b/dist/index.js.map @@ -1 +1 @@ -{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,IAAM,oBAAoB,GAAG,IAAI,CAAC;AAElC,iBAAc,uBAAuB,CAAC,EAAA;AACtC,iBAAc,eAAe,CAAC,EAAA;AAC9B,iBAAc,kBAAkB,CAAC,EAAA;AACjC,iBAAc,oBAAoB,CAAC,EAAA;AACnC,iBAAc,kBAAkB,CAAC,EAAA;AACjC,iBAAc,uBAAuB,CAAC,EAAA;AACtC,iBAAc,qBAAqB,CAAC,EAAA;AACpC,iBAAc,iBAAiB,CAAC,EAAA;AAShC,IAAI,YAAY,GAAG,KAAK,CAAC;AACzB,MAAM,CAAC,gBAAgB,CAAC,aAAa,EAAE;IACrC,YAAY,GAAG,IAAI,CAAC;AACtB,CAAC,CAAC,CAAA;AAEF,UAAU,CAAC;IACT,EAAE,CAAA,CAAC,CAAC,YAAY,IAAI,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC;QACnC,OAAO,CAAC,IAAI,CAAC,0CAA0C,GAAG,oBAAoB,GAAG,0HAA0H,CAAC,CAAC;IAC/M,CAAC;AACH,CAAC,EAAE,oBAAoB,CAAC,CAAC"} \ No newline at end of file +{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,IAAM,oBAAoB,GAAG,IAAI,CAAC;AAElC,iBAAc,uBAAuB,CAAC,EAAA;AACtC,iBAAc,eAAe,CAAC,EAAA;AAC9B,iBAAc,kBAAkB,CAAC,EAAA;AACjC,iBAAc,oBAAoB,CAAC,EAAA;AACnC,iBAAc,kBAAkB,CAAC,EAAA;AACjC,iBAAc,uBAAuB,CAAC,EAAA;AACtC,iBAAc,qBAAqB,CAAC,EAAA;AACpC,iBAAc,iBAAiB,CAAC,EAAA;AAShC,IAAI,MAAM,GAAG,CAAC,IAAI,IAAI,CAAC;AAEvB,IAAI,YAAY,GAAG,KAAK,CAAC;AACzB,QAAQ,CAAC,gBAAgB,CAAC,aAAa,EAAE;IACvC,OAAO,CAAC,GAAG,CAAC,0BAA0B,EAAE,CAAC,CAAC,IAAI,IAAI,GAAG,MAAM,CAAC,EAAE,IAAI,CAAC,CAAA;IACnE,YAAY,GAAG,IAAI,CAAC;AACtB,CAAC,CAAC,CAAA;AAEF,UAAU,CAAC;IACT,EAAE,CAAA,CAAC,CAAC,YAAY,IAAI,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC;QACnC,OAAO,CAAC,IAAI,CAAC,0CAA0C,GAAG,oBAAoB,GAAG,0HAA0H,CAAC,CAAC;IAC/M,CAAC;AACH,CAAC,EAAE,oBAAoB,CAAC,CAAC"} \ No newline at end of file diff --git a/dist/plugins/geolocation.d.ts b/dist/plugins/geolocation.d.ts index 771a23a66..af91f15c9 100644 --- a/dist/plugins/geolocation.d.ts +++ b/dist/plugins/geolocation.d.ts @@ -1,4 +1,4 @@ -export declare class Device { +export declare class Geolocation { static getCurrentPosition(options: any): void; static watchPosition(options: any): void; } diff --git a/dist/plugins/geolocation.js b/dist/plugins/geolocation.js index edaeedfc1..8a1cbaf65 100644 --- a/dist/plugins/geolocation.js +++ b/dist/plugins/geolocation.js @@ -7,32 +7,33 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key, } }; var plugin_1 = require('./plugin'); -var Device = (function () { - function Device() { +var Geolocation = (function () { + function Geolocation() { } - Device.getCurrentPosition = function (options) { }; + Geolocation.getCurrentPosition = function (options) { }; ; - Device.watchPosition = function (options) { }; + Geolocation.watchPosition = function (options) { }; ; - Object.defineProperty(Device, "getCurrentPosition", + Object.defineProperty(Geolocation, "getCurrentPosition", __decorate([ plugin_1.Cordova() - ], Device, "getCurrentPosition", Object.getOwnPropertyDescriptor(Device, "getCurrentPosition"))); - Object.defineProperty(Device, "watchPosition", + ], Geolocation, "getCurrentPosition", Object.getOwnPropertyDescriptor(Geolocation, "getCurrentPosition"))); + Object.defineProperty(Geolocation, "watchPosition", __decorate([ plugin_1.Cordova({ + callbackOrder: 'reverse', observable: true, clearFunction: 'clearWatch()' }) - ], Device, "watchPosition", Object.getOwnPropertyDescriptor(Device, "watchPosition"))); - Device = __decorate([ + ], Geolocation, "watchPosition", Object.getOwnPropertyDescriptor(Geolocation, "watchPosition"))); + Geolocation = __decorate([ plugin_1.Plugin({ name: 'Geolocation', plugin: 'cordova-plugin-geolocation', pluginRef: 'navigator.geolocation' }) - ], Device); - return Device; + ], Geolocation); + return Geolocation; })(); -exports.Device = Device; +exports.Geolocation = Geolocation; //# sourceMappingURL=geolocation.js.map \ No newline at end of file diff --git a/dist/plugins/geolocation.js.map b/dist/plugins/geolocation.js.map index 6678d1a78..e5c52f94c 100644 --- a/dist/plugins/geolocation.js.map +++ b/dist/plugins/geolocation.js.map @@ -1 +1 @@ -{"version":3,"file":"geolocation.js","sourceRoot":"","sources":["../../src/plugins/geolocation.ts"],"names":["Device","Device.constructor","Device.getCurrentPosition","Device.watchPosition"],"mappings":";;;;;;;;AAAA,uBAA8B,UAAU,CAAC,CAAA;AAMzC;IAAAA;IAeAC,CAACA;IARQD,yBAAkBA,GADzBA,UAC0BA,OAAWA,IAAEE,CAACA;;IAOjCF,oBAAaA,GAJpBA,UAIqBA,OAAWA,IAAEG,CAACA;;IARnCH,sBACOA,4BAAkBA;;YADxBA,gBAAOA,EAAEA;WACHA,4BAAkBA,kCAAlBA,4BAAkBA,IAAeA;IAGxCA,sBAIOA,uBAAaA;;YAJnBA,gBAAOA,CAACA;gBACPA,UAAUA,EAAEA,IAAIA;gBAChBA,aAAaA,EAAEA,cAAcA;aAC9BA,CAACA;WACKA,uBAAaA,kCAAbA,uBAAaA,IAAeA;IAdrCA;QAACA,eAAMA,CAACA;YACNA,IAAIA,EAAEA,aAAaA;YACnBA,MAAMA,EAAEA,4BAA4BA;YACpCA,SAASA,EAAEA,uBAAuBA;SACnCA,CAACA;eAWDA;IAADA,aAACA;AAADA,CAACA,AAfD,IAeC;AAVY,cAAM,SAUlB,CAAA"} \ No newline at end of file +{"version":3,"file":"geolocation.js","sourceRoot":"","sources":["../../src/plugins/geolocation.ts"],"names":["Geolocation","Geolocation.constructor","Geolocation.getCurrentPosition","Geolocation.watchPosition"],"mappings":";;;;;;;;AAAA,uBAA8B,UAAU,CAAC,CAAA;AAMzC;IAAAA;IAgBAC,CAACA;IATQD,8BAAkBA,GADzBA,UAC0BA,OAAWA,IAAEE,CAACA;;IAQjCF,yBAAaA,GALpBA,UAKqBA,OAAWA,IAAEG,CAACA;;IATnCH,sBACOA,iCAAkBA;;YADxBA,gBAAOA,EAAEA;WACHA,iCAAkBA,kCAAlBA,iCAAkBA,IAAeA;IAGxCA,sBAKOA,4BAAaA;;YALnBA,gBAAOA,CAACA;gBACPA,aAAaA,EAAEA,SAASA;gBACxBA,UAAUA,EAAEA,IAAIA;gBAChBA,aAAaA,EAAEA,cAAcA;aAC9BA,CAACA;WACKA,4BAAaA,kCAAbA,4BAAaA,IAAeA;IAfrCA;QAACA,eAAMA,CAACA;YACNA,IAAIA,EAAEA,aAAaA;YACnBA,MAAMA,EAAEA,4BAA4BA;YACpCA,SAASA,EAAEA,uBAAuBA;SACnCA,CAACA;oBAYDA;IAADA,kBAACA;AAADA,CAACA,AAhBD,IAgBC;AAXY,mBAAW,cAWvB,CAAA"} \ No newline at end of file diff --git a/dist/plugins/plugin.js b/dist/plugins/plugin.js index 4983804f0..58a6653f3 100644 --- a/dist/plugins/plugin.js +++ b/dist/plugins/plugin.js @@ -28,17 +28,14 @@ function callCordovaPlugin(pluginObj, methodName, args, opts, resolve, reject) { if (opts === void 0) { opts = {}; } if (!window.cordova) { exports.cordovaWarn(pluginObj.name, methodName); - reject({ - error: 'cordova_not_available' - }); - return; } // 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; + // Get those arguments in the order [reject, resolve, ...restOfArgs] + args.unshift(reject); + args.unshift(resolve); } else if (typeof opts.successIndex !== 'undefined' || typeof opts.errorIndex !== 'undefined') { // If we've specified a success/error index @@ -60,7 +57,8 @@ function callCordovaPlugin(pluginObj, methodName, args, opts, resolve, reject) { return; } console.log('Cordova calling', pluginObj.name, methodName, args); - return util_1.get(window, pluginObj.pluginRef)[methodName].apply(pluginObj, args); + // TODO: Illegal invocation needs window context + return util_1.get(window, pluginObj.pluginRef)[methodName].apply(pluginInstance, args); } function wrapPromise(pluginObj, methodName, args, opts) { if (opts === void 0) { opts = {}; } @@ -70,8 +68,12 @@ function wrapPromise(pluginObj, methodName, args, opts) { } function wrapObservable(pluginObj, methodName, args, opts) { if (opts === void 0) { opts = {}; } - return Rx_1.Observable.create(function (observer) { - var pluginResult = callCordovaPlugin(pluginObj, methodName, args, opts, observer.onNext, observer.onError); + return new Rx_1.Observable(function (observer) { + console.log('Calling inside observable', observer); + var pluginResult = callCordovaPlugin(pluginObj, methodName, args, opts, function (d) { + console.log('WATCH RESP', d); + observer.next(d); + }, observer.error); return function () { return util_1.get(window, pluginObj.pluginRef)[opts.clearFunction].apply(pluginObj, pluginResult); }; diff --git a/dist/plugins/plugin.js.map b/dist/plugins/plugin.js.map index 88c9679cf..7c08b5511 100644 --- a/dist/plugins/plugin.js.map +++ b/dist/plugins/plugin.js.map @@ -1 +1 @@ -{"version":3,"file":"plugin.js","sourceRoot":"","sources":["../../src/plugins/plugin.ts"],"names":["callC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AAE,IAAI,CAAC,CAAC;YACxD,CAAC;SACFA,CAAAA;IACHA,CAACA,CAAAA;AACHA,CAACA;AAVe,eAAO,UAUtB,CAAA;AAED;;GAEG;AACH,wBAA+B,MAAgB,EAAE,GAAW,EAAE,UAAwC;IACpGC,IAAIA,cAAcA,GAAGA,UAAUA,CAACA,KAAKA,CAACA;IAEtCA,UAAUA,CAACA,KAAKA,GAAGA;QAAS,cAAc;aAAd,WAAc,CAAd,sBAAc,CAAd,IAAc;YAAd,6BAAc;;QACxC,OAAO,CAAC,GAAG,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC;QAC7B,EAAE,CAAA,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC;YACnB,mBAAW,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;YAC7B,MAAM,CAAC;QACT,CAAC;QAED,IAAI,cAAc,GAAG,iBAAS,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QAC/C,EAAE,CAAA,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC;YACnB,kBAAU,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC;YACvC,MAAM,CAAC;QACT,CAAC;QACD,cAAc,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IACnC,CAAC,CAAAA;IAEDA,MAAMA,CAACA,UAAUA,CAACA;AACpBA,CAACA;AAnBe,sBAAc,iBAmB7B,CAAA"} \ No newline at end of file +{"version":3,"file":"plugin.js","sourceRoot":"","sources":["../../src/plugins/plugin.ts"],"names":["callCordovaPlugin","wrapPromise","wrapObservable","Plugin","Cordova","RequiresPlugin"],"mappings":"AAAA,qBAAkB,SAAS,CAAC,CAAA;AAK5B,mBAAyB,6BAA6B,CAAC,CAAA;AAG1C,iBAAS,GAAG,UAAS,SAAiB;IACjD,MAAM,CAAC,UAAG,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;AAChC,CAA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UtB,CAAA;AAED;;GAEG;AACH,wBAA+B,MAAgB,EAAE,GAAW,EAAE,UAAwC;IACpGC,IAAIA,cAAcA,GAAGA,UAAUA,CAACA,KAAKA,CAACA;IAEtCA,UAAUA,CAACA,KAAKA,GAAGA;QAAS,cAAc;aAAd,WAAc,CAAd,sBAAc,CAAd,IAAc;YAAd,6BAAc;;QACxC,OAAO,CAAC,GAAG,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC;QAC7B,EAAE,CAAA,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC;YACnB,mBAAW,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;YAC7B,MAAM,CAAC;QACT,CAAC;QAED,IAAI,cAAc,GAAG,iBAAS,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QAC/C,EAAE,CAAA,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC;YACnB,kBAAU,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC;YACvC,MAAM,CAAC;QACT,CAAC;QACD,cAAc,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IACnC,CAAC,CAAAA;IAEDA,MAAMA,CAACA,UAAUA,CAACA;AACpBA,CAACA;AAnBe,sBAAc,iBAmB7B,CAAA"} \ No newline at end of file diff --git a/dist/src/index.d.ts b/dist/src/index.d.ts new file mode 100644 index 000000000..1341363de --- /dev/null +++ b/dist/src/index.d.ts @@ -0,0 +1,8 @@ +export * from './plugins/actionsheet'; +export * from './plugins/ble'; +export * from './plugins/camera'; +export * from './plugins/contacts'; +export * from './plugins/device'; +export * from './plugins/geolocation'; +export * from './plugins/statusbar'; +export * from './plugins/toast'; diff --git a/dist/src/index.js b/dist/src/index.js new file mode 100644 index 000000000..b3842a82a --- /dev/null +++ b/dist/src/index.js @@ -0,0 +1,24 @@ +function __export(m) { + for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p]; +} +var DEVICE_READY_TIMEOUT = 2000; +__export(require('./plugins/actionsheet')); +__export(require('./plugins/ble')); +__export(require('./plugins/camera')); +__export(require('./plugins/contacts')); +__export(require('./plugins/device')); +__export(require('./plugins/geolocation')); +__export(require('./plugins/statusbar')); +__export(require('./plugins/toast')); +var before = +new Date; +var didFireReady = false; +document.addEventListener('deviceready', function () { + console.log('DEVICE READY FIRED AFTER', (+new Date - before), 'ms'); + didFireReady = true; +}); +setTimeout(function () { + if (!didFireReady && window.cordova) { + console.warn('Native: deviceready did not fire within ' + DEVICE_READY_TIMEOUT + 'ms. This can happen when plugins are in an inconsistent state. Try removing plugins from plugins/ and reinstalling them.'); + } +}, DEVICE_READY_TIMEOUT); +//# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/dist/src/index.js.map b/dist/src/index.js.map new file mode 100644 index 000000000..cc86a850f --- /dev/null +++ b/dist/src/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;AAAA,IAAM,oBAAoB,GAAG,IAAI,CAAC;AAElC,iBAAc,uBAAuB,CAAC,EAAA;AACtC,iBAAc,eAAe,CAAC,EAAA;AAC9B,iBAAc,kBAAkB,CAAC,EAAA;AACjC,iBAAc,oBAAoB,CAAC,EAAA;AACnC,iBAAc,kBAAkB,CAAC,EAAA;AACjC,iBAAc,uBAAuB,CAAC,EAAA;AACtC,iBAAc,qBAAqB,CAAC,EAAA;AACpC,iBAAc,iBAAiB,CAAC,EAAA;AAShC,IAAI,MAAM,GAAG,CAAC,IAAI,IAAI,CAAC;AAEvB,IAAI,YAAY,GAAG,KAAK,CAAC;AACzB,QAAQ,CAAC,gBAAgB,CAAC,aAAa,EAAE;IACvC,OAAO,CAAC,GAAG,CAAC,0BAA0B,EAAE,CAAC,CAAC,IAAI,IAAI,GAAG,MAAM,CAAC,EAAE,IAAI,CAAC,CAAA;IACnE,YAAY,GAAG,IAAI,CAAC;AACtB,CAAC,CAAC,CAAA;AAEF,UAAU,CAAC;IACT,EAAE,CAAA,CAAC,CAAC,YAAY,IAAI,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC;QACnC,OAAO,CAAC,IAAI,CAAC,0CAA0C,GAAG,oBAAoB,GAAG,0HAA0H,CAAC,CAAC;IAC/M,CAAC;AACH,CAAC,EAAE,oBAAoB,CAAC,CAAC"} \ No newline at end of file diff --git a/dist/src/plugins/geolocation.d.ts b/dist/src/plugins/geolocation.d.ts new file mode 100644 index 000000000..8d814b732 --- /dev/null +++ b/dist/src/plugins/geolocation.d.ts @@ -0,0 +1,4 @@ +export declare class Geolocation { + static getCurrentPosition(options: any): void; + static watchPosition(options: any): void; +} diff --git a/dist/src/plugins/geolocation.js b/dist/src/plugins/geolocation.js new file mode 100644 index 000000000..50d5703a6 --- /dev/null +++ b/dist/src/plugins/geolocation.js @@ -0,0 +1,45 @@ +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 Geolocation = (function () { + function Geolocation() { + } + Geolocation.getCurrentPosition = function (options) { }; + ; + Geolocation.watchPosition = function (options) { }; + ; + __decorate([ + plugin_1.Cordova(), + __metadata('design:type', Function), + __metadata('design:paramtypes', [Object]), + __metadata('design:returntype', void 0) + ], Geolocation, "getCurrentPosition", null); + __decorate([ + plugin_1.Cordova({ + callbackOrder: 'reverse', + observable: true, + clearFunction: 'clearWatch()' + }), + __metadata('design:type', Function), + __metadata('design:paramtypes', [Object]), + __metadata('design:returntype', void 0) + ], Geolocation, "watchPosition", null); + Geolocation = __decorate([ + plugin_1.Plugin({ + name: 'Geolocation', + plugin: 'cordova-plugin-geolocation', + pluginRef: 'navigator.geolocation' + }), + __metadata('design:paramtypes', []) + ], Geolocation); + return Geolocation; +})(); +exports.Geolocation = Geolocation; +//# sourceMappingURL=geolocation.js.map \ No newline at end of file diff --git a/dist/src/plugins/geolocation.js.map b/dist/src/plugins/geolocation.js.map new file mode 100644 index 000000000..8ad75cb69 --- /dev/null +++ b/dist/src/plugins/geolocation.js.map @@ -0,0 +1 @@ +{"version":3,"file":"geolocation.js","sourceRoot":"","sources":["../../../src/plugins/geolocation.ts"],"names":["Geolocation","Geolocation.constructor","Geolocation.getCurrentPosition","Geolocation.watchPosition"],"mappings":";;;;;;;;;AAAA,uBAA8B,UAAU,CAAC,CAAA;AAMzC;IAAAA;IAgBAC,CAACA;IATQD,8BAAkBA,GADzBA,UAC0BA,OAAWA,IAAEE,CAACA;;IAQjCF,yBAAaA,GALpBA,UAKqBA,OAAWA,IAAEG,CAACA;;IATnCH;QAACA,gBAAOA,EAAEA;;;;OACHA,iCAAkBA,QAAeA;IAGxCA;QAACA,gBAAOA,CAACA;YACPA,aAAaA,EAAEA,SAASA;YACxBA,UAAUA,EAAEA,IAAIA;YAChBA,aAAaA,EAAEA,cAAcA;SAC9BA,CAACA;;;;OACKA,4BAAaA,QAAeA;IAfrCA;QAACA,eAAMA,CAACA;YACNA,IAAIA,EAAEA,aAAaA;YACnBA,MAAMA,EAAEA,4BAA4BA;YACpCA,SAASA,EAAEA,uBAAuBA;SACnCA,CAACA;;oBAYDA;IAADA,kBAACA;AAADA,CAACA,AAhBD,IAgBC;AAXY,mBAAW,cAWvB,CAAA"} \ No newline at end of file diff --git a/dist/src/plugins/plugin.d.ts b/dist/src/plugins/plugin.d.ts new file mode 100644 index 000000000..3fd5ea03a --- /dev/null +++ b/dist/src/plugins/plugin.d.ts @@ -0,0 +1,10 @@ +export declare const getPlugin: (pluginRef: string) => any; +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: string, opts?: any) => (...args: any[]) => any; +export declare function Plugin(config: any): (cls: any) => any; +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 new file mode 100644 index 000000000..50b3f67d8 --- /dev/null +++ b/dist/src/plugins/plugin.js @@ -0,0 +1,137 @@ +var util_1 = require('../util'); +var Rx_1 = require('@reactivex/rxjs/dist/cjs/Rx'); +exports.getPlugin = function (pluginRef) { + return util_1.get(window, pluginRef); +}; +exports.isInstalled = function (pluginRef) { + return !!exports.getPlugin(pluginRef); +}; +exports.pluginWarn = function (pluginName, method, plugin) { + if (method) { + console.warn('Native: tried calling ' + pluginName + '.' + method + + ', but the ' + pluginName + ' plugin is not installed. Install the ' + + plugin + ' plugin'); + } + else { + console.warn('Native: tried accessing the ' + pluginName + ' plugin but it\'s not installed. Install the ' + plugin + ' plugin'); + } +}; +exports.cordovaWarn = function (pluginName, method) { + if (method) { + console.warn('Native: tried calling ' + pluginName + '.' + method + ', but Cordova is not available. Make sure to include cordova.js or run in a device/simulator'); + } + else { + console.warn('Native: tried accessing the ' + pluginName + ' plugin but Cordova is not available. Make sure to include cordova.js or run in a device/simulator'); + } +}; +function callCordovaPlugin(pluginObj, methodName, args, opts, resolve, reject) { + if (opts === void 0) { opts = {}; } + if (!window.cordova) { + exports.cordovaWarn(pluginObj.name, methodName); + } + if (opts.callbackOrder == 'reverse') { + args.unshift(reject); + args.unshift(resolve); + } + else if (typeof opts.successIndex !== 'undefined' || typeof opts.errorIndex !== 'undefined') { + args.splice(opts.successIndex, 0, resolve); + args.splice(opts.errorIndex, 0, reject); + } + else { + args.push(resolve); + args.push(reject); + } + var pluginInstance = exports.getPlugin(pluginObj.pluginRef); + if (!pluginInstance) { + exports.pluginWarn(pluginObj.name, methodName, pluginObj.name); + reject({ + error: 'plugin_not_installed' + }); + return; + } + console.log('Cordova calling', pluginObj.name, methodName, args); + return util_1.get(window, pluginObj.pluginRef)[methodName].apply(pluginInstance, args); +} +function wrapPromise(pluginObj, methodName, args, opts) { + if (opts === void 0) { opts = {}; } + return new Promise(function (resolve, reject) { + callCordovaPlugin(pluginObj, methodName, args, opts, resolve, reject); + }); +} +function wrapObservable(pluginObj, methodName, args, opts) { + if (opts === void 0) { opts = {}; } + return new Rx_1.Observable(function (observer) { + console.log('Calling inside observable', observer); + var pluginResult = callCordovaPlugin(pluginObj, methodName, args, opts, function (d) { + console.log('WATCH RESP', d); + observer.next(d); + }, observer.error); + return function () { + return util_1.get(window, pluginObj.pluginRef)[opts.clearFunction].apply(pluginObj, pluginResult); + }; + }); +} +exports.wrap = function (pluginObj, methodName, opts) { + if (opts === void 0) { opts = {}; } + return function () { + var args = []; + for (var _i = 0; _i < arguments.length; _i++) { + args[_i - 0] = arguments[_i]; + } + if (opts.observable) { + console.log("Wrapping observable"); + return wrapObservable(pluginObj, methodName, args, opts); + } + else { + return wrapPromise(pluginObj, methodName, args, opts); + } + }; +}; +function Plugin(config) { + return function (cls) { + for (var k in config) { + cls[k] = config[k]; + } + return cls; + }; +} +exports.Plugin = Plugin; +function Cordova(opts) { + if (opts === void 0) { opts = {}; } + 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).apply(this, args); + } + }; + }; +} +exports.Cordova = Cordova; +function RequiresPlugin(target, key, descriptor) { + var originalMethod = descriptor.value; + descriptor.value = function () { + var args = []; + for (var _i = 0; _i < arguments.length; _i++) { + args[_i - 0] = arguments[_i]; + } + console.log('Calling', this); + if (!window.cordova) { + exports.cordovaWarn(this.name, null); + return; + } + var pluginInstance = exports.getPlugin(this.pluginRef); + if (!pluginInstance) { + exports.pluginWarn(this.name, null, this.name); + return; + } + originalMethod.apply(this, args); + }; + return descriptor; +} +exports.RequiresPlugin = RequiresPlugin; +//# sourceMappingURL=plugin.js.map \ No newline at end of file diff --git a/dist/src/plugins/plugin.js.map b/dist/src/plugins/plugin.js.map new file mode 100644 index 000000000..a15ab093f --- /dev/null +++ b/dist/src/plugins/plugin.js.map @@ -0,0 +1 @@ +{"version":3,"file":"plugin.js","sourceRoot":"","sources":["../../../src/plugins/plugin.ts"],"names":["callCordovaPlugin","wrapPromise","wrapObservable","Plugin","Cordova","RequiresPlugin"],"mappings":"AAAA,qBAAkB,SAAS,CAAC,CAAA;AAK5B,mBAAyB,6BAA6B,CAAC,CAAA;AAG1C,iBAAS,GAAG,UAAS,SAAiB;IACjD,MAAM,CAAC,UAAG,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;AAChC,CAAC,CAAA;AACY,mBAAW,GAAG,UAAS,SAAiB;IACnD,MAAM,CAAC,CAAC,CAAC,iBAAS,CAAC,SAAS,CAAC,CAAC;AAChC,CAAC,CAAA;AACY,kBAAU,GAAG,UAAS,UAAkB,EAAE,MAAc,EAAE,MAAc;IACnF,EAAE,CAAA,CAAC,MAAM,CAAC,CAAC,CAAC;QACV,OAAO,CAAC,IAAI,CAAC,wBAAwB,GAAG,UAAU,GAAG,GAAG,GAAG,MAAM;YAC/D,YAAY,GAAG,UAAU,GAAG,wCAAwC;YACpE,MAAM,GAAG,SAAS,CAAC,CAAC;IACxB,CAAC;IAAC,IAAI,CAAC,CAAC;QACN,OAAO,CAAC,IAAI,CAAC,8BAA8B,GAAG,UAAU,GAAG,+CAA+C,GAAG,MAAM,GAAG,SAAS,CAAC,CAAC;IACnI,CAAC;AACH,CAAC,CAAA;AACY,mBAAW,GAA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;IACnC,CAAC,CAAAA;IAEDA,MAAMA,CAACA,UAAUA,CAACA;AACpBA,CAACA;AAnBe,sBAAc,iBAmB7B,CAAA"} \ No newline at end of file diff --git a/src/index.ts b/src/index.ts index 9c099186a..a8037c617 100644 --- a/src/index.ts +++ b/src/index.ts @@ -16,8 +16,11 @@ export * from './plugins/toast'; // an inconsistent plugin is often the culprit. declare var window; +let before = +new Date; + let didFireReady = false; -window.addEventListener('deviceready', function() { +document.addEventListener('deviceready', function() { + console.log('DEVICE READY FIRED AFTER', (+new Date - before), 'ms') didFireReady = true; }) diff --git a/src/plugins/geolocation.ts b/src/plugins/geolocation.ts index df677229c..3cd080945 100644 --- a/src/plugins/geolocation.ts +++ b/src/plugins/geolocation.ts @@ -9,12 +9,13 @@ declare var window; plugin: 'cordova-plugin-geolocation', pluginRef: 'navigator.geolocation' }) -export class Device { +export class Geolocation { @Cordova() static getCurrentPosition(options:any){}; @Cordova({ + callbackOrder: 'reverse', observable: true, clearFunction: 'clearWatch()' }) diff --git a/src/plugins/plugin.ts b/src/plugins/plugin.ts index ec8de10e5..0ec1665b8 100644 --- a/src/plugins/plugin.ts +++ b/src/plugins/plugin.ts @@ -32,10 +32,12 @@ export const cordovaWarn = function(pluginName: string, method: string) { function callCordovaPlugin(pluginObj:any, methodName:string, args:any[], opts:any={}, resolve:any, reject:any) { if(!window.cordova) { cordovaWarn(pluginObj.name, methodName); + /* reject({ error: 'cordova_not_available' }) return; + */ } // Try to figure out where the success/error callbacks need to be bound @@ -43,8 +45,9 @@ function callCordovaPlugin(pluginObj:any, methodName:string, args:any[], opts:an // If the plugin method expects myMethod(success, err, options) if(opts.callbackOrder == 'reverse') { - args[0] = resolve; - args[1] = reject; + // Get those arguments in the order [reject, resolve, ...restOfArgs] + args.unshift(reject); + args.unshift(resolve); } else if(typeof opts.successIndex !== 'undefined' || typeof opts.errorIndex !== 'undefined') { // If we've specified a success/error index args.splice(opts.successIndex, 0, resolve); @@ -68,7 +71,8 @@ function callCordovaPlugin(pluginObj:any, methodName:string, args:any[], opts:an console.log('Cordova calling', pluginObj.name, methodName, args); - return get(window, pluginObj.pluginRef)[methodName].apply(pluginObj, args); + // TODO: Illegal invocation needs window context + return get(window, pluginObj.pluginRef)[methodName].apply(pluginInstance, args); } function wrapPromise(pluginObj:any, methodName:string, args:any[], opts:any={}) { @@ -78,8 +82,12 @@ function wrapPromise(pluginObj:any, methodName:string, args:any[], opts:any={}) } function wrapObservable(pluginObj:any, methodName:string, args:any[], opts:any = {}) { - return Observable.create((observer) => { - let pluginResult = callCordovaPlugin(pluginObj, methodName, args, opts, observer.onNext, observer.onError); + return new Observable(observer => { + console.log('Calling inside observable', observer); + let pluginResult = callCordovaPlugin(pluginObj, methodName, args, opts, (d) => { + console.log('WATCH RESP', d); + observer.next(d) + }, observer.error); return () => { return get(window, pluginObj.pluginRef)[opts.clearFunction].apply(pluginObj, pluginResult);