Skip to content

Commit

Permalink
Port the deploy code to the latest version
Browse files Browse the repository at this point in the history
Major changes:
- the interface is already promisified, so we don't need to wrap the calls in promises
- some of the functions return slightly different values, supporting them now
- the updatecheck returns a build number that we display for greater debuggability
- Need to add the ionic hosts back to the CSP

Testing done:
- Ran the app with these changes
- Clicked on the link at
    https://e-mission.eecs.berkeley.edu/#/client_setup?new_client=urap2017emotion
- UI was updated to the emotion UI

After the update, we had the following errors:

```
[Error] Failed to load resource: the server responded with a status of 404 () (others.js, line 0)
[Error] Ionic Deploy: Unable to check for updates – TypeError: deploy.init is not a function. (In 'deploy.init(config, resolve, reject)', 'deploy.init' is undefined) — updatecheck.js:38
TypeError: deploy.init is not a function. (In 'deploy.init(config, resolve, reject)', 'deploy.init' is undefined) — updatecheck.js:38(anonymous function) — updatecheck.js:38Promise(anonymous function) — updatecheck.js:33(anonymous function) — updatecheck.js:163(anonymous function) — updatecheck.js:204processQueue — ionic.bundle.js:29127(anonymous function) — ionic.bundle.js:29143$digest — ionic.bundle.js:30211(anonymous function) — ionic.bundle.js:30434completeOutstandingRequest — ionic.bundle.js:19194(anonymous function) — ionic.bundle.js:19470
	(anonymous function) (cordova.js:1540)
	(anonymous function) (updatecheck.js:199)
	promiseReactionJob
[Error] Refused to load unsafe:ionic://localhost/img/neutralbear.gif because it does not appear in the img-src directive of the Content Security Policy.
```

These are because the channel has not yet been updated to use the new UI
changes with the new updatecheck code and the `ionic:` whitelist. Some of these
(like `others.js`) may also just be obsolete.
  • Loading branch information
shankari committed Jul 1, 2020
1 parent 08a2a53 commit 78503b9
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 39 deletions.
2 changes: 1 addition & 1 deletion www/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@
"downloading-update": "Downloading UI-only update",
"extracting-update": "Extracting UI-only update",
"done": "Update done, reloading...",
"download-new-ui": "Download new UI-only update?.",
"download-new-ui": "Download new UI-only update to build {{build}}?",
"download-not-now": "Not now",
"download-apply": "Apply"
},
Expand Down
2 changes: 1 addition & 1 deletion www/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">
<meta http-equiv="Content-Security-Policy" content="default-src 'self' data: gap: https://ssl.gstatic.com https://nominatim.openstreetmap.org emission: 'unsafe-eval'; style-src 'self' 'unsafe-inline'; script-src 'self' 'unsafe-inline' 'unsafe-eval'; img-src 'self' data: http://tile.stamen.com https://stamen-tiles.a.ssl.fastly.net https://stamen-tiles-*.a.ssl.fastly.net 'unsafe-inline'">
<meta http-equiv="Content-Security-Policy" content="default-src 'self' data: gap: https://ssl.gstatic.com https://api.ionicjs.com https://pro-deploy.ionicjs.com https://nominatim.openstreetmap.org emission: 'unsafe-eval'; style-src 'self' 'unsafe-inline'; script-src 'self' 'unsafe-inline' 'unsafe-eval'; img-src 'self' data: http://tile.stamen.com https://stamen-tiles.a.ssl.fastly.net https://stamen-tiles-*.a.ssl.fastly.net 'unsafe-inline'">
<title></title>

<link href="lib/ionic/css/ionic.css" rel="stylesheet">
Expand Down
50 changes: 13 additions & 37 deletions www/js/splash/updatecheck.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,11 @@ angular.module('emission.splash.updatecheck', ['emission.plugin.logger',
Logger.log("currChannel == null, skipping deploy init");
return Promise.resolve(null);
} else {
return new Promise(function(resolve, reject) {
var config = {
appId: "e0d8cdec",
channel: currChannel
}
deploy.init(config, resolve, reject);
});
var config = {
appId: "e0d8cdec",
channel: currChannel
}
return deploy.configure(config);
}
};

Expand All @@ -48,44 +46,22 @@ angular.module('emission.splash.updatecheck', ['emission.plugin.logger',

uc.checkPromise = function() {
var deploy = $window.IonicCordova.deploy;
return new Promise(function(resolve, reject) {
deploy.check(resolve, reject);
});
return deploy.checkForUpdate();
};

uc.downloadPromise = function() {
var deploy = $window.IonicCordova.deploy;
return new Promise(function(resolve, reject) {
deploy.download(function(res) {
if(res == 'true') {
resolve(res);
} else {
updateProgress(res);
}
}, reject);
});
return deploy.downloadUpdate(updateProgress);
};

uc.extractPromise = function() {
var deploy = $window.IonicCordova.deploy;
return new Promise(function(resolve, reject) {
deploy.extract(function(res) {
console.log("extract progress = "+res);
var expectedResult = $window.cordova.platformId == "ios"? "done": "true";
if(res == expectedResult) {
resolve(res);
} else {
updateProgress(res);
}
}, reject);
});
return deploy.extractUpdate(updateProgress);
};

uc.redirectPromise = function() {
var deploy = $window.IonicCordova.deploy;
return new Promise(function(resolve, reject) {
deploy.redirect(resolve, reject);
});
return deploy.reloadApp();
};

uc.handleClientChangeURL = function(urlComponents) {
Expand Down Expand Up @@ -166,13 +142,13 @@ angular.module('emission.splash.updatecheck', ['emission.plugin.logger',
getChannelToUse().then(function(currChannel) {
uc.initChannelPromise(currChannel).then(function() {
Logger.log("deploy init complete ");
uc.checkPromise().then(function(hasUpdate) {
Logger.log('Ionic Deploy: Update available: ' + hasUpdate);
if (hasUpdate == 'true') {
uc.checkPromise().then(function(updateResponse) {
Logger.log('Ionic Deploy: Update available: ' + JSON.stringify(updateResponse));
if (updateResponse.available == true) {
Logger.log('Ionic Deploy: found update, asking user: ');

$ionicPopup.show({
title: $translate.instant('updatecheck.download-new-ui'),
title: $translate.instant('updatecheck.download-new-ui', updateResponse),
templateUrl: 'templates/splash/release-notes.html',
scope: $rootScope,
buttons: [{ // Array[Object] (optional). Buttons to place in the popup footer.
Expand Down

0 comments on commit 78503b9

Please sign in to comment.