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

Commit a6a6c79

Browse files
committed
fix(native): remove ionic-native dependencies, use raw cordova calls. #190
1 parent 6ad44ab commit a6a6c79

File tree

7 files changed

+15
-34
lines changed

7 files changed

+15
-34
lines changed

package.json

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,7 @@
2828
"typings": "dist/es5/index.d.ts",
2929
"module": "dist/esm/index.js",
3030
"dependencies": {
31-
"ionic-native": "^2.2.11",
32-
"superagent": "1.7.2",
33-
"@ionic/db": "^0.1.0"
31+
"superagent": "1.7.2"
3432
},
3533
"devDependencies": {
3634
"babel-plugin-external-helpers": "^6.8.0",
@@ -75,7 +73,6 @@
7573
"minify": "uglifyjs --compress --mangle --screw-ie8 --source-map dist/bundle/ionic.cloud.min.js.map -o dist/bundle/ionic.cloud.min.js -p relative -- dist/bundle/ionic.cloud.js",
7674
"build": "npm run lint && npm run tsc && npm run rollup && npm run version && npm run minify",
7775
"test": "karma start --singleRun",
78-
"prepublish": "npm run build",
7976
"docs": "node scripts/docs.js",
8077
"watch": "scripts/watch.sh"
8178
}

src/auth.ts

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import { Facebook, FacebookLoginResponse, GooglePlus } from 'ionic-native';
2-
31
import {
42
APIResponseErrorDetails,
53
AuthDependencies,
@@ -641,7 +639,7 @@ export class GoogleAuth extends NativeAuth implements IGoogleAuth {
641639
user.unstore();
642640
user.clear();
643641

644-
GooglePlus.logout().then( () => {
642+
window.plugins.googleplus.logout(() => {
645643
deferred.resolve();
646644
}, (err) => {
647645
deferred.reject(err);
@@ -657,18 +655,13 @@ export class GoogleAuth extends NativeAuth implements IGoogleAuth {
657655
this.emitter.once('cordova:deviceready', () => {
658656
let scope = ['profile', 'email'];
659657

660-
if (!GooglePlus) {
661-
deferred.reject(new Error('Ionic native is not installed'));
662-
return;
663-
}
664-
665658
if (!window || !window.cordova) {
666659
deferred.reject(new Error('Cordova is missing'));
667660
return;
668661
}
669662

670663
if (!window.plugins || !window.plugins.googleplus) {
671-
deferred.reject(new Error('GooglePlus cordova plugin is missing.'));
664+
deferred.reject(new Error('GooglePlus cordova plugin is missing. Install the plugin by following the instructions here: https://github.com/EddyVerbruggen/cordova-plugin-googleplus'));
672665
return;
673666
}
674667

@@ -685,7 +678,7 @@ export class GoogleAuth extends NativeAuth implements IGoogleAuth {
685678
});
686679
}
687680

688-
GooglePlus.login({'webClientId': authConfig.google.webClientId, 'offline': true, 'scopes': scope.join(' ')}).then((success) => {
681+
window.plugins.googleplus.login({'webClientId': authConfig.google.webClientId, 'offline': true, 'scopes': scope.join(' ')}, (success) => {
689682
if (!success.serverAuthCode) {
690683
deferred.reject(new Error('Failed to retrieve offline access token.'));
691684
return;
@@ -738,7 +731,8 @@ export class FacebookAuth extends NativeAuth implements IFacebookAuth {
738731
user.clear();
739732

740733
// Clear the facebook auth.
741-
Facebook.logout().then( () => {
734+
735+
window.facebookConnectPlugin.logout(() => {
742736
deferred.resolve();
743737
}, (err) => {
744738
deferred.reject(err);
@@ -761,11 +755,6 @@ export class FacebookAuth extends NativeAuth implements IFacebookAuth {
761755
}
762756

763757
this.emitter.once('cordova:deviceready', () => {
764-
if (!Facebook) {
765-
deferred.reject(new Error('Ionic native is not installed'));
766-
return;
767-
}
768-
769758
if (!window || !window.cordova) {
770759
deferred.reject(new Error('Cordova is missing.'));
771760
return;
@@ -776,7 +765,7 @@ export class FacebookAuth extends NativeAuth implements IFacebookAuth {
776765
return;
777766
}
778767

779-
Facebook.login(scope).then((r: FacebookLoginResponse) => {
768+
window.facebookConnectPlugin.login(scope, (r: any) => {
780769
scope.splice(scope.indexOf('public_profile'), 1);
781770
const request_object = {
782771
'app_id': this.config.get('app_id'),

src/definitions.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import { Device as NativeDevice } from 'ionic-native';
2-
31
/**
42
* @hidden
53
*/
@@ -277,15 +275,15 @@ export interface DeviceIsConnectedToNetworkOptions {
277275
* @hidden
278276
*/
279277
export interface DeviceDependencies {
280-
nativeDevice: typeof NativeDevice;
278+
nativeDevice: any;
281279
emitter: IEventEmitter;
282280
}
283281

284282
/**
285283
* @hidden
286284
*/
287285
export interface IDevice {
288-
native: typeof NativeDevice;
286+
native: any;
289287
type: string;
290288

291289
isAndroid(): boolean;
@@ -821,7 +819,7 @@ export interface AuthDependencies {
821819
}
822820

823821
/**
824-
* @hidden
822+
* @hidden
825823
*/
826824
export interface NativeAuthDependencies {
827825
config: IConfig;

src/device.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import { Device as NativeDevice } from 'ionic-native';
2-
31
import {
42
DeviceDependencies,
53
DeviceIsConnectedToNetworkOptions,
@@ -15,7 +13,7 @@ declare var navigator: any;
1513
*/
1614
export class Device implements IDevice {
1715

18-
public native: typeof NativeDevice;
16+
public native: any;
1917

2018
public type: string;
2119

src/di.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import { Device as NativeDevice } from 'ionic-native';
2-
31
import {
42
AppStatus,
53
IAuth,
@@ -163,7 +161,8 @@ export class Container {
163161

164162
@cache
165163
public get device(): IDevice {
166-
return new Device({'nativeDevice': NativeDevice, 'emitter': this.eventEmitter});
164+
const cordovaDevice = (window as any).device;
165+
return new Device({'nativeDevice': cordovaDevice, 'emitter': this.eventEmitter});
167166
}
168167

169168
@cache

tsconfig-es5.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"pretty": true,
1414
"removeComments": false,
1515
"sourceMap": true,
16-
"strictNullChecks": true,
16+
"strictNullChecks": false,
1717
"target": "es5"
1818
},
1919
"files": [

tsconfig-esm.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"noImplicitReturns": true,
1111
"outDir": "dist/esm",
1212
"removeComments": false,
13-
"strictNullChecks": true,
13+
"strictNullChecks": false,
1414
"target": "es5"
1515
},
1616
"files": [

0 commit comments

Comments
 (0)