From 5a69d98ff4caad1d6720d4a152c57153f83dcf02 Mon Sep 17 00:00:00 2001
From: Curt Tudor <curt@rentallect.com>
Date: Thu, 4 Aug 2022 19:22:18 -0600
Subject: [PATCH] feat: add SW reload event mechanism (#86)

---
 src/runtime.js | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/src/runtime.js b/src/runtime.js
index be5783b..4e976b3 100644
--- a/src/runtime.js
+++ b/src/runtime.js
@@ -434,10 +434,22 @@ if (isUndefined(window.zitiBrowzerRuntime)) {
 
           setTimeout(function() {
             zitiBrowzerRuntime.logger.debug(`################ doing root-page page reload now ################`);
-            window.location.replace('https://' + this.zitiConfig.httpAgent.self.host + '/');
+            window.location.replace('https://' + zitiBrowzerRuntime.zitiConfig.httpAgent.self.host + '/');
           }, 100);
         }
 
+        else if (event.data.type === 'RELOAD') {
+
+          zitiBrowzerRuntime.logger.info(`A ${event.data.type} msg was received!`);
+
+          zitiBrowzerRuntime.toastWarning(`ServiceWorker initiated a reload - stand by`);
+
+          setTimeout(function() {
+            zitiBrowzerRuntime.logger.debug(`################ doing root-page page reload now ################`);
+            window.location.replace('https://' + zitiBrowzerRuntime.zitiConfig.httpAgent.self.host + '/');
+          }, 2500);
+        }
+
         else if (event.data.type === 'ZITI_CONFIG_NEEDED') {
 
           zitiBrowzerRuntime.wb.messageSW({