11import {
22 AsyncPipe ,
3+ NgClass ,
34 NgIf ,
45} from '@angular/common' ;
56import {
67 Component ,
8+ Inject ,
79 Input ,
810 OnInit ,
911} from '@angular/core' ;
@@ -13,6 +15,7 @@ import {
1315} from '@angular/router' ;
1416import { TranslateModule } from '@ngx-translate/core' ;
1517import {
18+ BehaviorSubject ,
1619 combineLatest as combineLatestObservable ,
1720 Observable ,
1821 of ,
@@ -30,6 +33,10 @@ import { environment } from '../../environments/environment';
3033import { ThemedAdminSidebarComponent } from '../admin/admin-sidebar/themed-admin-sidebar.component' ;
3134import { getPageInternalServerErrorRoute } from '../app-routing-paths' ;
3235import { ThemedBreadcrumbsComponent } from '../breadcrumbs/themed-breadcrumbs.component' ;
36+ import {
37+ NativeWindowRef ,
38+ NativeWindowService ,
39+ } from '../core/services/window.service' ;
3340import { ThemedFooterComponent } from '../footer/themed-footer.component' ;
3441import { ThemedHeaderNavbarWrapperComponent } from '../header-nav-wrapper/themed-header-navbar-wrapper.component' ;
3542import { slideSidebarPadding } from '../shared/animations/slide' ;
@@ -47,7 +54,20 @@ import { SystemWideAlertBannerComponent } from '../system-wide-alert/alert-banne
4754 styleUrls : [ './root.component.scss' ] ,
4855 animations : [ slideSidebarPadding ] ,
4956 standalone : true ,
50- imports : [ TranslateModule , ThemedAdminSidebarComponent , SystemWideAlertBannerComponent , ThemedHeaderNavbarWrapperComponent , ThemedBreadcrumbsComponent , NgIf , ThemedLoadingComponent , RouterOutlet , ThemedFooterComponent , NotificationsBoardComponent , AsyncPipe ] ,
57+ imports : [
58+ TranslateModule ,
59+ ThemedAdminSidebarComponent ,
60+ SystemWideAlertBannerComponent ,
61+ ThemedHeaderNavbarWrapperComponent ,
62+ ThemedBreadcrumbsComponent ,
63+ NgIf ,
64+ NgClass ,
65+ ThemedLoadingComponent ,
66+ RouterOutlet ,
67+ ThemedFooterComponent ,
68+ NotificationsBoardComponent ,
69+ AsyncPipe ,
70+ ] ,
5171} )
5272export class RootComponent implements OnInit {
5373 theme : Observable < ThemeConfig > = of ( { } as any ) ;
@@ -58,6 +78,8 @@ export class RootComponent implements OnInit {
5878 notificationOptions : INotificationBoardOptions ;
5979 models : any ;
6080
81+ browserOsClasses = new BehaviorSubject < string [ ] > ( [ ] ) ;
82+
6183 /**
6284 * Whether or not to show a full screen loader
6385 */
@@ -73,11 +95,23 @@ export class RootComponent implements OnInit {
7395 private cssService : CSSVariableService ,
7496 private menuService : MenuService ,
7597 private windowService : HostWindowService ,
98+ @Inject ( NativeWindowService ) private _window : NativeWindowRef ,
7699 ) {
77100 this . notificationOptions = environment . notifications ;
78101 }
79102
80103 ngOnInit ( ) {
104+ const browserName = this . getBrowserName ( ) ;
105+ if ( browserName ) {
106+ const browserOsClasses = new Array < string > ( ) ;
107+ browserOsClasses . push ( `browser-${ browserName } ` ) ;
108+ const osName = this . getOSName ( ) ;
109+ if ( osName ) {
110+ browserOsClasses . push ( `browser-${ browserName } -${ osName } ` ) ;
111+ }
112+ this . browserOsClasses . next ( browserOsClasses ) ;
113+ }
114+
81115 this . isSidebarVisible$ = this . menuService . isMenuVisibleWithVisibleSections ( MenuID . ADMIN ) ;
82116
83117 this . expandedSidebarWidth$ = this . cssService . getVariable ( '--ds-admin-sidebar-total-width' ) . pipe (
@@ -108,4 +142,23 @@ export class RootComponent implements OnInit {
108142 mainContent . focus ( ) ;
109143 }
110144 }
145+
146+ getBrowserName ( ) : string {
147+ const userAgent = this . _window . nativeWindow . navigator . userAgent ;
148+ if ( / F i r e f o x / . test ( userAgent ) ) {
149+ return 'firefox' ;
150+ }
151+ if ( / S a f a r i / . test ( userAgent ) ) {
152+ return 'safari' ;
153+ }
154+ return undefined ;
155+ }
156+
157+ getOSName ( ) : string {
158+ const userAgent = this . _window . nativeWindow . navigator . userAgent ;
159+ if ( / W i n d o w s / . test ( userAgent ) ) {
160+ return 'windows' ;
161+ }
162+ return undefined ;
163+ }
111164}
0 commit comments