Files
psp_panel/src/app/domains/pos/components/splash.component.ts
T

79 lines
2.2 KiB
TypeScript
Raw Normal View History

import { brandingConfig } from '@/branding/branding.config';
2026-05-11 18:42:05 +03:30
import { PwaInstallService } from '@/core/services';
import { Component, effect, EventEmitter, inject, Output } from '@angular/core';
2026-05-11 18:42:05 +03:30
import { ButtonDirective } from 'primeng/button';
import { finalize, forkJoin } from 'rxjs';
import images from 'src/assets/images';
import { PosInfoStore, PosProfileStore } from '../store';
import { DeviceInfoStore } from '../store/device.store';
@Component({
selector: 'pos-splash',
templateUrl: 'splash.component.html',
2026-05-11 18:42:05 +03:30
imports: [ButtonDirective],
})
export class PosSplashComponent {
@Output() onComplete = new EventEmitter<void>();
private readonly posProfileStore = inject(PosProfileStore);
private readonly posInfoStore = inject(PosInfoStore);
private readonly deviceInfoStore = inject(DeviceInfoStore);
2026-05-11 18:42:05 +03:30
private readonly pwaInstallService = inject(PwaInstallService);
logo = images.logo;
// requireInstall = false;
requireInstall = brandingConfig.enableInstallPrompt;
2026-05-11 18:42:05 +03:30
pwaInstalled = this.pwaInstallService.isInstalled;
canInstall = this.pwaInstallService.canInstall;
private installPromptShown = false;
constructor() {
effect(() => {
if (!this.requireInstall || this.pwaInstalled() || this.installPromptShown) {
this.getData();
return;
}
2026-05-11 18:42:05 +03:30
if (this.canInstall()) {
this.installPromptShown = true;
this.pwaInstallService.openInstallConfirm();
}
});
}
async ngOnInit() {
const data = await this.deviceInfoStore.getData();
if (!this.requireInstall || this.pwaInstalled()) {
this.getData();
}
if (this.canInstall()) {
this.pwaInstallService.openInstallConfirm();
this.installPromptShown = true;
}
}
async getData() {
const profileObs = await this.posProfileStore.getData();
const infoObs = await this.posInfoStore.getData();
forkJoin([profileObs, infoObs])
.pipe(
finalize(() => {
this.onComplete.emit();
}),
)
.subscribe(([profileResult, infoResult]) => {});
}
2026-05-11 18:42:05 +03:30
installPwa() {
this.pwaInstallService.openInstallConfirm();
}
continueAfterInstall() {
if (this.pwaInstalled()) {
this.onComplete.emit();
}
}
}