Skip to content

Commit ec1afeb

Browse files
committed
Correctly set sync status message in all scenarios
Without this change, when pressing the sync button while the connected state is "offline", it keeps showing "synchronizing" while no sync is running.
1 parent ece903a commit ec1afeb

File tree

1 file changed

+17
-16
lines changed

1 file changed

+17
-16
lines changed

src/widget.js

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -67,18 +67,10 @@ class Widget {
6767
}, 1000);
6868
break;
6969
case 'sync-done':
70-
if (!msg.completed) return;
70+
if (this.online && !msg.completed) return;
7171
this.syncInProgress = false;
7272
this.rsSyncButton.classList.remove("rs-rotate");
73-
74-
if (this.rsWidget.classList.contains('rs-state-unauthorized') ||
75-
!this.rs.remote.online) {
76-
this.updateLastSyncedOutput();
77-
} else if (this.rs.remote.online) {
78-
this.lastSynced = new Date();
79-
this.rsConnectedLabel.textContent = 'Synced just now';
80-
}
81-
73+
this.updateLastSyncedStatus();
8274
if (!this.closed && this.shouldCloseWhenSyncDone) {
8375
setTimeout(this.close.bind(this), this.autoCloseAfter);
8476
}
@@ -532,12 +524,21 @@ class Widget {
532524
}
533525
}
534526

535-
updateLastSyncedOutput () {
536-
if (!this.lastSynced) { return; } // don't do anything when we've never synced yet
537-
let now = new Date();
538-
let secondsSinceLastSync = Math.round((now.getTime() - this.lastSynced.getTime())/1000);
539-
let subHeadlineEl = document.querySelector('.rs-box-connected .rs-sub-headline');
540-
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`;
541542
}
542543

543544
isSmallScreen () {

0 commit comments

Comments
 (0)