2018-06-21 04:27:37 +02:00
|
|
|
import {
|
|
|
|
Component,
|
2018-07-03 15:27:59 +02:00
|
|
|
NgZone,
|
|
|
|
OnDestroy,
|
|
|
|
OnInit,
|
2018-06-21 04:27:37 +02:00
|
|
|
} from '@angular/core';
|
|
|
|
|
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
|
|
|
|
2021-06-07 20:13:58 +02:00
|
|
|
import { BroadcasterService } from 'jslib-angular/services/broadcaster.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;
|
2018-07-03 15:27:59 +02:00
|
|
|
|
|
|
|
constructor(private tokenService: TokenService, private broadcasterService: BroadcasterService,
|
2019-02-18 22:10:32 +01:00
|
|
|
private ngZone: NgZone, private platformUtilsService: PlatformUtilsService) { }
|
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:
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
|
|
|
ngOnDestroy() {
|
|
|
|
this.broadcasterService.unsubscribe(BroadcasterSubscriptionId);
|
|
|
|
}
|
|
|
|
|
|
|
|
async load() {
|
|
|
|
this.premium = await this.tokenService.getPremium();
|
|
|
|
}
|
|
|
|
}
|