mirror of
https://github.com/bitwarden/web
synced 2025-12-15 07:43:16 +00:00
device types for web
This commit is contained in:
2
jslib
2
jslib
Submodule jslib updated: 8ac3450d9e...9a73e73351
@@ -76,7 +76,7 @@ const i18nService = new I18nService(window.navigator.language, 'locales');
|
|||||||
const stateService = new StateService();
|
const stateService = new StateService();
|
||||||
const broadcasterService = new BroadcasterService();
|
const broadcasterService = new BroadcasterService();
|
||||||
const messagingService = new BroadcasterMessagingService(broadcasterService);
|
const messagingService = new BroadcasterMessagingService(broadcasterService);
|
||||||
const platformUtilsService = new WebPlatformUtilsService(messagingService, i18nService);
|
const platformUtilsService = new WebPlatformUtilsService(i18nService);
|
||||||
const storageService: StorageServiceAbstraction = new HtmlStorageService();
|
const storageService: StorageServiceAbstraction = new HtmlStorageService();
|
||||||
const secureStorageService: StorageServiceAbstraction = new MemoryStorageService();
|
const secureStorageService: StorageServiceAbstraction = new MemoryStorageService();
|
||||||
const cryptoFunctionService: CryptoFunctionServiceAbstraction = new WebCryptoFunctionService(window,
|
const cryptoFunctionService: CryptoFunctionServiceAbstraction = new WebCryptoFunctionService(window,
|
||||||
|
|||||||
@@ -16,44 +16,67 @@ const swal: SweetAlert = _swal as any;
|
|||||||
export class WebPlatformUtilsService implements PlatformUtilsService {
|
export class WebPlatformUtilsService implements PlatformUtilsService {
|
||||||
identityClientId: string = 'web';
|
identityClientId: string = 'web';
|
||||||
|
|
||||||
private browserCache: string = null;
|
private browserCache: DeviceType = null;
|
||||||
|
|
||||||
constructor(private messagingService: MessagingService, private i18nService: I18nService) { }
|
constructor(private i18nService: I18nService) { }
|
||||||
|
|
||||||
getDevice(): DeviceType {
|
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 {
|
getDeviceString(): string {
|
||||||
return 'Web';
|
const device = DeviceType[this.getDevice()].toLowerCase();
|
||||||
|
return device.replace('browser', '');
|
||||||
}
|
}
|
||||||
|
|
||||||
isFirefox(): boolean {
|
isFirefox(): boolean {
|
||||||
return this.getBrowserType() === 'firefox';
|
return this.getDevice() === DeviceType.FirefoxBrowser;
|
||||||
}
|
}
|
||||||
|
|
||||||
isChrome(): boolean {
|
isChrome(): boolean {
|
||||||
return this.getBrowserType() === 'chrome';
|
return this.getDevice() === DeviceType.ChromeBrowser;
|
||||||
}
|
}
|
||||||
|
|
||||||
isEdge(): boolean {
|
isEdge(): boolean {
|
||||||
return this.getBrowserType() === 'edge';
|
return this.getDevice() === DeviceType.EdgeBrowser;
|
||||||
}
|
}
|
||||||
|
|
||||||
isOpera(): boolean {
|
isOpera(): boolean {
|
||||||
return this.getBrowserType() === 'opera';
|
return this.getDevice() === DeviceType.OperaBrowser;
|
||||||
}
|
}
|
||||||
|
|
||||||
isVivaldi(): boolean {
|
isVivaldi(): boolean {
|
||||||
return this.getBrowserType() === 'vivaldi';
|
return this.getDevice() === DeviceType.VivaldiBrowser;
|
||||||
}
|
}
|
||||||
|
|
||||||
isSafari(): boolean {
|
isSafari(): boolean {
|
||||||
return this.getBrowserType() === 'safari';
|
return this.getDevice() === DeviceType.SafariBrowser;
|
||||||
}
|
}
|
||||||
|
|
||||||
isIE(): boolean {
|
isIE(): boolean {
|
||||||
return this.getBrowserType() === 'ie';
|
return this.getDevice() === DeviceType.IEBrowser;
|
||||||
}
|
}
|
||||||
|
|
||||||
isMacAppStore(): boolean {
|
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user