|
@@ -16,6 +16,7 @@ import { generateId } from 'angularlib/base.service';
|
|
|
import { Store } from '@ngxs/store';
|
|
import { Store } from '@ngxs/store';
|
|
|
import config from '../config/config.json';
|
|
import config from '../config/config.json';
|
|
|
import { UIAuthActions } from 'angularlib/login/state/login.actions';
|
|
import { UIAuthActions } from 'angularlib/login/state/login.actions';
|
|
|
|
|
+import { Platform } from '@angular/cdk/platform';
|
|
|
|
|
|
|
|
@Component({
|
|
@Component({
|
|
|
selector: 'app-root',
|
|
selector: 'app-root',
|
|
@@ -69,7 +70,8 @@ export class AppComponent extends BaseComponent implements OnInit {
|
|
|
/**Platform Browser title */
|
|
/**Platform Browser title */
|
|
|
protected pbTitle: Title,
|
|
protected pbTitle: Title,
|
|
|
protected cs: ComponentService,
|
|
protected cs: ComponentService,
|
|
|
- private route: ActivatedRoute
|
|
|
|
|
|
|
+ private route: ActivatedRoute,
|
|
|
|
|
+ private platform: Platform
|
|
|
) {
|
|
) {
|
|
|
super(store,cs);
|
|
super(store,cs);
|
|
|
}
|
|
}
|
|
@@ -106,6 +108,8 @@ export class AppComponent extends BaseComponent implements OnInit {
|
|
|
this.notificationCount = state.notifications.length;
|
|
this.notificationCount = state.notifications.length;
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
|
|
|
+
|
|
|
|
|
+ if (this.platform.ANDROID || this.platform.IOS) this.pwaPrompt();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -121,4 +125,31 @@ export class AppComponent extends BaseComponent implements OnInit {
|
|
|
message:{title:generateId(),desc:generateId(),timestamp: new Date()}
|
|
message:{title:generateId(),desc:generateId(),timestamp: new Date()}
|
|
|
}));
|
|
}));
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ /**prompt to install PWA App */
|
|
|
|
|
+ private pwaPrompt() {
|
|
|
|
|
+ let installPrompt = null;
|
|
|
|
|
+ const installButton = document.querySelector("#installApp");
|
|
|
|
|
+
|
|
|
|
|
+ const disableInAppInstallPrompt = () => {
|
|
|
|
|
+ installPrompt = null;
|
|
|
|
|
+ installButton.setAttribute("hidden","");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ window.addEventListener("beforeinstallprompt",(event) => {
|
|
|
|
|
+ event.preventDefault();
|
|
|
|
|
+ installPrompt = event;
|
|
|
|
|
+ installButton.removeAttribute("hidden");
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ installButton.addEventListener("click", async () => {
|
|
|
|
|
+ if (!installPrompt) return;
|
|
|
|
|
+ const result = await installPrompt.prompt();
|
|
|
|
|
+ disableInAppInstallPrompt();
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ window.addEventListener("appinstalled", () => {
|
|
|
|
|
+ disableInAppInstallPrompt();
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|