SVGHMI: fix HMI freeze at load when no screen saver is defined
authorEdouard Tisserant
Wed, 09 Nov 2022 12:14:35 +0100
changeset 3664 7e8db0b44e42
parent 3663 31aaec736e4d
child 3665 db7e4952b64f
child 3680 20f9f0c36ad6
child 3734 ed1ec3136c2b
SVGHMI: fix HMI freeze at load when no screen saver is defined
svghmi/svghmi.js
--- a/svghmi/svghmi.js	Tue Nov 08 11:03:45 2022 +0100
+++ b/svghmi/svghmi.js	Wed Nov 09 12:14:35 2022 +0100
@@ -428,18 +428,22 @@
     e.preventDefault();
 });
 
-var screensaver_timer = null;
-function reset_screensaver_timer() {
-    if(screensaver_timer){
-        window.clearTimeout(screensaver_timer);
-    }
-    screensaver_timer = window.setTimeout(() => {
-        switch_page("ScreenSaver");
-        screensaver_timer = null;
-    }, screensaver_delay*1000);
-}
-if(screensaver_delay)
+if(screensaver_delay){
+    var screensaver_timer = null;
+    function reset_screensaver_timer() {
+        if(screensaver_timer){
+            window.clearTimeout(screensaver_timer);
+        }
+        screensaver_timer = window.setTimeout(() => {
+            switch_page("ScreenSaver");
+            screensaver_timer = null;
+        }, screensaver_delay*1000);
+    }
     document.body.addEventListener('pointerdown', reset_screensaver_timer);
+    // initialize screensaver
+    reset_screensaver_timer();
+}
+
 
 function detach_detachables() {
 
@@ -601,9 +605,6 @@
 // show main page
 switch_page(default_page);
 
-// initialize screensaver
-reset_screensaver_timer();
-
 var reconnect_delay = 0;
 var periodic_reconnect_timer;