From 0294c2cb6d3a91b89ee419bec7c934dc3d5f7c27 Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Mon, 9 Jul 2018 09:32:24 -0400 Subject: [PATCH] device types for web --- jslib | 2 +- src/app/services/services.module.ts | 2 +- src/services/webPlatformUtils.service.ts | 69 ++++++++++++------------ 3 files changed, 36 insertions(+), 37 deletions(-) diff --git a/jslib b/jslib index 8ac3450d9e..9a73e73351 160000 --- a/jslib +++ b/jslib @@ -1 +1 @@ -Subproject commit 8ac3450d9eee10c54bc35dd931a70bf82f97d0a5 +Subproject commit 9a73e733512e69221d6c74065bc8ec614c7ba0fd diff --git a/src/app/services/services.module.ts b/src/app/services/services.module.ts index 287150039c..10c9798992 100644 --- a/src/app/services/services.module.ts +++ b/src/app/services/services.module.ts @@ -76,7 +76,7 @@ const i18nService = new I18nService(window.navigator.language, 'locales'); const stateService = new StateService(); const broadcasterService = new BroadcasterService(); const messagingService = new BroadcasterMessagingService(broadcasterService); -const platformUtilsService = new WebPlatformUtilsService(messagingService, i18nService); +const platformUtilsService = new WebPlatformUtilsService(i18nService); const storageService: StorageServiceAbstraction = new HtmlStorageService(); const secureStorageService: StorageServiceAbstraction = new MemoryStorageService(); const cryptoFunctionService: CryptoFunctionServiceAbstraction = new WebCryptoFunctionService(window, diff --git a/src/services/webPlatformUtils.service.ts b/src/services/webPlatformUtils.service.ts index a1ff24268e..dcdb8a5805 100644 --- a/src/services/webPlatformUtils.service.ts +++ b/src/services/webPlatformUtils.service.ts @@ -16,44 +16,67 @@ const swal: SweetAlert = _swal as any; export class WebPlatformUtilsService implements PlatformUtilsService { identityClientId: string = 'web'; - private browserCache: string = null; + private browserCache: DeviceType = null; - constructor(private messagingService: MessagingService, private i18nService: I18nService) { } + constructor(private i18nService: I18nService) { } getDevice(): DeviceType { - return DeviceType.Web; + if (this.browserCache != null) { + return this.browserCache; + } + + if (navigator.userAgent.indexOf(' Firefox/') !== -1 || navigator.userAgent.indexOf(' Gecko/') !== -1) { + this.browserCache = DeviceType.FirefoxBrowser; + } else if (navigator.userAgent.indexOf(' OPR/') >= 0) { + this.browserCache = DeviceType.OperaBrowser; + } else if (navigator.userAgent.indexOf(' Edge/') !== -1) { + this.browserCache = DeviceType.EdgeBrowser; + } else if (navigator.userAgent.indexOf(' Vivaldi/') !== -1) { + this.browserCache = DeviceType.VivaldiBrowser; + } else if (navigator.userAgent.indexOf(' Safari/') !== -1 && navigator.userAgent.indexOf('Chrome') === -1) { + this.browserCache = DeviceType.SafariBrowser; + } else if ((window as any).chrome && navigator.userAgent.indexOf(' Chrome/') !== -1) { + this.browserCache = DeviceType.ChromeBrowser; + } else if (navigator.userAgent.indexOf(' Trident/') !== -1) { + this.browserCache = DeviceType.IEBrowser; + } else { + this.browserCache = DeviceType.UnknownBrowser; + } + + return this.browserCache; } getDeviceString(): string { - return 'Web'; + const device = DeviceType[this.getDevice()].toLowerCase(); + return device.replace('browser', ''); } isFirefox(): boolean { - return this.getBrowserType() === 'firefox'; + return this.getDevice() === DeviceType.FirefoxBrowser; } isChrome(): boolean { - return this.getBrowserType() === 'chrome'; + return this.getDevice() === DeviceType.ChromeBrowser; } isEdge(): boolean { - return this.getBrowserType() === 'edge'; + return this.getDevice() === DeviceType.EdgeBrowser; } isOpera(): boolean { - return this.getBrowserType() === 'opera'; + return this.getDevice() === DeviceType.OperaBrowser; } isVivaldi(): boolean { - return this.getBrowserType() === 'vivaldi'; + return this.getDevice() === DeviceType.VivaldiBrowser; } isSafari(): boolean { - return this.getBrowserType() === 'safari'; + return this.getDevice() === DeviceType.SafariBrowser; } isIE(): boolean { - return this.getBrowserType() === 'ie'; + return this.getDevice() === DeviceType.IEBrowser; } isMacAppStore(): boolean { @@ -208,28 +231,4 @@ export class WebPlatformUtilsService implements PlatformUtilsService { } } } - - private getBrowserType(): string { - if (this.browserCache != null) { - return this.browserCache; - } - - if (navigator.userAgent.indexOf(' Firefox/') !== -1 || navigator.userAgent.indexOf(' Gecko/') !== -1) { - this.browserCache = 'firefox'; - } else if (navigator.userAgent.indexOf(' OPR/') >= 0) { - this.browserCache = 'opera'; - } else if (navigator.userAgent.indexOf(' Edge/') !== -1) { - this.browserCache = 'edge'; - } else if (navigator.userAgent.indexOf(' Vivaldi/') !== -1) { - this.browserCache = 'vivaldi'; - } else if (navigator.userAgent.indexOf(' Safari/') !== -1 && navigator.userAgent.indexOf('Chrome') === -1) { - this.browserCache = 'safari'; - } else if ((window as any).chrome && navigator.userAgent.indexOf(' Chrome/') !== -1) { - this.browserCache = 'chrome'; - } else if (navigator.userAgent.indexOf(' Trident/') !== -1) { - this.browserCache = 'ie'; - } - - return this.browserCache; - } }