mirror of
https://github.com/humhub/humhub.git
synced 2025-01-17 14:18:27 +01:00
Enh: Added option to disable PWA/ServiceWorker Support (#4796)
This commit is contained in:
parent
a337048f0b
commit
9f1885dbe1
@ -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
|
||||
|
@ -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
|
||||
*/
|
||||
|
@ -41,7 +41,12 @@ class ManifestController extends Controller
|
||||
public function actionIndex()
|
||||
{
|
||||
$this->handleIcons();
|
||||
|
||||
/** @var Module $module */
|
||||
$module = Yii::$app->getModule('web');
|
||||
if ($module->enableServiceWorker !== false) {
|
||||
$this->handlePwa();
|
||||
}
|
||||
|
||||
return $this->asJson($this->manifest);
|
||||
}
|
||||
|
@ -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,14 +42,21 @@ 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(<<<JS
|
||||
if ('serviceWorker' in navigator) {
|
||||
navigator.serviceWorker.register('$serviceWorkUrl', { scope: '$rootPath' })
|
||||
@ -60,6 +68,7 @@ class LayoutHeader extends Widget
|
||||
}
|
||||
JS
|
||||
, View::POS_READY, 'serviceWorkerInit');
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user