diff --git a/package.json b/package.json index 06110d84d..1a2b48257 100644 --- a/package.json +++ b/package.json @@ -9,6 +9,7 @@ "dist" ], "dependencies": { + "@angular/core": "^2.4.6", "rxjs": "5.0.0-beta.12" }, "devDependencies": { diff --git a/scripts/build/build.sh b/scripts/build/build.sh index 1c6a71d64..c7332609e 100644 --- a/scripts/build/build.sh +++ b/scripts/build/build.sh @@ -33,4 +33,5 @@ for d in $PLUGINS ; do echo "$NEW_TSCONFIG" > "$PLUGIN_BUILD_DIR/tsconfig.json" ./node_modules/.bin/tsc -p "$PLUGIN_BUILD_DIR/tsconfig.json" echo "$NEW_PACKAGE_JSON" > "$BUILD_PLUGINS_DIST/$BASE/package.json" + exit 0 done diff --git a/scripts/build/plugin-package.json.template b/scripts/build/plugin-package.json.template index b17a41f56..d951d9a34 100644 --- a/scripts/build/plugin-package.json.template +++ b/scripts/build/plugin-package.json.template @@ -7,6 +7,7 @@ "author": "ionic", "license": "MIT", "dependencies": { + "@angular/core": "2.2.1", "@ionic-native/core": "{{VERSION}}" }, "peerDependencies": { diff --git a/src/@ionic-native/core/plugin.ts b/src/@ionic-native/core/plugin.ts index c8610dbfa..a141bdd64 100644 --- a/src/@ionic-native/core/plugin.ts +++ b/src/@ionic-native/core/plugin.ts @@ -121,7 +121,7 @@ export const getPlugin = function(pluginRef: string): any { * @param method */ export const pluginWarn = function(pluginObj: any, method?: string) { - let pluginName = pluginObj.pluginName, plugin = pluginObj.plugin; + let pluginName = pluginObj.constructor.getPluginName(), plugin = pluginObj.constructor.getPlugin(); if (method) { console.warn('Native: tried calling ' + pluginName + '.' + method + ', but the ' + pluginName + ' plugin is not installed.'); } else { @@ -208,12 +208,12 @@ function callCordovaPlugin(pluginObj: any, methodName: string, args: any[], opts // to our promise resolve/reject handlers. args = setIndex(args, opts, resolve, reject); - let pluginInstance = getPlugin(pluginObj.pluginRef); + let pluginInstance = getPlugin(pluginObj.constructor.getPluginRef()); if (!pluginInstance || pluginInstance[methodName] === 'undefined') { // Do this check in here in the case that the Web API for this plugin is available (for example, Geolocation). if (!window.cordova) { - cordovaWarn(pluginObj.pluginName, methodName); + cordovaWarn(pluginObj.constructor.getPluginName(), methodName); return { error: 'cordova_not_available' }; @@ -239,24 +239,11 @@ export function getPromise(cb) { cb(resolve, reject); }); } else { - console.error('No Promise support or polyfill found. To enable Ionic Native support, please add the es6-promise polyfill before this script, or run with a library like Angular 1/2 or on a recent browser.'); + console.error('No Promise support or polyfill found. To enable Ionic Native support, please add the es6-promise polyfill before this script, or run with a library like Angular 2 or on a recent browser.'); } }; - if (window.angular) { - let injector = window.angular.element(document.querySelector('[ng-app]') || document.body).injector(); - if (injector) { - let $q = injector.get('$q'); - return $q((resolve, reject) => { - cb(resolve, reject); - }); - } else { - console.warn('Angular 1 was detected but $q couldn\'t be retrieved. This is usually when the app is not bootstrapped on the html or body tag. Falling back to native promises which won\'t trigger an automatic digest when promises resolve.'); - return tryNativePromise(); - } - } else { - return tryNativePromise(); - } + return tryNativePromise(); } function wrapPromise(pluginObj: any, methodName: string, args: any[], opts: any = {}) { @@ -297,10 +284,10 @@ function wrapObservable(pluginObj: any, methodName: string, args: any[], opts: a if (opts.clearWithArgs) { return callCordovaPlugin(pluginObj, opts.clearFunction, args, opts, observer.next.bind(observer), observer.error.bind(observer)); } - return get(window, pluginObj.pluginRef)[opts.clearFunction].call(pluginObj, pluginResult); + return get(window, pluginObj.constructor.getPluginRef())[opts.clearFunction].call(pluginObj, pluginResult); } } catch (e) { - console.warn('Unable to clear the previous observable watch for', pluginObj.pluginName, methodName); + console.warn('Unable to clear the previous observable watch for', pluginObj.constructor.getPluginName(), methodName); console.error(e); } }; @@ -327,7 +314,7 @@ function wrapInstance(pluginObj: any, methodName: string, opts: any = {}) { } return pluginObj._objectInstance[opts.clearFunction].call(pluginObj, pluginResult); } catch (e) { - console.warn('Unable to clear the previous observable watch for', pluginObj.pluginName, methodName); + console.warn('Unable to clear the previous observable watch for', pluginObj.constructor.getPluginName(), methodName); console.error(e); } }; @@ -365,12 +352,12 @@ function wrapEventObservable(event: string, element: any = window): Observable { return new Observable(observer => { - let pluginInstance = getPlugin(pluginObj.pluginRef); + let pluginInstance = getPlugin(pluginObj.constructor.getPluginRef()); if (!pluginInstance) { // Do this check in here in the case that the Web API for this plugin is available (for example, Geolocation). if (!window.cordova) { - cordovaWarn(pluginObj.pluginName, methodName); + cordovaWarn(pluginObj.constructor.getPluginName(), methodName); observer.error({ error: 'cordova_not_available' }); @@ -466,6 +453,22 @@ export function Plugin(config: PluginConfig) { return true; }; + cls['getPluginName'] = function() { + return config.pluginName; + }; + cls['getPluginRef'] = function() { + return config.pluginRef; + }; + cls['getPluginInstallName'] = function() { + return config.plugin; + }; + cls['getPluginRepo'] = function() { + return config.repo; + }; + cls['getSupportedPlatforms'] = function() { + return config.platforms; + }; + return cls; }; } @@ -478,8 +481,10 @@ export function Plugin(config: PluginConfig) { */ export function Cordova(opts: CordovaOptions = {}) { return (target: Object, methodName: string, descriptor: TypedPropertyDescriptor) => { + console.log('@Cordova()', target, methodName, descriptor); return { value: function(...args: any[]) { + console.log('@Cordova() wrap()', this, methodName, opts); return wrap(this, methodName, opts).apply(this, args); } }; diff --git a/src/@ionic-native/plugins/3dtouch/index.ts b/src/@ionic-native/plugins/3dtouch/index.ts index d36484641..20e89e4e3 100644 --- a/src/@ionic-native/plugins/3dtouch/index.ts +++ b/src/@ionic-native/plugins/3dtouch/index.ts @@ -1,6 +1,8 @@ import { Cordova, Plugin } from '@ionic-native/core'; import { Observable } from 'rxjs/Observable'; +import {Injectable} from '@angular/core'; + declare var window: any; export interface ThreeDeeTouchQuickAction { @@ -126,6 +128,7 @@ export interface ThreeDeeTouchForceTouch { repo: 'https://github.com/EddyVerbruggen/cordova-plugin-3dtouch', platforms: ['iOS'] }) +@Injectable() export class ThreeDeeTouch { /** @@ -133,7 +136,7 @@ export class ThreeDeeTouch { * @returns {Promise} returns a promise that resolves with a boolean that indicates whether the plugin is available or not */ @Cordova() - static isAvailable(): Promise { return; } + isAvailable(): Promise { return; } /** * You can get a notification when the user force touches the webview. The plugin defines a Force Touch when at least 75% of the maximum force is applied to the screen. Your app will receive the x and y coordinates, so you have to figure out which UI element was touched. @@ -142,7 +145,7 @@ export class ThreeDeeTouch { @Cordova({ observable: true }) - static watchForceTouches(): Observable { return; } + watchForceTouches(): Observable { return; } /** * setup the 3D-touch actions, takes an array of objects with the following @@ -155,13 +158,13 @@ export class ThreeDeeTouch { @Cordova({ sync: true }) - static configureQuickActions(quickActions: Array): void { } + configureQuickActions(quickActions: Array): void { } /** * When a home icon is pressed, your app launches and this JS callback is invoked. * @returns {Observable} returns an observable that notifies you when he user presses on the home screen icon */ - static onHomeIconPressed(): Observable { + onHomeIconPressed(): Observable { return new Observable(observer => { if (window.ThreeDeeTouch) { window.ThreeDeeTouch.onHomeIconPressed = observer.next.bind(observer); @@ -179,7 +182,7 @@ export class ThreeDeeTouch { @Cordova({ sync: true }) - static enableLinkPreview(): void { } + enableLinkPreview(): void { } /** * Disabled the link preview feature, if enabled. @@ -187,6 +190,6 @@ export class ThreeDeeTouch { @Cordova({ sync: true }) - static disableLinkPreview(): void { } + disableLinkPreview(): void { } }