mirror of
https://github.com/phpbb/phpbb.git
synced 2025-07-26 03:48:53 +00:00
[ticket/17321] Provide correct push worker update
PHPBB3-17321
This commit is contained in:
parent
c6fd14352e
commit
ad715dac08
3 changed files with 52 additions and 1 deletions
29
phpBB/assets/javascript/update_worker.js
Normal file
29
phpBB/assets/javascript/update_worker.js
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
function webpushWorkerUpdate() {
|
||||||
|
if ('serviceWorker' in navigator) {
|
||||||
|
navigator.serviceWorker.getRegistration(serviceWorkerUrl)
|
||||||
|
.then((registration) => {
|
||||||
|
registration.update();
|
||||||
|
})
|
||||||
|
.catch(error => {
|
||||||
|
// Service worker could not be updated
|
||||||
|
console.info(error);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Do not redeclare function if exist
|
||||||
|
if (typeof domReady === 'undefined') {
|
||||||
|
window.domReady = function(callBack) {
|
||||||
|
if (document.readyState === 'loading') {
|
||||||
|
document.addEventListener('DOMContentLoaded', callBack);
|
||||||
|
} else {
|
||||||
|
callBack();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
domReady(() => {
|
||||||
|
/* global serviceWorkerUrl */
|
||||||
|
webpushWorkerUpdate();
|
||||||
|
});
|
|
@ -3855,7 +3855,8 @@ function page_header($page_title = '', $display_online_list = false, $item_id =
|
||||||
|
|
||||||
// Output the notifications
|
// Output the notifications
|
||||||
$notifications = false;
|
$notifications = false;
|
||||||
if ($config['load_notifications'] && $config['allow_board_notifications'] && $user->data['user_id'] != ANONYMOUS && $user->data['user_type'] != USER_IGNORE)
|
$notifications_enabled = $config['load_notifications'] && $config['allow_board_notifications'] && $user->data['user_id'] != ANONYMOUS && $user->data['user_type'] != USER_IGNORE;
|
||||||
|
if ($notifications_enabled)
|
||||||
{
|
{
|
||||||
/* @var $phpbb_notifications \phpbb\notification\manager */
|
/* @var $phpbb_notifications \phpbb\notification\manager */
|
||||||
$phpbb_notifications = $phpbb_container->get('notification_manager');
|
$phpbb_notifications = $phpbb_container->get('notification_manager');
|
||||||
|
@ -4032,6 +4033,20 @@ function page_header($page_title = '', $display_online_list = false, $item_id =
|
||||||
'SITE_LOGO_IMG' => $user->img('site_logo'),
|
'SITE_LOGO_IMG' => $user->img('site_logo'),
|
||||||
));
|
));
|
||||||
|
|
||||||
|
$webpush_available = $notifications_enabled && $phpbb_notifications->get_method_class('notification.method.webpush')->is_available();
|
||||||
|
if ($webpush_available)
|
||||||
|
{
|
||||||
|
if (!$this->template->retrieve_var('U_WEBPUSH_WORKER_URL'))
|
||||||
|
{
|
||||||
|
$this->template->assign_var('U_WEBPUSH_WORKER_URL', $controller_helper->route('phpbb_ucp_push_worker_controller'));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$this->template->retrieve_var('NOTIFICATIONS_WEBPUSH_ENABLE'))
|
||||||
|
{
|
||||||
|
$this->template->assign_var('NOTIFICATIONS_WEBPUSH_ENABLE', true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$http_headers = array();
|
$http_headers = array();
|
||||||
|
|
||||||
if ($send_headers)
|
if ($send_headers)
|
||||||
|
|
|
@ -117,6 +117,13 @@
|
||||||
</script>
|
</script>
|
||||||
<!-- ENDIF -->
|
<!-- ENDIF -->
|
||||||
|
|
||||||
|
{% if NOTIFICATIONS_WEBPUSH_ENABLE %}
|
||||||
|
<script>
|
||||||
|
const serviceWorkerUrl = '{{ U_WEBPUSH_WORKER_URL }}';
|
||||||
|
</script>
|
||||||
|
{% INCLUDEJS(T_ASSETS_PATH ~ '/javascript/update_worker.js') %}
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
<!-- EVENT overall_footer_after -->
|
<!-- EVENT overall_footer_after -->
|
||||||
|
|
||||||
<!-- IF S_PLUPLOAD --><!-- INCLUDE plupload.html --><!-- ENDIF -->
|
<!-- IF S_PLUPLOAD --><!-- INCLUDE plupload.html --><!-- ENDIF -->
|
||||||
|
|
Loading…
Add table
Reference in a new issue