33 lines
910 B
TypeScript
33 lines
910 B
TypeScript
import { environment } from 'src/environments/environment.prod';
|
|
|
|
export enum DeviceType {
|
|
ios,
|
|
android,
|
|
}
|
|
|
|
export function getTypeDevice(): DeviceType {
|
|
const userAgent = window.navigator.userAgent.toLowerCase();
|
|
const ios = /iphone|ipod|ipad/.test(userAgent);
|
|
return ios ? DeviceType.ios : DeviceType.android;
|
|
}
|
|
|
|
export async function pwaInstalled(): Promise<boolean> {
|
|
if (window.matchMedia('(display-mode: standalone)').matches) return true;
|
|
|
|
if ('getInstalledRelatedApps' in navigator) {
|
|
const apps = await (window.navigator as any).getInstalledRelatedApps();
|
|
for (const app of apps) {
|
|
if (app.url == environment.manifestUrl) {
|
|
return true;
|
|
}
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
export function format(s: string, ...args: string[]) {
|
|
return s.replace(/{(\d+)}/g, function (match, number) {
|
|
return typeof args[number] != 'undefined' ? args[number] : match;
|
|
});
|
|
}
|