@@ -36,7 +36,18 @@ function runWhenIdle(task, timeoutMs = 2000, fallbackDelayMs = 600) {
3636function detectHaApp ( ) {
3737 try {
3838 const ua = window . navigator ?. userAgent || '' ;
39- return / H o m e A s s i s t a n t / i. test ( ua ) ;
39+ return / H o m e A s s i s t a n t | H o m e A s s i s t a n t / i. test ( ua ) ;
40+ } catch ( e ) {
41+ return false ;
42+ }
43+ }
44+
45+ function detectMobile ( ) {
46+ try {
47+ const ua = window . navigator ?. userAgent || '' ;
48+ const mobileUA = / A n d r o i d | i P h o n e | i P a d | i P o d | M o b i l e / i. test ( ua ) ;
49+ const smallViewport = window . innerWidth <= 768 || window . matchMedia ?. ( '(max-width: 768px)' ) ?. matches ;
50+ return mobileUA || ! ! smallViewport ;
4051 } catch ( e ) {
4152 return false ;
4253 }
@@ -46,6 +57,9 @@ window.OIG_RUNTIME = window.OIG_RUNTIME || {};
4657if ( window . OIG_RUNTIME . isHaApp === undefined ) {
4758 window . OIG_RUNTIME . isHaApp = detectHaApp ( ) ;
4859}
60+ if ( window . OIG_RUNTIME . isMobile === undefined ) {
61+ window . OIG_RUNTIME . isMobile = detectMobile ( ) ;
62+ }
4963if ( window . OIG_RUNTIME . initialLoadComplete === undefined ) {
5064 window . OIG_RUNTIME . initialLoadComplete = false ;
5165}
@@ -321,6 +335,7 @@ var closeGridChargingDialog = window.DashboardGridCharging?.closeGridChargingDia
321335// === INITIALIZATION ===
322336function init ( ) {
323337 console . log ( '[Dashboard] Initializing...' ) ;
338+ const isConstrainedRuntime = ! ! ( window . OIG_RUNTIME ?. isHaApp || window . OIG_RUNTIME ?. isMobile ) ;
324339
325340 // Detekovat a aplikovat téma z Home Assistantu
326341 detectAndApplyTheme ( ) ;
@@ -369,16 +384,16 @@ function init() {
369384 const startHeavyLoad = ( ) => {
370385 forceFullRefresh ( ) ;
371386 } ;
372- if ( window . OIG_RUNTIME ?. isHaApp ) {
373- setTimeout ( ( ) => runWhenIdle ( startHeavyLoad , 2500 , 900 ) , 200 ) ;
387+ if ( isConstrainedRuntime ) {
388+ setTimeout ( ( ) => runWhenIdle ( startHeavyLoad , 3500 , 1200 ) , 200 ) ;
374389 } else {
375390 startHeavyLoad ( ) ;
376391 }
377392
378393 updateTime ( ) ;
379394
380395 // NOVÉ: Load extended timeline for Today Plan Tile
381- runWhenIdle ( buildExtendedTimeline , 2500 , 900 ) ;
396+ runWhenIdle ( buildExtendedTimeline , isConstrainedRuntime ? 3500 : 2500 , isConstrainedRuntime ? 1200 : 900 ) ;
382397
383398 // OPRAVA: Načíst pricing data pokud je pricing tab aktivní při načtení stránky
384399 const pricingTab = document . getElementById ( 'pricing-tab' ) ;
@@ -566,10 +581,18 @@ function init() {
566581 // Problém: Po restartu HA se někdy načítají CSS/HTML v jiném pořadí
567582 // Řešení: Opakované překreslení po různých intervalech
568583 // OPRAVA BUG #3: Inicializovat cache před prvním kreslením
569- setTimeout ( ( ) => { getNodeCenters ( ) ; drawConnections ( ) ; } , 100 ) ; // První pokus po 100ms
570- setTimeout ( ( ) => { getNodeCenters ( ) ; drawConnections ( ) ; } , 500 ) ; // Druhý pokus po 500ms
571- setTimeout ( ( ) => { getNodeCenters ( ) ; drawConnections ( ) ; } , 1000 ) ; // Třetí pokus po 1s
572- setTimeout ( ( ) => { getNodeCenters ( ) ; drawConnections ( ) ; } , 2000 ) ; // Finální po 2s
584+ const scheduleConnectionsDraw = ( delay ) => {
585+ setTimeout ( ( ) => { getNodeCenters ( ) ; drawConnections ( ) ; } , delay ) ;
586+ } ;
587+ if ( isConstrainedRuntime ) {
588+ scheduleConnectionsDraw ( 200 ) ; // První pokus po 200ms (mobile/HA app)
589+ scheduleConnectionsDraw ( 1200 ) ; // Finální po 1.2s
590+ } else {
591+ scheduleConnectionsDraw ( 100 ) ; // První pokus po 100ms
592+ scheduleConnectionsDraw ( 500 ) ; // Druhý pokus po 500ms
593+ scheduleConnectionsDraw ( 1000 ) ; // Třetí pokus po 1s
594+ scheduleConnectionsDraw ( 2000 ) ; // Finální po 2s
595+ }
573596
574597 // Mobile: Toggle node details on click (collapsed by default)
575598 if ( window . innerWidth <= 768 ) {
0 commit comments