1
0
Эх сурвалжийг харах

Ticket #4480 - Add service worker.

AntonLV 3 жил өмнө
parent
commit
ff610915e7

+ 5 - 0
inc/classes/BxDolTemplate.php

@@ -1928,6 +1928,11 @@ class BxDolTemplate extends BxDolFactory implements iBxDolSingleton
 				$sKey = str_replace('css_media_', '', $sKey);
                 $sRet = $aData[$sKey];
                 break;
+            case 'service_worker':
+                if(getParam('sys_pwa_sw_enable') != 'on')
+                    break;
+                $sRet = "if(navigator && navigator.serviceWorker) navigator.serviceWorker.register('sw.js.php');";
+                break;
             case 'socket_engine':
                 $sRet = BxDolSockets::getInstance()->getJsCode();
                 break;

+ 3 - 2
install/sql/system.sql

@@ -772,8 +772,9 @@ INSERT INTO `sys_options_categories`(`type_id`, `name`, `caption`, `hidden`, `or
 SET @iCategoryId = LAST_INSERT_ID();
 
 INSERT INTO `sys_options`(`category_id`, `name`, `caption`, `value`, `type`, `extra`, `check`, `check_error`, `order`) VALUES
-(@iCategoryId, 'sys_pwa_sw_cache', '_adm_stg_cpt_option_sys_pwa_sw_cache', '', 'text', '', '', '', 1), 
-(@iCategoryId, 'sys_pwa_sw_offline', '_adm_stg_cpt_option_sys_pwa_sw_offline', '', 'digit', '', '', '', 2);
+(@iCategoryId, 'sys_pwa_sw_enable', '_adm_stg_cpt_option_sys_pwa_sw_enable', '', 'checkbox', '', '', '', 1),
+(@iCategoryId, 'sys_pwa_sw_cache', '_adm_stg_cpt_option_sys_pwa_sw_cache', '', 'text', '', '', '', 2), 
+(@iCategoryId, 'sys_pwa_sw_offline', '_adm_stg_cpt_option_sys_pwa_sw_offline', '', 'digit', '', '', '', 3);
 
 --
 -- Table structure for table `sys_options_mixes`

+ 1 - 0
modules/boonex/english/data/langs/system/en.xml

@@ -1744,6 +1744,7 @@
     <string name="_adm_stg_cpt_option_sys_pwa_manifest_theme_color"><![CDATA[Theme color]]></string>
 
     <string name="_adm_stg_cpt_category_pwa_sw"><![CDATA[Service Worker]]></string>
+    <string name="_adm_stg_cpt_option_sys_pwa_sw_enable"><![CDATA[Enable]]></string>
     <string name="_adm_stg_cpt_option_sys_pwa_sw_cache"><![CDATA[URLs to cache on install (each in new line)]]></string>
     <string name="_adm_stg_cpt_option_sys_pwa_sw_offline"><![CDATA[Offline page]]></string>
 

+ 1 - 0
modules/boonex/russian/data/langs/system/ru.xml

@@ -1722,6 +1722,7 @@
     <string name="_adm_stg_cpt_option_sys_pwa_manifest_theme_color"><![CDATA[Цвет темы]]></string>
 
     <string name="_adm_stg_cpt_category_pwa_sw"><![CDATA[Service Worker]]></string>
+    <string name="_adm_stg_cpt_option_sys_pwa_sw_enable"><![CDATA[Включить]]></string>
     <string name="_adm_stg_cpt_option_sys_pwa_sw_cache"><![CDATA[URL-адреса для кэширования при установке (каждый в новой строке)]]></string>
     <string name="_adm_stg_cpt_option_sys_pwa_sw_offline"><![CDATA[Офлайн-страница]]></string>
 

+ 1 - 3
template/_header_js.html

@@ -7,9 +7,7 @@
         bx_redirect_for_external_links($('.bx-def-vanilla-html'));
     });
 
-    if (navigator && navigator.serviceWorker) {
-        navigator.serviceWorker.register('sw.js.php');
-    }
+    __service_worker__
 
     (function(w) {
         var dpr = (w.devicePixelRatio === undefined ? 1 : Math.round(w.devicePixelRatio));