Skip to content

Commit

Permalink
Remove references to ngCordova
Browse files Browse the repository at this point in the history
ngCordova is now deprecated
https://github.com/ionic-team/ng-cordova#readme

We could move to IonicNative, but not sure how much longer we are going to
stick with Ionic.

Going back to regular cordova plugin calls, which we use in other places as well.
The only places where we were using ngCordova wrappers was for the in-app
browser and the email composer

+ changed the options for the in-app browser to match the new spec in which the
options are in a single string instead of a JSON dict. Without this change, the
browser is not launched properly
  • Loading branch information
shankari committed Jul 31, 2020
1 parent ad5736c commit 61513d9
Show file tree
Hide file tree
Showing 9 changed files with 126 additions and 124 deletions.
1 change: 0 additions & 1 deletion OpenSourceLicenses.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ based on bugs. TODO: Go through the modules, determine the changes and submit th
|--------|---------|
| `www/lib/ionic` | MIT (from [`bower.json`](https://github.com/ionic-team/ionic-bower/blob/v1.3.0/bower.json)) |
| `www/lib/ionic-toast` | MIT |
| `www/lib/ngCordova` | MIT |
| `www/lib/moment` | MIT |
| `www/lib/moment-timezone` | MIT |
| `www/lib/Leaflet.awesome-markers` | MIT |
Expand Down
1 change: 0 additions & 1 deletion bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
"devDependencies": {
"ionic": "driftyco/ionic-bower#1.3.1",
"ionic-toast": "^0.2.0",
"ngCordova": "^0.1.24-alpha",
"moment": "^2.11.2",
"moment-timezone": "^0.5.0",
"leaflet": "^0.7.7",
Expand Down
41 changes: 19 additions & 22 deletions www/js/control/emailService.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

angular.module('emission.services.email', ['emission.plugin.logger'])

.service('EmailHelper', function ($cordovaEmailComposer, $translate, $http, Logger) {
.service('EmailHelper', function ($window, $translate, $http, Logger) {

var getEmailConfig = function () {
const getEmailConfig = function () {
return new Promise(function (resolve, reject) {
window.Logger.log(window.Logger.LEVEL_INFO, "About to get email config");
var address = [];
Expand All @@ -25,16 +25,21 @@ angular.module('emission.services.email', ['emission.plugin.logger'])
});
}

const hasAccount = function() {
return new Promise(function(resolve, reject) {
$window.cordova.plugins.email.hasAccount(function (hasAct) {
resolve(hasAct);
});
});
}

this.sendEmail = function (database) {
getEmailConfig().then(function (address) {
Promise.all([getEmailConfig(), hasAccount()]).then(function([address, hasAct]) {
var parentDir = "unknown";

$cordovaEmailComposer.isAvailable().then(function () {
// is available
}, function () {
if (!hasAct) {
alert($translate.instant('email-service.email-account-not-configured'));
return;
});
}

if (ionic.Platform.isAndroid()) {
parentDir = "app://databases";
Expand Down Expand Up @@ -64,19 +69,11 @@ angular.module('emission.services.email', ['emission.plugin.logger'])
body: $translate.instant('email-service.email-log.body-please-fill-in-what-is-wrong')
}

$cordovaEmailComposer.open(email).then(function () {
window.Logger.log(window.Logger.LEVEL_DEBUG,
"Email queued successfully");
},
function () {
// user cancelled email. in this case too, we want to remove the file
// so that the file creation earlier does not fail.
window.Logger.log(window.Logger.LEVEL_INFO,
"Email cancel reported, seems to be an error on android");
});
}).catch(function (err) {
alert($translate.instant('email-service.no-email-address-configured') + err);
return;
$window.cordova.plugins.email.open(email, function () {
Logger.log("email app closed while sending, "+JSON.stringify(email)+" not sure if we should do anything");
// alert($translate.instant('email-service.no-email-address-configured') + err);
return;
});
});
};
});
});
1 change: 0 additions & 1 deletion www/js/diary/current.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
angular.module('emission.main.diary.current', ['ui-leaflet',
'ngCordova',
'emission.services',
'ionic',
'emission.incident.posttrip.manual',
Expand Down
56 changes: 26 additions & 30 deletions www/js/goals.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ angular.module('emission.main.goals',['emission.services', 'emission.plugin.logg
'ng-walkthrough', 'nzTour'])

.controller('GoalsCtrl', function(CommHelper, $state, $ionicLoading, $ionicPlatform, $scope, $rootScope, $ionicModal, nzTour,
$window, $http, $ionicPopup, $timeout, KVStore, ReferralHandler, ReferHelper, Logger, $cordovaInAppBrowser, SurveyLaunch) {
$window, $http, $ionicPopup, $timeout, KVStore, ReferralHandler, ReferHelper, Logger, SurveyLaunch) {
$scope.goals = [];
$scope.goal = {};
$scope.challenges=[];
Expand All @@ -24,6 +24,7 @@ angular.module('emission.main.goals',['emission.services', 'emission.plugin.logg
var floatGold;
var refresh;
var HABITICA_REGISTERED_KEY = 'habitica_registered';
var iab;
//var challengeMembersId = [];

// THIS BLOCK FOR inAppBrowser
Expand Down Expand Up @@ -150,36 +151,31 @@ angular.module('emission.main.goals',['emission.services', 'emission.plugin.logg
/*$scope.data = {
showDelete: false
};*/
$scope.toBrowser = function() {
var options = {
location: 'no',
clearcache: 'no',
toolbar: 'yes'
};
var settings = localStorage.getItem("habit-mobile-settings");
$scope.toBrowser = function() {
var options = {
location: 'no',
clearcache: 'no',
toolbar: 'yes'
};

var settings = localStorage.getItem("habit-mobile-settings");

$rootScope.$on('$cordovaInAppBrowser:loadstop', function(e, event){
// insert Javascript via code / file
if (event.url == 'https://em-game.eecs.berkeley.edu/static/front' ||
event.url == 'https://em-game.eecs.berkeley.edu/static/front#/tasks') {
$cordovaInAppBrowser.executeScript({
code: "localStorage.setItem('habit-mobile-settings', '" + settings + "');"
+ "window.location.href = 'https://em-game.eecs.berkeley.edu/#/tasks';"
});
} else {
Logger.log("checking for game loadstop, finished loading url "+event.url+" ignoring...");
}
});
$cordovaInAppBrowser.open('https://em-game.eecs.berkeley.edu/#/tasks', '_blank', options)
.then(function(event) {
// success
})
.catch(function(error) {
Logger.displayError("Error while launching habitica website", error);
// error
});

iab = $window.cordova.InAppBrowser.open('https://em-game.eecs.berkeley.edu/#/tasks', '_blank', options);
iab.addEventListener('loadstop', function(event){
// insert Javascript via code / file
if (event.url == 'https://em-game.eecs.berkeley.edu/static/front' ||
event.url == 'https://em-game.eecs.berkeley.edu/static/front#/tasks') {
iab.executeScript({
code: "localStorage.setItem('habit-mobile-settings', '" + settings + "');"
+ "window.location.href = 'https://em-game.eecs.berkeley.edu/#/tasks';"
});
} else {
Logger.log("checking for game loadstop, finished loading url "+event.url+" ignoring...");
}
});
iab.addEventListener('loaderror', function(event){
Logger.displayError("Error while launching habitica website", JSON.stringify(event));
});
};

$scope.openLeaderboard = function() {
Expand Down
29 changes: 27 additions & 2 deletions www/js/intro.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ angular.module('emission.intro', ['emission.splash.startprefs',
})

.controller('IntroCtrl', function($scope, $state, $window, $ionicSlideBoxDelegate,
$ionicPopup, $ionicHistory, ionicToast, $timeout, CommHelper, StartPrefs, $translate, $cordovaFile) {
$ionicPopup, $ionicHistory, ionicToast, $timeout, CommHelper, StartPrefs, $translate) {

$scope.platform = $window.device.platform;
$scope.osver = $window.device.version.split(".")[0];
Expand All @@ -45,6 +45,31 @@ angular.module('emission.intro', ['emission.splash.startprefs',
$scope.allowBackgroundInstructions = $translate.instant("intro.allow_background.samsung");
}

// copy-pasted from ngCordova, and updated to promises
$scope.checkFile = function(directory, fn) {
return new Promise(function(resolve, reject) {
if ((/^\//.test(file))) {
reject('directory cannot start with \/');
}

try {
var directory = path + file;
$window.resolveLocalFileSystemURL(directory, function (fileSystem) {
if (fileSystem.isFile === true) {
resolve(fileSystem);
} else {
reject({code: 13, message: 'input is not a file'});
}
}, function (error) {
reject({code: error.code, message: "error while resolving URL "+directory});
});
} catch (err) {
err.message = "$window.resolveLocalFileSystemURL not found";
reject(err);
}
});
}

console.log("Explanation = "+$scope.locationPermExplanation);

// The language comes in between the first and second part
Expand All @@ -53,7 +78,7 @@ angular.module('emission.intro', ['emission.splash.startprefs',
var defaultVal = fpFirstPart + fpSecondPart;
if (lang != 'en') {
var url = fpFirstPart + lang + fpSecondPart;
$cordovaFile.checkFile(cordova.file.applicationDirectory, url).then( function(result){
$scope.checkFile(cordova.file.applicationDirectory, url).then( function(result){
window.Logger.log(window.Logger.LEVEL_DEBUG,
"Successfully found the consent file, result is " + JSON.stringify(result));
return url.replace("www/", "");
Expand Down
2 changes: 1 addition & 1 deletion www/js/recent.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
angular.module('emission.main.recent', ['ngCordova', 'emission.services'])
angular.module('emission.main.recent', ['emission.services'])


.controller('appCtrl', function($scope, $timeout) {
Expand Down
4 changes: 2 additions & 2 deletions www/js/services.js
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ angular.module('emission.services', ['emission.plugin.logger',
return combinedPromise(localPromise, remotePromise, combineWithDedup);
}
})
.service('ControlHelper', function($cordovaEmailComposer,
.service('ControlHelper', function($window,
$ionicPopup,
$translate,
CommHelper,
Expand Down Expand Up @@ -363,7 +363,7 @@ angular.module('emission.services', ['emission.plugin.logger',
subject: $translate.instant('email-service.email-data.subject-data-dump-from-to', {start: startMoment.format(fmt),end: endMoment.format(fmt)}),
body: $translate.instant('email-service.email-data.body-data-consists-of-list-of-entries')
}
$cordovaEmailComposer.open(email).then(resolve());
$window.cordova.plugins.email.open(email).then(resolve());
}
reader.readAsText(file);
}, function(error) {
Expand Down
Loading

0 comments on commit 61513d9

Please sign in to comment.