Skip to content

Commit 2bbdaea

Browse files
authored
Merge pull request #135 from remotestorage/feature/improve_sync_status
Improve sync status display/behavior
2 parents 964570e + ec1afeb commit 2bbdaea

File tree

1 file changed

+21
-19
lines changed

1 file changed

+21
-19
lines changed

src/widget.js

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -67,17 +67,10 @@ class Widget {
6767
}, 1000);
6868
break;
6969
case 'sync-done':
70+
if (this.online && !msg.completed) return;
7071
this.syncInProgress = false;
7172
this.rsSyncButton.classList.remove("rs-rotate");
72-
73-
if (this.rsWidget.classList.contains('rs-state-unauthorized') ||
74-
!this.rs.remote.online) {
75-
this.updateLastSyncedOutput();
76-
} else if (this.rs.remote.online) {
77-
this.lastSynced = new Date();
78-
this.rsConnectedLabel.textContent = 'Synced just now';
79-
}
80-
73+
this.updateLastSyncedStatus();
8174
if (!this.closed && this.shouldCloseWhenSyncDone) {
8275
setTimeout(this.close.bind(this), this.autoCloseAfter);
8376
}
@@ -94,8 +87,8 @@ class Widget {
9487
this.online = true;
9588
if (this.rs.hasFeature('Sync')) {
9689
this.shouldCloseWhenSyncDone = true;
97-
this.rs.on('sync-req-done', () => this.eventHandler('sync-req-done'));
98-
this.rs.on('sync-done', () => this.eventHandler('sync-done'));
90+
this.rs.on('sync-req-done', msg => this.eventHandler('sync-req-done', msg));
91+
this.rs.on('sync-done', msg => this.eventHandler('sync-done', msg));
9992
} else {
10093
this.rsSyncButton.classList.add('rs-hidden');
10194
setTimeout(this.close.bind(this), this.autoCloseAfter);
@@ -122,7 +115,7 @@ class Widget {
122115
} else if (msg.name === 'Unauthorized') {
123116
this.handleUnauthorized(msg);
124117
} else {
125-
console.debug('Encountered unhandled error', msg);
118+
console.debug(`Encountered unhandled error: "${msg}"`);
126119
}
127120
break;
128121
}
@@ -516,7 +509,7 @@ class Widget {
516509
}
517510

518511
handleSyncError (error) {
519-
console.debug('Encountered SyncError', error);
512+
console.debug(`Encountered SyncError: "${error.message}"`);
520513
this.setOffline();
521514
}
522515

@@ -531,12 +524,21 @@ class Widget {
531524
}
532525
}
533526

534-
updateLastSyncedOutput () {
535-
if (!this.lastSynced) { return; } // don't do anything when we've never synced yet
536-
let now = new Date();
537-
let secondsSinceLastSync = Math.round((now.getTime() - this.lastSynced.getTime())/1000);
538-
let subHeadlineEl = document.querySelector('.rs-box-connected .rs-sub-headline');
539-
subHeadlineEl.innerHTML = `Synced ${secondsSinceLastSync} seconds ago`;
527+
updateLastSyncedStatus () {
528+
const now = new Date();
529+
if (this.online) {
530+
this.lastSynced = now;
531+
this.rsConnectedLabel.textContent = 'Synced just now';
532+
return;
533+
}
534+
if (!this.lastSynced) {
535+
if (!this.rsWidget.classList.contains('rs-state-unauthorized')) {
536+
this.rsConnectedLabel.textContent = 'Offline';
537+
}
538+
return;
539+
}
540+
const secondsSinceLastSync = Math.round((now.getTime() - this.lastSynced.getTime())/1000);
541+
this.rsConnectedLabel.textContent = `Synced ${secondsSinceLastSync} seconds ago`;
540542
}
541543

542544
isSmallScreen () {

0 commit comments

Comments
 (0)