Skip to content
This repository was archived by the owner on May 16, 2019. It is now read-only.

Commit 91c4be8

Browse files
committed
more init sequence connect tweaks
1 parent 0b2ff36 commit 91c4be8

File tree

3 files changed

+38
-21
lines changed

3 files changed

+38
-21
lines changed

js/main.js

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -453,27 +453,29 @@ pageConnectModal.on('cancel', () => {
453453

454454
app.connectHeartbeatSocket();
455455
app.serverConnectModal = new ServerConnectModal().render();
456-
app.serverConnectModal.on('connected', (authenticated) => {
456+
app.serverConnectModal.on('connected', () => {
457457
if (profileLoaded) {
458458
// If we've already loaded called loadProfile() and then, we connect
459459
// to a new server (or reconnect to the same server) we'll reload the
460460
// app since some of the "global" components (Router, PageNav,
461461
// SocketView...) were not designed to handle a new connection.
462-
authenticated && location.reload();
463-
} else {
464-
// clear some flags so the heartbeat events will
465-
// appropriatally loadProfile or launch onboarding
466-
guidCreating = null;
467-
loadProfileNeeded = true;
468-
app.serverConnectModal.close();
469-
$loadingModal.removeClass('hide');
462+
location.reload();
470463
}
471464
});
472465

473466
app.getHeartbeatSocket().on('open', function(e) {
474467
removeStartupRetry();
475468
pageConnectModal.remove();
476469
$loadingModal.removeClass('hide');
470+
471+
if (!profileLoaded) {
472+
// clear some flags so the heartbeat events will
473+
// appropriatally loadProfile or launch onboarding
474+
guidCreating = null;
475+
loadProfileNeeded = true;
476+
app.serverConnectModal.close();
477+
$loadingModal.removeClass('hide');
478+
}
477479
});
478480

479481
app.getHeartbeatSocket().on('close', (startUpRetry = function(e) {
@@ -495,15 +497,24 @@ removeStartupRetry = function() {
495497
clearTimeout(startUpRetry.timeout);
496498
app.getHeartbeatSocket().off('close', startUpRetry);
497499
app.getHeartbeatSocket().on('close', (e) => {
498-
app.serverConnectModal.failConnection(null, app.serverConfigs.getActive())
499-
.open();
500+
app.serverConnectModal.failConnection(null, app.serverConfigs.getActive());
501+
502+
if (app.serverConnectModal.getConnectAttempt()) {
503+
app.serverConnectModal.getConnectAttempt()
504+
.fail(() => {
505+
app.serverConnectModal.open();
506+
});
507+
} else {
508+
app.serverConnectModal.open();
509+
}
500510
});
501511
};
502512

503513
app.getHeartbeatSocket().on('message', function(e) {
504514
if (e.jsonData && e.jsonData.status) {
505515
switch (e.jsonData.status) {
506516
case 'generating GUID':
517+
profileLoaded && location.reload();
507518
if (guidCreating) return;
508519

509520
// todo: put in some timeout in the off chance the guid
@@ -514,6 +525,8 @@ app.getHeartbeatSocket().on('message', function(e) {
514525
launchOnboarding(guidCreating);
515526
break;
516527
case 'GUID generation complete':
528+
profileLoaded && location.reload();
529+
517530
app.serverConfigs.getActive().save({
518531
username: e.jsonData.username,
519532
password: e.jsonData.password

js/templates/pageNav.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ <h3 class="margin0 marginTop25"><%= polyglot.t('Discover') %></h3>
7272
<div class="noOverflow inlineBlock" style="max-width: 171px"><%= ob.connectedServer.name %></div>
7373
<span class="pull-right txt-muted ion-arrow-right-b positionRelative" style="top: 4px"></span>
7474
</a>
75+
<hr/>
7576
<a href="#userPage">
7677
<span class="ion-document-text fontSize12 marginRight2 textOpacity1"></span>
7778
<%= polyglot.t('nav.myPage') %>

js/views/serverConnectModal.js

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ module.exports = BaseModal.extend({
142142
},
143143

144144
onCancelClick: function(e) {
145-
this.connectAttempt && this.connectAttempt.cancel();
145+
this._connectAttempt && this._connectAttempt.cancel();
146146
},
147147

148148
onConnectClick: function(e) {
@@ -155,10 +155,10 @@ module.exports = BaseModal.extend({
155155

156156
// todo: validate args
157157

158-
if (this.connectAttempt && this.connectAttempt.state() === 'pending') return this;
159-
160158
this._connectedServer = configMd;
161159

160+
if (this._connectAttempt && this._connectAttempt.state() === 'pending') return this;
161+
162162
this.serverConfigsVw.setConnectionState({
163163
id: configMd.id,
164164
status: 'connected'
@@ -178,8 +178,8 @@ module.exports = BaseModal.extend({
178178

179179
var msg;
180180

181-
if (this.connectAttempt && this.connectAttempt.state() === 'pending') return this;
182181
if (this._connectedServer && this._connectedServer.id === configMd.id) this._connectedServer = null;
182+
if (this._connectAttempt && this._connectAttempt.state() === 'pending') return this;
183183

184184
this.serverConfigsVw.setConnectionState({
185185
id: configMd.id,
@@ -212,7 +212,7 @@ module.exports = BaseModal.extend({
212212
active configuration in the ServerConfigs collection.`);
213213
}
214214

215-
this.connectAttempt && this.connectAttempt.cancel();
215+
this._connectAttempt && this._connectAttempt.cancel();
216216
this.hideMessageBar();
217217

218218
if (this._connectedServer) {
@@ -232,16 +232,16 @@ module.exports = BaseModal.extend({
232232
this.setModalOptions({ showCloseButton: false });
233233
this.serverConfigs.setActive(configMd.id);
234234

235-
this.connectAttempt = this.attemptConnection().done(() => {
235+
this._connectAttempt = this.attemptConnection().done(() => {
236236
this.succeedConnection(configMd);
237237
}).fail((reason) => {
238238
this.failConnection(reason, configMd)
239239
}).always(() => {
240-
this.connectAttempt = null;
240+
this._connectAttempt = null;
241241
});
242242

243-
this.connectAttempt.serverId = configMd.id;
244-
connectAttempt = this.connectAttempt;
243+
this._connectAttempt.serverId = configMd.id;
244+
connectAttempt = this._connectAttempt;
245245

246246
return connectAttempt;
247247
},
@@ -280,7 +280,6 @@ module.exports = BaseModal.extend({
280280
loginRequest = app.login().done(function(data) {
281281
if (data.success) {
282282
conclude(false, data);
283-
self.trigger('connected', true);
284283
} else {
285284
if (data.reason === 'too many attempts') {
286285
conclude(true, 'failed-auth-too-many');
@@ -341,6 +340,10 @@ module.exports = BaseModal.extend({
341340
return this._connectedServer;
342341
},
343342

343+
getConnectAttempt: function() {
344+
return this._connectAttempt;
345+
},
346+
344347
close: function() {
345348
this.closeConfigForm();
346349
BaseModal.prototype.close.apply(this, arguments);

0 commit comments

Comments
 (0)