@@ -14,6 +14,7 @@ import { getVersion } from 'react-native-device-info'
1414import RNFS from 'react-native-fs'
1515
1616import { initDeviceSettings } from './actions/DeviceSettingsActions'
17+ import { showError } from './components/services/AirshipInstance'
1718import { changeTheme , getTheme } from './components/services/ThemeContext'
1819import { ENV } from './env'
1920import type { NumberMap } from './types/types'
@@ -101,7 +102,7 @@ const asServerDetails = asObject({
101102const ENABLE_PERF_LOGGING = false
102103const PERF_LOGGING_ONLY = false
103104
104- const perfTimers : NumberMap = { }
105+ const perfTimers = new Map < string , number > ( )
105106const perfCounters : NumberMap = { }
106107const perfTotals : NumberMap = { }
107108
@@ -165,9 +166,9 @@ if (ENABLE_PERF_LOGGING) {
165166 perfTotals [ label ] = 0
166167 perfCounters [ label ] = 0
167168 }
168- if ( typeof perfTimers [ label ] === 'undefined' ) {
169+ if ( typeof perfTimers . get ( label ) === 'undefined' ) {
169170 // @ts -expect-error
170- perfTimers [ label ] = global . nativePerformanceNow ( )
171+ perfTimers . set ( label , global . nativePerformanceNow ( ) )
171172 } else {
172173 clog ( `${ d } : PTIMER Error: PTimer already started: ${ label } ` )
173174 }
@@ -176,15 +177,16 @@ if (ENABLE_PERF_LOGGING) {
176177 // @ts -expect-error
177178 global . pend = function ( label : string ) {
178179 const d = makeDate ( )
179- if ( typeof perfTimers [ label ] === 'number' ) {
180+ const timer = perfTimers . get ( label )
181+ if ( typeof timer === 'number' ) {
180182 // @ts -expect-error
181- const elapsed = global . nativePerformanceNow ( ) - perfTimers [ label ]
183+ const elapsed = global . nativePerformanceNow ( ) - timer
182184 perfTotals [ label ] += elapsed
183185 perfCounters [ label ] ++
184186 clog (
185187 `${ d } : PTIMER ${ label } :${ elapsed } ms total:${ perfTotals [ label ] } ms count:${ perfCounters [ label ] } `
186188 )
187- delete perfTimers [ label ]
189+ perfTimers . delete ( label )
188190 } else {
189191 clog ( `${ d } : PTIMER Error: PTimer not started: ${ label } ` )
190192 }
@@ -250,7 +252,7 @@ if (ENV.DEBUG_THEME) {
250252 method : 'GET'
251253 }
252254 let themeJson = ''
253- setInterval ( async ( ) => {
255+ const updateTheme = async ( ) : Promise < void > => {
254256 try {
255257 const response = await realFetch ( url , getOptions )
256258 const overrideTheme = await response . json ( )
@@ -264,6 +266,11 @@ if (ENV.DEBUG_THEME) {
264266 } catch ( e : any ) {
265267 console . log ( `Failed get theme` , e . message )
266268 }
269+ }
270+ setInterval ( ( ) => {
271+ updateTheme ( ) . catch ( ( error : unknown ) => {
272+ showError ( error )
273+ } )
267274 } , 3000 )
268275 } catch ( e : any ) {
269276 console . log ( `Failed to access theme server` )
0 commit comments