@@ -5,35 +5,26 @@ import SelectBox from './selectbox'
55import { Theme , ALL_THEMES } from './themes.js'
66import { DESATURATION_FILTER } from './filters.js'
77import { JSON_delta } from './vendor/json_delta.js'
8+ import Config from './config.js'
89
910const PIXI = require ( 'pixi.js' )
1011
1112const addWheelListener = require ( './vendor/addWheelListener' )
1213
13- const TRUTHY_VALUES = new Set ( [ '1' , 'true' ] )
14-
1514
1615export default class App {
1716
1817 constructor ( ) {
1918 const params = this . parseLocationHash ( )
20- this . dashboardMode = TRUTHY_VALUES . has ( params . get ( 'dashboard' ) )
21- this . reloadIntervalSeconds = parseInt ( params . get ( 'reload' ) ) || 0
19+ this . config = Config . fromParams ( params )
2220 this . filterString = params . get ( 'q' ) || ''
2321 this . selectedClusters = new Set ( ( params . get ( 'clusters' ) || '' ) . split ( ',' ) . filter ( x => x ) )
24- this . initialScale = parseFloat ( params . get ( 'scale' ) ) || 1.0
2522 this . seenPods = new Set ( )
2623 this . sorterFn = ''
2724 this . theme = Theme . get ( localStorage . getItem ( 'theme' ) )
2825 this . eventSource = null
2926 this . connectTime = null
3027 this . keepAliveTimer = null
31- // make sure we got activity at least every 20 seconds
32- this . keepAliveSeconds = 20
33- // always reconnect after 5 minutes
34- this . maxConnectionLifetimeSeconds = 300
35- // consider cluster data older than 1 minute outdated
36- this . maxDataAgeSeconds = 60
3728 this . clusters = new Map ( )
3829 this . clusterStatuses = new Map ( )
3930 this . viewContainerTargetPosition = new PIXI . Point ( )
@@ -104,8 +95,9 @@ export default class App {
10495 initialize ( ) {
10596 App . current = this
10697
107- //Create the renderer
108- const renderer = PIXI . autoDetectRenderer ( 256 , 256 , { resolution : 2 } )
98+ // create the renderer
99+ const noWebGL = this . config . renderer === 'canvas'
100+ const renderer = PIXI . autoDetectRenderer ( 256 , 256 , { resolution : 2 } , noWebGL )
109101 renderer . view . style . display = 'block'
110102 renderer . autoResize = true
111103 renderer . resize ( window . innerWidth , window . innerHeight )
@@ -124,8 +116,8 @@ export default class App {
124116 this . registerEventListeners ( )
125117 setInterval ( this . pruneUnavailableClusters . bind ( this ) , 5 * 1000 )
126118
127- if ( this . reloadIntervalSeconds ) {
128- setTimeout ( function ( ) { location . reload ( false ) } , this . reloadIntervalSeconds * 1000 )
119+ if ( this . config . reloadIntervalSeconds ) {
120+ setTimeout ( function ( ) { location . reload ( false ) } , this . config . reloadIntervalSeconds * 1000 )
129121 }
130122 }
131123
@@ -152,7 +144,7 @@ export default class App {
152144 }
153145 else if ( event . key == 'Home' ) {
154146 this . viewContainerTargetPosition . x = 20
155- this . viewContainerTargetPosition . y = this . dashboardMode ? 20 : 40
147+ this . viewContainerTargetPosition . y = this . config . dashboardMode ? 20 : 40
156148 }
157149 else if ( event . key && event . key . length == 1 && ! event . ctrlKey && ! event . metaKey ) {
158150 this . filterString += event . key
@@ -334,14 +326,14 @@ export default class App {
334326 this . theme . apply ( this . stage )
335327
336328 const viewContainer = new PIXI . Container ( )
337- viewContainer . scale . set ( this . initialScale )
329+ viewContainer . scale . set ( this . config . initialScale )
338330 viewContainer . x = 20
339- viewContainer . y = this . dashboardMode ? 20 : 40
331+ viewContainer . y = this . config . dashboardMode ? 20 : 40
340332 this . viewContainerTargetPosition . x = viewContainer . x
341333 this . viewContainerTargetPosition . y = viewContainer . y
342334 this . stage . addChild ( viewContainer )
343335
344- if ( ! this . dashboardMode ) {
336+ if ( ! this . config . dashboardMode ) {
345337 this . drawMenuBar ( )
346338 }
347339
@@ -550,10 +542,10 @@ export default class App {
550542 if ( this . keepAliveTimer != null ) {
551543 clearTimeout ( this . keepAliveTimer )
552544 }
553- this . keepAliveTimer = setTimeout ( this . connect . bind ( this ) , this . keepAliveSeconds * 1000 )
545+ this . keepAliveTimer = setTimeout ( this . connect . bind ( this ) , this . config . keepAliveSeconds * 1000 )
554546 if ( this . connectTime != null ) {
555547 const now = Date . now ( )
556- if ( now - this . connectTime > this . maxConnectionLifetimeSeconds * 1000 ) {
548+ if ( now - this . connectTime > this . config . maxConnectionLifetimeSeconds * 1000 ) {
557549 // maximum connection lifetime exceeded => reconnect
558550 this . connect ( )
559551 }
@@ -565,7 +557,7 @@ export default class App {
565557 const nowSeconds = Date . now ( ) / 1000
566558 for ( const [ clusterId , statusObj ] of this . clusterStatuses . entries ( ) ) {
567559 const lastQueryTime = statusObj . last_query_time || 0
568- if ( lastQueryTime < nowSeconds - this . maxDataAgeSeconds ) {
560+ if ( lastQueryTime < nowSeconds - this . config . maxDataAgeSeconds ) {
569561 this . clusters . delete ( clusterId )
570562 updateNeeded = true
571563 } else if ( lastQueryTime < nowSeconds - 20 ) {
@@ -622,7 +614,7 @@ export default class App {
622614 const cluster = JSON . parse ( event . data )
623615 const status = that . clusterStatuses . get ( cluster . id )
624616 const nowSeconds = Date . now ( ) / 1000
625- if ( status && status . last_query_time < nowSeconds - that . maxDataAgeSeconds ) {
617+ if ( status && status . last_query_time < nowSeconds - that . config . maxDataAgeSeconds ) {
626618 // outdated data => ignore
627619 } else {
628620 that . clusters . set ( cluster . id , cluster )
0 commit comments