bitwarden-estensione-browser/src/popup/settings/sync.component.ts

46 lines
1.4 KiB
TypeScript
Raw Normal View History

2018-04-13 17:49:03 +02:00
import {
Component,
OnInit,
} from '@angular/core';
import { I18nService } from 'jslib-common/abstractions/i18n.service';
2021-12-07 20:42:18 +01:00
import { PlatformUtilsService } from 'jslib-common/abstractions/platformUtils.service';
import { SyncService } from 'jslib-common/abstractions/sync.service';
2018-04-13 17:49:03 +02:00
@Component({
selector: 'app-sync',
templateUrl: 'sync.component.html',
})
export class SyncComponent implements OnInit {
lastSync = '--';
syncPromise: Promise<any>;
2021-12-07 20:42:18 +01:00
constructor(private syncService: SyncService, private platformUtilsService: PlatformUtilsService,
2018-04-13 17:49:03 +02:00
private i18nService: I18nService) {
}
async ngOnInit() {
await this.setLastSync();
}
async sync() {
this.syncPromise = this.syncService.fullSync(true);
const success = await this.syncPromise;
if (success) {
await this.setLastSync();
2021-12-07 20:42:18 +01:00
this.platformUtilsService.showToast('success', null, this.i18nService.t('syncingComplete'));
2018-04-13 17:49:03 +02:00
} else {
2021-12-07 20:42:18 +01:00
this.platformUtilsService.showToast('error', null, this.i18nService.t('syncingFailed'));
2018-04-13 17:49:03 +02:00
}
}
async setLastSync() {
const last = await this.syncService.getLastSync();
if (last != null) {
this.lastSync = last.toLocaleDateString() + ' ' + last.toLocaleTimeString();
} else {
this.lastSync = this.i18nService.t('never');
}
}
}