@ -13,7 +13,7 @@ export default class BrowserPlatformUtilsService implements PlatformUtilsService
@@ -13,7 +13,7 @@ export default class BrowserPlatformUtilsService implements PlatformUtilsService
number ,
{ tryResolve : ( canceled : boolean , password : string ) = > Promise < boolean > ; date : Date }
> ( ) ;
private deviceCache : DeviceType = null ;
private static deviceCache : DeviceType = null ;
constructor (
private messagingService : MessagingService ,
@ -22,28 +22,32 @@ export default class BrowserPlatformUtilsService implements PlatformUtilsService
@@ -22,28 +22,32 @@ export default class BrowserPlatformUtilsService implements PlatformUtilsService
private win : Window & typeof globalThis
) { }
getDevice ( ) : DeviceType {
static getDevice ( win : Window & typeof globalThis ) : DeviceType {
if ( this . deviceCache ) {
return this . deviceCache ;
}
if ( BrowserPlatformUtilsService . isFirefox ( ) ) {
this . deviceCache = DeviceType . FirefoxExtension ;
} else if ( BrowserPlatformUtilsService . isOpera ( this . win ) ) {
} else if ( BrowserPlatformUtilsService . isOpera ( win ) ) {
this . deviceCache = DeviceType . OperaExtension ;
} else if ( BrowserPlatformUtilsService . isEdge ( ) ) {
this . deviceCache = DeviceType . EdgeExtension ;
} else if ( BrowserPlatformUtilsService . isVivaldi ( ) ) {
this . deviceCache = DeviceType . VivaldiExtension ;
} else if ( BrowserPlatformUtilsService . isChrome ( this . win ) ) {
} else if ( BrowserPlatformUtilsService . isChrome ( win ) ) {
this . deviceCache = DeviceType . ChromeExtension ;
} else if ( BrowserPlatformUtilsService . isSafari ( this . win ) ) {
} else if ( BrowserPlatformUtilsService . isSafari ( win ) ) {
this . deviceCache = DeviceType . SafariExtension ;
}
return this . deviceCache ;
}
getDevice ( ) : DeviceType {
return BrowserPlatformUtilsService . getDevice ( this . win ) ;
}
getDeviceString ( ) : string {
const device = DeviceType [ this . getDevice ( ) ] . toLowerCase ( ) ;
return device . replace ( "extension" , "" ) ;
@ -53,6 +57,9 @@ export default class BrowserPlatformUtilsService implements PlatformUtilsService
@@ -53,6 +57,9 @@ export default class BrowserPlatformUtilsService implements PlatformUtilsService
return ClientType . Browser ;
}
/ * *
* @deprecated Do not call this directly , use getDevice ( ) instead
* /
static isFirefox ( ) : boolean {
return (
navigator . userAgent . indexOf ( " Firefox/" ) !== - 1 ||
@ -64,7 +71,10 @@ export default class BrowserPlatformUtilsService implements PlatformUtilsService
@@ -64,7 +71,10 @@ export default class BrowserPlatformUtilsService implements PlatformUtilsService
return this . getDevice ( ) === DeviceType . FirefoxExtension ;
}
static isChrome ( win : Window & typeof globalThis ) : boolean {
/ * *
* @deprecated Do not call this directly , use getDevice ( ) instead
* /
private static isChrome ( win : Window & typeof globalThis ) : boolean {
return win . chrome && navigator . userAgent . indexOf ( " Chrome/" ) !== - 1 ;
}
@ -72,7 +82,10 @@ export default class BrowserPlatformUtilsService implements PlatformUtilsService
@@ -72,7 +82,10 @@ export default class BrowserPlatformUtilsService implements PlatformUtilsService
return this . getDevice ( ) === DeviceType . ChromeExtension ;
}
static isEdge ( ) : boolean {
/ * *
* @deprecated Do not call this directly , use getDevice ( ) instead
* /
private static isEdge ( ) : boolean {
return navigator . userAgent . indexOf ( " Edg/" ) !== - 1 ;
}
@ -80,7 +93,10 @@ export default class BrowserPlatformUtilsService implements PlatformUtilsService
@@ -80,7 +93,10 @@ export default class BrowserPlatformUtilsService implements PlatformUtilsService
return this . getDevice ( ) === DeviceType . EdgeExtension ;
}
static isOpera ( win : Window & typeof globalThis ) : boolean {
/ * *
* @deprecated Do not call this directly , use getDevice ( ) instead
* /
private static isOpera ( win : Window & typeof globalThis ) : boolean {
return (
( ! ! win . opr && ! ! win . opr . addons ) || ! ! win . opera || navigator . userAgent . indexOf ( " OPR/" ) >= 0
) ;
@ -90,7 +106,10 @@ export default class BrowserPlatformUtilsService implements PlatformUtilsService
@@ -90,7 +106,10 @@ export default class BrowserPlatformUtilsService implements PlatformUtilsService
return this . getDevice ( ) === DeviceType . OperaExtension ;
}
static isVivaldi ( ) : boolean {
/ * *
* @deprecated Do not call this directly , use getDevice ( ) instead
* /
private static isVivaldi ( ) : boolean {
return navigator . userAgent . indexOf ( " Vivaldi/" ) !== - 1 ;
}
@ -98,6 +117,9 @@ export default class BrowserPlatformUtilsService implements PlatformUtilsService
@@ -98,6 +117,9 @@ export default class BrowserPlatformUtilsService implements PlatformUtilsService
return this . getDevice ( ) === DeviceType . VivaldiExtension ;
}
/ * *
* @deprecated Do not call this directly , use getDevice ( ) instead
* /
static isSafari ( win : Window & typeof globalThis ) : boolean {
// Opera masquerades as Safari, so make sure we're not there first
return (
@ -105,6 +127,24 @@ export default class BrowserPlatformUtilsService implements PlatformUtilsService
@@ -105,6 +127,24 @@ export default class BrowserPlatformUtilsService implements PlatformUtilsService
) ;
}
private static safariVersion ( ) : string {
return navigator . userAgent . match ( "Version/([0-9.]*)" ) ? . [ 1 ] ;
}
/ * *
* Safari previous to version 16.1 had a bug which caused artifacts on hover in large extension popups .
* https : //bugs.webkit.org/show_bug.cgi?id=218704
* /
static shouldApplySafariHeightFix ( win : Window & typeof globalThis ) : boolean {
if ( BrowserPlatformUtilsService . getDevice ( win ) !== DeviceType . SafariExtension ) {
return false ;
}
const version = BrowserPlatformUtilsService . safariVersion ( ) ;
const parts = version ? . split ( "." ) ? . map ( ( v ) = > Number ( v ) ) ;
return parts ? . [ 0 ] < 16 || ( parts ? . [ 0 ] === 16 && parts ? . [ 1 ] === 0 ) ;
}
isSafari ( ) : boolean {
return this . getDevice ( ) === DeviceType . SafariExtension ;
}