Skip to content
This repository has been archived by the owner on Apr 2, 2018. It is now read-only.

Ionic Native 3.x #199

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,20 @@
"typings": "dist/es5/index.d.ts",
"module": "dist/esm/index.js",
"dependencies": {
"ionic-native": "^2.2.11",
"superagent": "1.7.2",
"@ionic/db": "^0.1.0"
},
"peerDependencies": {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you upgrade the dependencies to native 3.6.1?

"@ionic-native/core": "^3.0.0",
"@ionic-native/device": "^3.0.0",
"@ionic-native/facebook": "^3.0.0",
"@ionic-native/google-plus": "^3.0.0"
},
"devDependencies": {
"@ionic-native/core": "^3.0.0",
"@ionic-native/device": "^3.0.0",
"@ionic-native/facebook": "^3.0.0",
"@ionic-native/google-plus": "^3.0.0",
"babel-plugin-external-helpers": "^6.8.0",
"babel-preset-es2015": "^6.14.0",
"browserify": "^13.1.0",
Expand Down
6 changes: 5 additions & 1 deletion src/angular.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
import { Device as NativeDevice } from '@ionic-native/device';
import { Facebook } from '@ionic-native/facebook';
import { GooglePlus } from '@ionic-native/google-plus';

import { Container as DIContainer } from './di';
import { EventEmitter } from './events';
import { DeferredPromise } from './promise';
Expand All @@ -12,7 +16,7 @@ export function bootstrapAngular1() {
return; // No global angular--this is not an AngularJS project.
}

let container = new DIContainer();
let container = new DIContainer(new NativeDevice(), new Facebook(), new GooglePlus());

angular.element(document).ready(function() {
container.core.init();
Expand Down
29 changes: 22 additions & 7 deletions src/auth.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Facebook, FacebookLoginResponse, GooglePlus } from 'ionic-native';
import { Facebook, FacebookLoginResponse } from '@ionic-native/facebook';
import { GooglePlus } from '@ionic-native/google-plus';

import {
APIResponseErrorDetails,
Expand Down Expand Up @@ -631,6 +632,13 @@ export abstract class NativeAuth {
* @featured
*/
export class GoogleAuth extends NativeAuth implements IGoogleAuth {
private googlePlus: GooglePlus;

constructor(deps: NativeAuthDependencies) {
super(deps);

this.googlePlus = deps.googlePlus;
}

public logout(): Promise<void> {
let deferred = new DeferredPromise<void, Error>();
Expand All @@ -641,7 +649,7 @@ export class GoogleAuth extends NativeAuth implements IGoogleAuth {
user.unstore();
user.clear();

GooglePlus.logout().then( () => {
this.googlePlus.logout().then( () => {
deferred.resolve();
}, (err) => {
deferred.reject(err);
Expand All @@ -657,7 +665,7 @@ export class GoogleAuth extends NativeAuth implements IGoogleAuth {
this.emitter.once('cordova:deviceready', () => {
let scope = ['profile', 'email'];

if (!GooglePlus) {
if (!this.googlePlus) {
deferred.reject(new Error('Ionic native is not installed'));
return;
}
Expand Down Expand Up @@ -685,7 +693,7 @@ export class GoogleAuth extends NativeAuth implements IGoogleAuth {
});
}

GooglePlus.login({'webClientId': authConfig.google.webClientId, 'offline': true, 'scopes': scope.join(' ')}).then((success) => {
this.googlePlus.login({'webClientId': authConfig.google.webClientId, 'offline': true, 'scopes': scope.join(' ')}).then((success) => {
if (!success.serverAuthCode) {
deferred.reject(new Error('Failed to retrieve offline access token.'));
return;
Expand Down Expand Up @@ -727,6 +735,13 @@ export class GoogleAuth extends NativeAuth implements IGoogleAuth {
* @featured
*/
export class FacebookAuth extends NativeAuth implements IFacebookAuth {
private facebook: Facebook;

constructor(deps: NativeAuthDependencies) {
super(deps);

this.facebook = deps.facebook;
}

public logout(): Promise<void> {
let deferred = new DeferredPromise<void, Error>();
Expand All @@ -738,7 +753,7 @@ export class FacebookAuth extends NativeAuth implements IFacebookAuth {
user.clear();

// Clear the facebook auth.
Facebook.logout().then( () => {
this.facebook.logout().then( () => {
deferred.resolve();
}, (err) => {
deferred.reject(err);
Expand All @@ -761,7 +776,7 @@ export class FacebookAuth extends NativeAuth implements IFacebookAuth {
}

this.emitter.once('cordova:deviceready', () => {
if (!Facebook) {
if (!this.facebook) {
deferred.reject(new Error('Ionic native is not installed'));
return;
}
Expand All @@ -776,7 +791,7 @@ export class FacebookAuth extends NativeAuth implements IFacebookAuth {
return;
}

Facebook.login(scope).then((r: FacebookLoginResponse) => {
this.facebook.login(scope).then((r: FacebookLoginResponse) => {
scope.splice(scope.indexOf('public_profile'), 1);
const request_object = {
'app_id': this.config.get('app_id'),
Expand Down
12 changes: 8 additions & 4 deletions src/definitions.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { Device as NativeDevice } from 'ionic-native';
import { Facebook } from '@ionic-native/facebook';
import { GooglePlus } from '@ionic-native/google-plus';
import { Device as NativeDevice } from '@ionic-native/device';
import { IonicDBOptions } from '@ionic/db';

/**
Expand Down Expand Up @@ -290,15 +292,15 @@ export interface DeviceIsConnectedToNetworkOptions {
* @hidden
*/
export interface DeviceDependencies {
nativeDevice: typeof NativeDevice;
nativeDevice: NativeDevice;
emitter: IEventEmitter;
}

/**
* @hidden
*/
export interface IDevice {
native: typeof NativeDevice;
native: NativeDevice;
type: string;

isAndroid(): boolean;
Expand Down Expand Up @@ -834,7 +836,7 @@ export interface AuthDependencies {
}

/**
* @hidden
* @hidden
*/
export interface NativeAuthDependencies {
config: IConfig;
Expand All @@ -843,6 +845,8 @@ export interface NativeAuthDependencies {
storage: IStorage<string>;
tokenContext: ICombinedTokenContext;
emitter: IEventEmitter;
facebook: Facebook;
googlePlus: GooglePlus;
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/device.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Device as NativeDevice } from 'ionic-native';
import { Device as NativeDevice } from '@ionic-native/device';

import {
DeviceDependencies,
Expand All @@ -15,7 +15,7 @@ declare var navigator: any;
*/
export class Device implements IDevice {

public native: typeof NativeDevice;
public native: NativeDevice;

public type: string;

Expand Down
15 changes: 11 additions & 4 deletions src/di.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { Device as NativeDevice } from 'ionic-native';
import { Device as NativeDevice } from '@ionic-native/device';
import { Facebook } from '@ionic-native/facebook';
import { GooglePlus } from '@ionic-native/google-plus';
import { IonicDBOptions } from '@ionic/db';

import {
Expand Down Expand Up @@ -82,6 +84,7 @@ function cache<T>(target: any, propertyKey: string, descriptor: TypedPropertyDes
* @hidden
*/
export class Container {
constructor(private nativeDevice: NativeDevice, private facebook: Facebook, private googlePlus: GooglePlus) { }

@cache
public get appStatus(): AppStatus {
Expand Down Expand Up @@ -165,7 +168,7 @@ export class Container {

@cache
public get device(): IDevice {
return new Device({'nativeDevice': NativeDevice, 'emitter': this.eventEmitter});
return new Device({'nativeDevice': this.nativeDevice, 'emitter': this.eventEmitter});
}

@cache
Expand Down Expand Up @@ -228,7 +231,9 @@ export class Container {
'userService': this.singleUserService,
'storage': new Storage<string>({'strategy': this.localStorageStrategy}),
'tokenContext': this.authTokenContext,
'emitter': this.eventEmitter
'emitter': this.eventEmitter,
'facebook': this.facebook,
'googlePlus': this.googlePlus
});
}

Expand All @@ -240,7 +245,9 @@ export class Container {
'userService': this.singleUserService,
'storage': new Storage<string>({'strategy': this.localStorageStrategy}),
'tokenContext': this.authTokenContext,
'emitter': this.eventEmitter
'emitter': this.eventEmitter,
'facebook': this.facebook,
'googlePlus': this.googlePlus
});
}

Expand Down
2 changes: 1 addition & 1 deletion src/insights.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ export class Insights implements IInsights {
* @private
*/
protected shouldSubmit(): boolean {
return this.batch.length >= this.options.submitCount;
return this.batch.length >= (this.options.submitCount || 0);
}

/**
Expand Down