import { ChangeDetectionStrategy, Component, Inject } from '@angular/core' import { LoadingController } from '@ionic/angular' import { ErrorToastService } from '@start9labs/shared' import { Observable, Subject, merge } from 'rxjs' import { UpdateToastService } from './update-toast.service' import { ApiService } from '../../../services/api/embassy-api.service' @Component({ selector: 'update-toast', templateUrl: './update-toast.component.html', changeDetection: ChangeDetectionStrategy.OnPush, }) export class UpdateToastComponent { private readonly dismiss$ = new Subject() readonly visible$: Observable = merge(this.dismiss$, this.update$) constructor( @Inject(UpdateToastService) private readonly update$: Observable, private readonly embassyApi: ApiService, private readonly errToast: ErrorToastService, private readonly loadingCtrl: LoadingController, ) {} onDismiss() { this.dismiss$.next(false) } async restart(): Promise { this.onDismiss() const loader = await this.loadingCtrl.create({ message: 'Restarting...', }) await loader.present() try { await this.embassyApi.restartServer({}) } catch (e: any) { await this.errToast.present(e) } finally { await loader.dismiss() } } }