Index: remoting/webapp/crd/js/host_list.js |
diff --git a/remoting/webapp/crd/js/host_list.js b/remoting/webapp/crd/js/host_list.js |
index 2cf7628b325c420d0f9ada18168468c84a9e68e1..f5bd6f1b4142f9a8780d591d3bdbefc15e801460 100644 |
--- a/remoting/webapp/crd/js/host_list.js |
+++ b/remoting/webapp/crd/js/host_list.js |
@@ -289,10 +289,121 @@ remoting.HostList.prototype.display = function() { |
remoting.updateModalUi(enabled ? 'enabled' : 'disabled', 'data-daemon-state'); |
var element = document.getElementById('daemon-control'); |
element.hidden = !canChangeLocalHostState; |
- element = document.getElementById('host-list-empty-hosting-supported'); |
- element.hidden = !canChangeLocalHostState; |
- element = document.getElementById('host-list-empty-hosting-unsupported'); |
- element.hidden = canChangeLocalHostState; |
+ |
+ if (noHostsRegistered) { |
+ this.showEmptyText_(canChangeLocalHostState); |
+ } |
+}; |
+ |
+/** |
+ * Displays a message to the user when the host list is empty. |
+ * |
+ * @param {boolean} hostingSupported |
+ * @return {void} |
+ * @private |
+ */ |
+remoting.HostList.prototype.showEmptyText_ = function(hostingSupported) { |
Jamie
2015/01/15 20:51:30
"Empty text" suggests that the text is empty, not
kelvinp
2015/01/20 19:41:00
Done.
|
+ /** |
+ * @param {string} email |
+ * @param {string} fullName |
+ * @return {string} |
+ */ |
+ function buildMigrationTips(email, fullName) { |
+ var params = [ |
+ fullName, |
+ email, |
+ '<a href="https://support.google.com/chrome/answer/2364824?hl=en" ' + |
+ 'target="_blank">', |
+ '</a>']; |
+ return l10n.getTranslationOrError( |
+ /*i18n-content*/'HOST_LIST_EMPTY_V2_MIGRATION', params); |
+ } |
+ |
+ var emptyTextDiv = this.noHosts_; |
Jamie
2015/01/15 20:51:30
I'm not sure what the value of this assignment is.
kelvinp
2015/01/20 19:41:00
This variable is necessary for the annonymous func
|
+ |
+ this.isSignedInWithDifferentIdentity_().then( |
+ /** |
+ * @param {{ email: string, fullName: string}} previousIdentity |
+ * @this {remoting.HostList} |
+ */ |
+ function(previousIdentity) { |
+ var buttonLabel = l10n.getTranslationOrError( |
+ /*i18n-content*/'HOME_DAEMON_START_BUTTON'); |
+ |
+ if (Boolean(previousIdentity)) { |
+ emptyTextDiv.innerHTML = buildMigrationTips(previousIdentity.email, |
+ previousIdentity.fullName); |
+ } else if (hostingSupported) { |
+ emptyTextDiv.innerText = l10n.getTranslationOrError( |
+ /*i18n-content*/'HOST_LIST_EMPTY_HOSTING_SUPPORTED', |
+ [buttonLabel]); |
+ } else { |
+ emptyTextDiv.innerText = l10n.getTranslationOrError( |
+ /*i18n-content*/'HOST_LIST_EMPTY_HOSTING_UNSUPPORTED', |
+ [buttonLabel]); |
+ } |
+ } |
+ ); |
+}; |
+ |
+/** |
+ * @return {Promise} A Promise object that would resolve to |
+ * { email: string, fullName: string} if the user has signed in with a |
+ * different account that has hosts registered to it. Otherwise, resolves to |
+ * null. |
+ * @private |
+ */ |
+remoting.HostList.prototype.isSignedInWithDifferentIdentity_ = function() { |
+ if (!base.isAppsV2()) { |
+ return Promise.resolve(null); |
Jamie
2015/01/15 20:51:31
I think my original objection still applies. For t
kelvinp
2015/01/20 19:41:00
Done.
|
+ } |
+ |
+ var getCachedInfo = new Promise( |
Jamie
2015/01/15 20:51:30
s/Info/UserInfo/
You could also consider s/Cached
kelvinp
2015/01/20 19:41:00
Done.
|
+ /** @param {function(*) : void} resolve */ |
+ function(resolve) { |
+ chrome.storage.local.get( |
+ ['remoting-email','remoting-fullname',remoting.HostList.HOSTS_KEY], |
Jamie
2015/01/15 20:51:30
Nit: Spaces between list elements.
Jamie
2015/01/15 20:51:30
These strings are duplicated. You should define th
kelvinp
2015/01/20 19:41:00
Done.
|
+ /** @param {*} results */ |
+ function(results) { resolve(results); } |
+ ); |
+ } |
+ ); |
+ |
+ var getCurrentEmail = new Promise( |
+ /** |
+ * @param {function(*) : void} resolve |
+ * @param {function(*) : void} reject |
+ */ |
+ function(resolve, reject) { |
+ /** |
+ * @param {string} email |
+ * @param {string} name |
+ */ |
+ remoting.identity.getUserInfo(function(email, name) { |
+ resolve(email); |
+ }, reject); |
+ } |
+ ); |
+ |
+ return Promise.all([getCachedInfo, getCurrentEmail]).then( |
+ /** @param {Object} results */ |
+ function(results){ |
+ var cached = /** @type {Object} */ (results[0]); |
Jamie
2015/01/15 20:51:31
s/cached/cachedUserInfo/
|
+ var currentEmail = /** @type {string} */ (results[1]); |
+ var cachedHosts = /** @type {Array} */ |
+ (base.jsonParseSafe(cached[remoting.HostList.HOSTS_KEY])); |
+ var cachedEmail = getStringAttr(cached, 'remoting-email', ''); |
+ var cachedName = getStringAttr(cached, 'remoting-fullname', ''); |
+ |
+ if (cachedEmail && cachedEmail !== currentEmail && |
+ Array.isArray(cachedHosts) && cachedHosts.length !== 0) { |
+ return { |
+ email: cachedEmail, |
+ fullName: cachedName |
+ }; |
+ } |
+ return null; |
+ }); |
}; |
/** |
@@ -459,8 +570,15 @@ remoting.HostList.prototype.onErrorClick_ = function() { |
* Save the host list to local storage. |
*/ |
remoting.HostList.prototype.save_ = function() { |
+ if (this.hosts_.length === 0) { |
+ return; |
+ } |
Jamie
2015/01/15 20:51:30
I don't think this logic is correct. It will preve
kelvinp
2015/01/20 19:41:00
Done.
|
+ |
var items = {}; |
items[remoting.HostList.HOSTS_KEY] = JSON.stringify(this.hosts_); |
+ if (base.isAppsV2()) { |
+ chrome.storage.local.remove('remoting-email'); |
Jamie
2015/01/15 20:51:31
Clearing this here seems a bit ad-hoc. I think you
kelvinp
2015/01/20 19:41:00
Done.
|
+ } |
chrome.storage.local.set(items); |
}; |