1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-16 00:03:56 +00:00

automatic sync intervals

This commit is contained in:
Kyle Spearrin
2018-02-09 15:49:00 -05:00
parent ac647f3184
commit 3b3750734b
3 changed files with 47 additions and 3 deletions

View File

@@ -36,8 +36,11 @@ import { CollectionView } from 'jslib/models/view/collectionView';
import { FolderView } from 'jslib/models/view/folderView';
import { I18nService } from 'jslib/abstractions/i18n.service';
import { MessagingService } from 'jslib/abstractions/messaging.service';
import { SyncService } from 'jslib/abstractions/sync.service';
const SyncInterval = 6 * 60 * 60 * 1000; // 6 hours
@Component({
selector: 'app-vault',
template: template,
@@ -64,7 +67,7 @@ export class VaultComponent implements OnInit {
private componentFactoryResolver: ComponentFactoryResolver, private i18nService: I18nService,
private broadcasterService: BroadcasterService, private changeDetectorRef: ChangeDetectorRef,
private ngZone: NgZone, private syncService: SyncService, private analytics: Angulartics2,
private toasterService: ToasterService) {
private toasterService: ToasterService, private messagingService: MessagingService) {
}
async ngOnInit() {
@@ -104,8 +107,25 @@ export class VaultComponent implements OnInit {
this.toasterService.popAsync('error', null, this.i18nService.t('syncingFailed'));
}
break;
case 'checkSyncVault':
try {
const lastSync = await this.syncService.getLastSync();
let lastSyncAgo = SyncInterval + 1;
if (lastSync != null) {
lastSyncAgo = new Date().getTime() - lastSync.getTime();
}
if (lastSyncAgo >= SyncInterval) {
await this.syncService.fullSync(false);
}
} catch { }
this.messagingService.send('scheduleNextSync');
break;
case 'syncCompleted':
await this.load();
if (message.successfully) {
await this.load();
}
break;
default:
detectChanges = false;