Skip to content

Commit 6423e08

Browse files
committed
Decouple manifest from push notifications
Signed-off-by: Matt Friedman <maf675@gmail.com>
1 parent a156afb commit 6423e08

5 files changed

Lines changed: 38 additions & 11 deletions

File tree

event/listener.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public static function getSubscribedEvents()
8787
return [
8888
'core.ucp_display_module_before' => 'load_language',
8989
'core.acp_main_notice' => 'compatibility_notice',
90-
'core.page_header_after' => 'load_template_data',
90+
'core.page_header_after' => [['load_template_data'], ['pwa_manifest']],
9191
'core.acp_board_config_edit_add' => 'acp_pwa_options',
9292
'core.validate_config_variable' => 'validate_pwa_options',
9393
];
@@ -136,6 +136,19 @@ public function compatibility_notice()
136136
$this->template->assign_var('S_WPN_COMPATIBILITY_NOTICE', phpbb_version_compare(PHPBB_VERSION, '4.0.0-dev', '>='));
137137
}
138138

139+
/**
140+
* Assign template data for web manifest support
141+
*
142+
* @return void
143+
*/
144+
public function pwa_manifest()
145+
{
146+
$this->template->assign_vars([
147+
'U_MANIFEST_URL' => $this->controller_helper->route('phpbb_webpushnotifications_manifest_controller'),
148+
'U_TOUCH_ICON' => $this->config['pwa_icon_small'],
149+
]);
150+
}
151+
139152
/**
140153
* Progressive web app options for the ACP
141154
*

notification/method/webpush.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -385,8 +385,6 @@ public function get_ucp_template_data(helper $controller_helper, form_helper $fo
385385
'U_WEBPUSH_WORKER_URL' => $controller_helper->route('phpbb_webpushnotifications_ucp_push_worker_controller'),
386386
'SUBSCRIPTIONS' => $subscriptions,
387387
'WEBPUSH_FORM_TOKENS' => $form_helper->get_form_tokens(\phpbb\webpushnotifications\ucp\controller\webpush::FORM_TOKEN_UCP),
388-
'U_MANIFEST_URL' => $controller_helper->route('phpbb_webpushnotifications_manifest_controller'),
389-
'U_TOUCH_ICON' => $this->config['pwa_icon_small'],
390388
];
391389
}
392390

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
<meta name="apple-mobile-web-app-capable" content="yes">
2+
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
3+
<meta name="apple-mobile-web-app-title" content="{{ SITENAME }}">
4+
<link rel="manifest" href="{{ U_MANIFEST_URL }}">
5+
{% if U_TOUCH_ICON %}<link rel="apple-touch-icon" href="{{ T_ICONS_PATH ~ U_TOUCH_ICON }}">{% endif %}
6+
17
{% if NOTIFICATIONS_WEBPUSH_ENABLE %}
28
{% include '@phpbb_webpushnotifications/ucp_notifications_webpush.html' %}
39
{% endif %}

styles/all/template/ucp_notifications_webpush.html

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,3 @@
1-
<meta name="apple-mobile-web-app-capable" content="yes">
2-
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
3-
<meta name="apple-mobile-web-app-title" content="{{ SITENAME }}">
4-
<link rel="manifest" href="{{ U_MANIFEST_URL }}">
5-
{% if U_TOUCH_ICON %}<link rel="apple-touch-icon" href="{{ T_ICONS_PATH ~ U_TOUCH_ICON }}">{% endif %}
6-
71
<script>
82
phpbbWebpushOptions = {
93
serviceWorkerUrl: '{{ U_WEBPUSH_WORKER_URL }}',

tests/event/listener_test.php

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -243,8 +243,6 @@ public function test_get_ucp_template_data($user_id, $method_data, $subscription
243243
'U_WEBPUSH_WORKER_URL' => $this->controller_helper->route('phpbb_webpushnotifications_ucp_push_worker_controller'),
244244
'SUBSCRIPTIONS' => $subscriptions,
245245
'WEBPUSH_FORM_TOKENS' => $this->form_helper->get_form_tokens(\phpbb\webpushnotifications\ucp\controller\webpush::FORM_TOKEN_UCP),
246-
'U_MANIFEST_URL' => $this->controller_helper->route('phpbb_webpushnotifications_manifest_controller'),
247-
'U_TOUCH_ICON' => '',
248246
]
249247
);
250248

@@ -261,6 +259,24 @@ public function test_get_ucp_template_data($user_id, $method_data, $subscription
261259
$dispatcher->trigger_event('core.page_header_after');
262260
}
263261

262+
public function test_pwa_manifest()
263+
{
264+
$this->config['pwa_icon_small'] = 'icon-192x192.png';
265+
266+
$this->set_listener();
267+
268+
$this->template->expects(self::once())
269+
->method('assign_vars')
270+
->with([
271+
'U_MANIFEST_URL' => $this->controller_helper->route('phpbb_webpushnotifications_manifest_controller'),
272+
'U_TOUCH_ICON' => 'icon-192x192.png',
273+
]);
274+
275+
$dispatcher = new \phpbb\event\dispatcher();
276+
$dispatcher->addListener('core.acp_main_notice', [$this->listener, 'pwa_manifest']);
277+
$dispatcher->trigger_event('core.acp_main_notice');
278+
}
279+
264280
public function acp_pwa_options_data()
265281
{
266282
return [

0 commit comments

Comments
 (0)