bitwarden-estensione-browser/src/app/settings/settings.component.ts

50 lines
1.4 KiB
TypeScript
Raw Normal View History

2018-06-21 04:27:37 +02:00
import {
Component,
NgZone,
OnDestroy,
OnInit,
2018-06-21 04:27:37 +02:00
} from '@angular/core';
2019-02-18 22:10:32 +01:00
import { PlatformUtilsService } from 'jslib/abstractions/platformUtils.service';
import { TokenService } from 'jslib/abstractions/token.service';
import { BroadcasterService } from 'jslib/angular/services/broadcaster.service';
const BroadcasterSubscriptionId = 'SettingsComponent';
2018-06-21 04:27:37 +02:00
@Component({
selector: 'app-settings',
templateUrl: 'settings.component.html',
})
export class SettingsComponent implements OnInit, OnDestroy {
premium: boolean;
2019-02-18 22:10:32 +01:00
selfHosted: boolean;
constructor(private tokenService: TokenService, private broadcasterService: BroadcasterService,
2019-02-18 22:10:32 +01:00
private ngZone: NgZone, private platformUtilsService: PlatformUtilsService) { }
async ngOnInit() {
this.broadcasterService.subscribe(BroadcasterSubscriptionId, async (message: any) => {
this.ngZone.run(async () => {
switch (message.command) {
case 'purchasedPremium':
await this.load();
break;
default:
}
});
});
2019-02-18 22:10:32 +01:00
this.selfHosted = await this.platformUtilsService.isSelfHost();
await this.load();
}
ngOnDestroy() {
this.broadcasterService.unsubscribe(BroadcasterSubscriptionId);
}
async load() {
this.premium = await this.tokenService.getPremium();
}
}