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

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

45 lines
1.3 KiB
TypeScript
Raw Normal View History

2018-04-13 17:49:03 +02:00
import { Component, OnInit } from "@angular/core";
2022-06-14 17:10:53 +02:00
import { I18nService } from "@bitwarden/common/abstractions/i18n.service";
import { PlatformUtilsService } from "@bitwarden/common/abstractions/platformUtils.service";
import { SyncService } from "@bitwarden/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
}
2021-12-21 15:43:35 +01:00
}
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");
}
2021-12-21 15:43:35 +01:00
}
2018-04-13 17:49:03 +02:00
}