2018-06-21 04:27:37 +02:00
|
|
|
import { Component, NgZone, OnDestroy, OnInit } from "@angular/core";
|
|
|
|
|
2021-12-07 23:16:47 +01:00
|
|
|
import { BroadcasterService } from "jslib-common/abstractions/broadcaster.service";
|
2021-12-14 17:10:26 +01:00
|
|
|
import { OrganizationService } from "jslib-common/abstractions/organization.service";
|
2021-06-07 20:13:58 +02:00
|
|
|
import { PlatformUtilsService } from "jslib-common/abstractions/platformUtils.service";
|
|
|
|
import { TokenService } from "jslib-common/abstractions/token.service";
|
2018-07-03 15:27:59 +02:00
|
|
|
|
|
|
|
const BroadcasterSubscriptionId = "SettingsComponent";
|
|
|
|
|
2018-06-21 04:27:37 +02:00
|
|
|
@Component({
|
|
|
|
selector: "app-settings",
|
|
|
|
templateUrl: "settings.component.html",
|
|
|
|
})
|
2018-07-03 15:27:59 +02:00
|
|
|
export class SettingsComponent implements OnInit, OnDestroy {
|
|
|
|
premium: boolean;
|
2019-02-18 22:10:32 +01:00
|
|
|
selfHosted: boolean;
|
2021-11-22 14:41:40 +01:00
|
|
|
hasFamilySponsorshipAvailable: boolean;
|
2021-12-17 15:57:11 +01:00
|
|
|
|
2018-07-03 15:27:59 +02:00
|
|
|
constructor(
|
|
|
|
private tokenService: TokenService,
|
|
|
|
private broadcasterService: BroadcasterService,
|
2021-11-22 14:41:40 +01:00
|
|
|
private ngZone: NgZone,
|
|
|
|
private platformUtilsService: PlatformUtilsService,
|
2021-12-14 17:10:26 +01:00
|
|
|
private organizationService: OrganizationService
|
|
|
|
) {}
|
2021-12-17 15:57:11 +01:00
|
|
|
|
2018-07-03 15:27:59 +02:00
|
|
|
async ngOnInit() {
|
|
|
|
this.broadcasterService.subscribe(BroadcasterSubscriptionId, async (message: any) => {
|
|
|
|
this.ngZone.run(async () => {
|
|
|
|
switch (message.command) {
|
|
|
|
case "purchasedPremium":
|
|
|
|
await this.load();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
}
|
|
|
|
});
|
2021-12-17 15:57:11 +01:00
|
|
|
});
|
|
|
|
|
2019-02-18 22:10:32 +01:00
|
|
|
this.selfHosted = await this.platformUtilsService.isSelfHost();
|
2018-07-03 15:27:59 +02:00
|
|
|
await this.load();
|
|
|
|
}
|
2021-12-17 15:57:11 +01:00
|
|
|
|
2018-07-03 15:27:59 +02:00
|
|
|
ngOnDestroy() {
|
|
|
|
this.broadcasterService.unsubscribe(BroadcasterSubscriptionId);
|
|
|
|
}
|
2021-12-17 15:57:11 +01:00
|
|
|
|
2018-07-03 15:27:59 +02:00
|
|
|
async load() {
|
|
|
|
this.premium = await this.tokenService.getPremium();
|
2021-12-14 17:10:26 +01:00
|
|
|
this.hasFamilySponsorshipAvailable = await this.organizationService.canManageSponsorships();
|
2018-07-03 15:27:59 +02:00
|
|
|
}
|
|
|
|
}
|