diff --git a/CHANGELOG_DEV.md b/CHANGELOG_DEV.md index 2e970617a0..ef70450911 100644 --- a/CHANGELOG_DEV.md +++ b/CHANGELOG_DEV.md @@ -34,3 +34,4 @@ - Enh #4416: Added replay to sub comments - Enh #4571: humhub/libs/Html::containerLink() now adds a "data-guid" attribute - Enh #4787: Always enable Space Membership Web Notifications +- Enh #4796: Added option to disable PWA/ServiceWorker support diff --git a/protected/humhub/modules/web/Module.php b/protected/humhub/modules/web/Module.php index ba522f5151..5db7da2157 100644 --- a/protected/humhub/modules/web/Module.php +++ b/protected/humhub/modules/web/Module.php @@ -21,7 +21,6 @@ use humhub\modules\web\pwa\controllers\ServiceWorkerController; */ class Module extends \humhub\components\Module { - /** * @inheritdoc */ @@ -32,6 +31,12 @@ class Module extends \humhub\components\Module */ public $security; + /** + * @since 1.8 + * @var boolean Disable Service Worker and PWA Support + */ + public $enableServiceWorker = true; + /** * @inheritdoc */ diff --git a/protected/humhub/modules/web/pwa/controllers/ManifestController.php b/protected/humhub/modules/web/pwa/controllers/ManifestController.php index f75bbde6d7..2d7076b7af 100644 --- a/protected/humhub/modules/web/pwa/controllers/ManifestController.php +++ b/protected/humhub/modules/web/pwa/controllers/ManifestController.php @@ -41,7 +41,12 @@ class ManifestController extends Controller public function actionIndex() { $this->handleIcons(); - $this->handlePwa(); + + /** @var Module $module */ + $module = Yii::$app->getModule('web'); + if ($module->enableServiceWorker !== false) { + $this->handlePwa(); + } return $this->asJson($this->manifest); } diff --git a/protected/humhub/modules/web/pwa/widgets/LayoutHeader.php b/protected/humhub/modules/web/pwa/widgets/LayoutHeader.php index bf0814154a..4810cdd1e6 100644 --- a/protected/humhub/modules/web/pwa/widgets/LayoutHeader.php +++ b/protected/humhub/modules/web/pwa/widgets/LayoutHeader.php @@ -12,7 +12,7 @@ use Yii; use yii\base\WidgetEvent; use yii\helpers\Url; use humhub\components\Widget; -use humhub\modules\ui\Module; +use humhub\modules\web\Module; use humhub\modules\ui\view\components\View; /** @@ -30,6 +30,7 @@ class LayoutHeader extends Widget */ public static function registerHeadTags(View $view) { + $view->registerMetaTag(['name' => 'theme-color', 'content' => Yii::$app->view->theme->variable('primary')]); $view->registerMetaTag(['name' => 'application-name', 'content' => Yii::$app->name]); @@ -41,25 +42,33 @@ class LayoutHeader extends Widget $view->registerLinkTag(['rel' => 'manifest', 'href' => Url::to(['/web/pwa-manifest/index'])]); + /** @var Module $module */ + $module = Yii::$app->getModule('web'); + if ($module->enableServiceWorker !== false) { + static::registerServiceWorker($view); + } + } + private static function registerServiceWorker(View $view) + { $cacheId = Yii::$app->cache->getOrSet('service-worker-cache-id', function () { return time(); }); $serviceWorkUrl = Url::to(['/web/pwa-service-worker/index', 'v' => $cacheId]); - - $rootPath = Yii::getAlias('@web') . '/'; + $view->registerJs(<<