diff --git a/.github/workflows/phpunit.yml b/.github/workflows/phpunit.yml index 67fe092..6147873 100644 --- a/.github/workflows/phpunit.yml +++ b/.github/workflows/phpunit.yml @@ -3,6 +3,8 @@ name: PHPUnit Plugin Tests on: [push, pull_request] jobs: - lint: + phpunit: name: Run PHPUnit test suites uses: ColdTrick/.github/.github/workflows/phpunit.yml@master + with: + elgg_major_version: 6 diff --git a/README.md b/README.md index f51669c..1457620 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Progressive Web App -![Elgg 5.0](https://img.shields.io/badge/Elgg-5.0-green.svg) +![Elgg 6.0](https://img.shields.io/badge/Elgg-6.0-green.svg) ![Lint Checks](https://github.com/ColdTrick/pwa/actions/workflows/lint.yml/badge.svg?event=push) [![Latest Stable Version](https://poser.pugx.org/coldtrick/pwa/v/stable.svg)](https://packagist.org/packages/coldtrick/pwa) [![License](https://poser.pugx.org/coldtrick/pwa/license.svg)](https://packagist.org/packages/coldtrick/pwa) diff --git a/classes/ColdTrick/PWA/Bootstrap.php b/classes/ColdTrick/PWA/Bootstrap.php index 4081b86..3cbdaa3 100644 --- a/classes/ColdTrick/PWA/Bootstrap.php +++ b/classes/ColdTrick/PWA/Bootstrap.php @@ -10,19 +10,12 @@ class Bootstrap extends DefaultPluginBootstrap { /** - * {@inheritDoc} + * {@inheritdoc} */ public function init() { elgg_register_external_file('js', 'upup', elgg_get_simplecache_url('pwa/upup/upup.js')); elgg_load_external_file('js', 'upup'); - elgg_register_simplecache_view('page/elements/offline.css'); - elgg_register_simplecache_view('pwa/upup/upup.sw.js'); - elgg_register_simplecache_view('resources/pwa/offline.html'); - - elgg_define_js('pwa/installable', [ - 'src' => elgg_get_simplecache_url('pwa/installable.js'), - ]); - elgg_require_js('pwa/installable'); + elgg_import_esm('pwa/installable'); } } diff --git a/composer.json b/composer.json index fd741e3..89b7e4f 100644 --- a/composer.json +++ b/composer.json @@ -13,7 +13,7 @@ "npm-asset/upup": "~1.1.0" }, "conflict": { - "elgg/elgg": "<5.0" + "elgg/elgg": "<6.0" }, "config": { "process-timeout": 0, diff --git a/composer.lock b/composer.lock index 5f45bc8..29e4bdf 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "84bfbca411ffece9a393de930a77cb65", + "content-hash": "832313651417aa491d473097706326b3", "packages": [ { "name": "npm-asset/upup", diff --git a/elgg-plugin.php b/elgg-plugin.php index fd7b953..6c27f5c 100644 --- a/elgg-plugin.php +++ b/elgg-plugin.php @@ -64,4 +64,10 @@ 'pwa/upup.config.js' => [], ], ], + 'view_options' => [ + 'page/elements/offline.css' => ['simplecache' => true], + 'pwa/installable.mjs' => ['simplecache' => true], + 'pwa/upup/upup.sw.js' => ['simplecache' => true], + 'resources/pwa/offline.html' => ['simplecache' => true], + ], ]; diff --git a/views/default/pwa/installable.js.php b/views/default/pwa/installable.js.php deleted file mode 100644 index c989a43..0000000 --- a/views/default/pwa/installable.js.php +++ /dev/null @@ -1,38 +0,0 @@ - -define(['jquery'], function($) { - - // Initialize deferredPrompt for use later to show browser install prompt. - let deferredPrompt; - - window.addEventListener('beforeinstallprompt', (e) => { - // Stash the event so it can be triggered later. - deferredPrompt = e; - - installable !== 'default') { ?> - // Prevent the mini-infobar from appearing on mobile - e.preventDefault(); - - installable === 'custom') { ?> - // Update UI notify the user they can install the PWA - showPWAInstallPromotion(); - - - }); - - window.addEventListener('appinstalled', () => { - // Handle app installed event - appInstalledEventHandler(); - - // Clear the deferredPrompt so it can be garbage collected - deferredPrompt = null; - }); - - -}); diff --git a/views/default/pwa/installable.mjs.php b/views/default/pwa/installable.mjs.php new file mode 100644 index 0000000..d65de01 --- /dev/null +++ b/views/default/pwa/installable.mjs.php @@ -0,0 +1,37 @@ + + +import 'jquery'; + +// Initialize deferredPrompt for use later to show browser install prompt. +let deferredPrompt; + +window.addEventListener('beforeinstallprompt', (e) => { + // Stash the event so it can be triggered later. + deferredPrompt = e; + + installable !== 'default') { ?> + // Prevent the mini-infobar from appearing on mobile + e.preventDefault(); + + installable === 'custom') { ?> + // Update UI notify the user they can install the PWA + showPWAInstallPromotion(); + + +}); + +window.addEventListener('appinstalled', () => { + // Handle app installed event + appInstalledEventHandler(); + + // Clear the deferredPrompt so it can be garbage collected + deferredPrompt = null; +}); + +