This commit is contained in:
2026-05-11 18:42:05 +03:30
parent 88adb566eb
commit 9bcb917d3b
17 changed files with 185 additions and 17 deletions
+2 -1
View File
@@ -8,6 +8,7 @@ import { Router } from '@angular/router';
import { CookieService } from 'ngx-cookie-service';
import { BehaviorSubject, Observable, throwError } from 'rxjs';
import { catchError, finalize, tap } from 'rxjs/operators';
import config from 'src/config';
import { COOKIE_KEYS, LOCAL_STORAGE_KEYS } from '../../../assets/constants';
import {
IAuthAccountResponse,
@@ -75,7 +76,7 @@ export class AuthService {
return this.http
.post<IAuthResponse>(
'/api/v1/auth/login',
{ username, password },
{ username, password, isPos: config.isPosApplication },
{
headers: baseHeaders,
},
+1
View File
@@ -4,3 +4,4 @@ export { ErrorHandlerService } from './error-handler.service';
export { ConfigService } from './config.service';
export * from './breadcrumb.service';
export * from './native-bridge.service';
export * from './pwa-install.service';
@@ -0,0 +1,66 @@
import { Injectable, signal } from '@angular/core';
import { ConfirmationService } from 'primeng/api';
@Injectable({ providedIn: 'root' })
export class PwaInstallService {
private deferredInstallPrompt: any = null;
readonly isInstalled = signal(false);
readonly canInstall = signal(false);
constructor(private readonly confirmationService: ConfirmationService) {
this.init();
}
init() {
if (typeof window === 'undefined') {
return;
}
const standalone =
window.matchMedia('(display-mode: standalone)').matches ||
(window.navigator as any).standalone === true;
console.log(window.matchMedia('(display-mode: standalone)').matches);
console.log(window.navigator);
this.isInstalled.set(standalone);
window.addEventListener('beforeinstallprompt', (event: any) => {
event.preventDefault();
this.deferredInstallPrompt = event;
this.canInstall.set(true);
console.log(this.deferredInstallPrompt);
});
window.addEventListener('appinstalled', () => {
this.deferredInstallPrompt = null;
this.canInstall.set(false);
this.isInstalled.set(true);
});
}
openInstallConfirm() {
if (this.isInstalled() || !this.canInstall() || !this.deferredInstallPrompt) {
return;
}
console.log('openInstallConfirm');
this.confirmationService.confirm({
header: 'نصب اپلیکیشن',
message: 'برای ادامه می‌بایست نیازمندی‌های نرم‌افزار را نصب کنید',
acceptLabel: 'نصب',
rejectButtonProps: {
outlined: true,
},
accept: () => {
this.deferredInstallPrompt.prompt();
this.deferredInstallPrompt.userChoice.finally(() => {
this.deferredInstallPrompt = null;
this.canInstall.set(false);
});
},
});
}
}