From 4a293d8d12a2d828834056e0576280509702c9fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexandre=20D=2E=20D=C3=ADaz?= Date: Wed, 9 Dec 2020 21:05:58 +0100 Subject: [PATCH] [IMP] web_pwa_oca: Drop BeforeInstallPrompt --- web_pwa_oca/README.rst | 13 +++-- web_pwa_oca/__manifest__.py | 3 -- web_pwa_oca/readme/INSTALL.rst | 2 - web_pwa_oca/readme/ROADMAP.rst | 4 +- web_pwa_oca/readme/USAGE.rst | 7 ++- web_pwa_oca/static/description/index.html | 11 ++--- web_pwa_oca/static/src/js/pwa_install.js | 40 ---------------- web_pwa_oca/static/src/js/pwa_manager.js | 56 +++------------------- web_pwa_oca/static/src/xml/pwa_install.xml | 14 ------ web_pwa_oca/templates/assets.xml | 1 - 10 files changed, 23 insertions(+), 128 deletions(-) delete mode 100644 web_pwa_oca/static/src/js/pwa_install.js delete mode 100644 web_pwa_oca/static/src/xml/pwa_install.xml diff --git a/web_pwa_oca/README.rst b/web_pwa_oca/README.rst index 5f4e2acc8..0068ca1b3 100644 --- a/web_pwa_oca/README.rst +++ b/web_pwa_oca/README.rst @@ -62,8 +62,6 @@ And like all other installed apps, it's a top level app in the task switcher. In Chrome, a Progressive Web App can either be installed through the three-dot context menu. -This module also provides a "Install PWA" link in Odoo user menu. - In case you previously installed `web_pwa`, run the following steps with `odoo shell`, after having installed `openupgradelib`: @@ -91,8 +89,11 @@ Usage To use your PWA: -#. Open the Odoo web app using a supported browser (like Chrome/Chromium) -#. Install the PWA +#. Open the Odoo web app using a supported browser (See https://caniuse.com/?search=A2HS) +#. Open the browser options +#. Click on 'Add to Home screen' (or 'Install' in other browsers) + +** Maybe you need refresh the page to load the service worker after use 'add to home screen'. Known issues / Roadmap ====================== @@ -131,9 +132,7 @@ Known issues / Roadmap * Fix issue when trying to run in localhost with several databases. The browser doesn't send the cookie and web manifest returns 404. * Evaluate to support 'require' system. -* 'Install PWA' menu option disappears even if not installed. This is due to the - very nature of service workers, so they are running including when you close - the page tabs. +* Firefox can't detect 'standalone' mode. See https://bugzilla.mozilla.org/show_bug.cgi?id=1285858 Bug Tracker =========== diff --git a/web_pwa_oca/__manifest__.py b/web_pwa_oca/__manifest__.py index bb666043d..53e84ea4d 100644 --- a/web_pwa_oca/__manifest__.py +++ b/web_pwa_oca/__manifest__.py @@ -24,8 +24,5 @@ "templates/service_worker.xml", "views/res_config_settings_views.xml", ], - 'qweb': [ - 'static/src/xml/pwa_install.xml', - ], 'images': ['static/description/pwa.png'], } diff --git a/web_pwa_oca/readme/INSTALL.rst b/web_pwa_oca/readme/INSTALL.rst index b73ab9f0c..e82e32b91 100644 --- a/web_pwa_oca/readme/INSTALL.rst +++ b/web_pwa_oca/readme/INSTALL.rst @@ -10,8 +10,6 @@ And like all other installed apps, it's a top level app in the task switcher. In Chrome, a Progressive Web App can either be installed through the three-dot context menu. -This module also provides a "Install PWA" link in Odoo user menu. - In case you previously installed `web_pwa`, run the following steps with `odoo shell`, after having installed `openupgradelib`: diff --git a/web_pwa_oca/readme/ROADMAP.rst b/web_pwa_oca/readme/ROADMAP.rst index 5d292a4e7..d267ce12c 100644 --- a/web_pwa_oca/readme/ROADMAP.rst +++ b/web_pwa_oca/readme/ROADMAP.rst @@ -32,6 +32,4 @@ * Fix issue when trying to run in localhost with several databases. The browser doesn't send the cookie and web manifest returns 404. * Evaluate to support 'require' system. -* 'Install PWA' menu option disappears even if not installed. This is due to the - very nature of service workers, so they are running including when you close - the page tabs. +* Firefox can't detect 'standalone' mode. See https://bugzilla.mozilla.org/show_bug.cgi?id=1285858 diff --git a/web_pwa_oca/readme/USAGE.rst b/web_pwa_oca/readme/USAGE.rst index 3cf386adc..d7d83d698 100644 --- a/web_pwa_oca/readme/USAGE.rst +++ b/web_pwa_oca/readme/USAGE.rst @@ -1,4 +1,7 @@ To use your PWA: -#. Open the Odoo web app using a supported browser (like Chrome/Chromium) -#. Install the PWA +#. Open the Odoo web app using a supported browser (See https://caniuse.com/?search=A2HS) +#. Open the browser options +#. Click on 'Add to Home screen' (or 'Install' in other browsers) + +** Maybe you need refresh the page to load the service worker after use 'add to home screen'. diff --git a/web_pwa_oca/static/description/index.html b/web_pwa_oca/static/description/index.html index 24b4b17bf..238a6914e 100644 --- a/web_pwa_oca/static/description/index.html +++ b/web_pwa_oca/static/description/index.html @@ -405,7 +405,6 @@ that ‘Odoo Bootstrap’ is not supported so, you can’t use ‘require’ her It launches from the same place that other apps launch. It runs in an app without an address bar or other browser UI. And like all other installed apps, it’s a top level app in the task switcher.

In Chrome, a Progressive Web App can either be installed through the three-dot context menu.

-

This module also provides a “Install PWA” link in Odoo user menu.

In case you previously installed web_pwa, run the following steps with odoo shell, after having installed openupgradelib:

 >>> from openupgradelib import openupgrade
@@ -432,9 +431,11 @@ And like all other installed apps, it’s a top level app in the task switcher.<
 

Usage

To use your PWA:

    -
  1. Open the Odoo web app using a supported browser (like Chrome/Chromium)
  2. -
  3. Install the PWA
  4. +
  5. Open the Odoo web app using a supported browser (See https://caniuse.com/?search=A2HS)
  6. +
  7. Open the browser options
  8. +
  9. Click on ‘Add to Home screen’ (or ‘Install’ in other browsers)
+

** Maybe you need refresh the page to load the service worker after use ‘add to home screen’.

Known issues / Roadmap

@@ -478,9 +479,7 @@ doesn’t send the cookie and web manifest returns 404.

  • Evaluate to support ‘require’ system.

  • -
  • ‘Install PWA’ menu option disappears even if not installed. This is due to the -very nature of service workers, so they are running including when you close -the page tabs.

    +
  • Firefox can’t detect ‘standalone’ mode. See https://bugzilla.mozilla.org/show_bug.cgi?id=1285858

  • diff --git a/web_pwa_oca/static/src/js/pwa_install.js b/web_pwa_oca/static/src/js/pwa_install.js deleted file mode 100644 index b8076988d..000000000 --- a/web_pwa_oca/static/src/js/pwa_install.js +++ /dev/null @@ -1,40 +0,0 @@ -/* Copyright 2020 Lorenzo Battistini @ TAKOBI - Copyright 2020 Tecnativa - Alexandre D. Díaz - * License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). */ - -odoo.define('web_pwa_oca.systray.install', function (require) { - "use strict"; - - var UserMenu = require('web.UserMenu'); - var WebClientObj = require("web.web_client"); - - - UserMenu.include({ - - /** - * We can't control if the UserMenu is loaded berfore PWA manager... - * So check if need unhide the user menu options to install the PWA. - * - * @override - */ - start: function () { - var self = this; - return this._super.apply(this, arguments).then(function () { - if (WebClientObj.pwa_manager.canBeInstalled()) { - self.$el.find('#pwa_install_button')[0] - .removeAttribute('hidden'); - } - }); - }, - - /** - * Handle 'Install PWA' user menu option click - * - * @private - */ - _onMenuInstallpwa: function () { - WebClientObj.pwa_manager.install(); - }, - }); - -}); diff --git a/web_pwa_oca/static/src/js/pwa_manager.js b/web_pwa_oca/static/src/js/pwa_manager.js index 6ffdc1871..72b6df020 100644 --- a/web_pwa_oca/static/src/js/pwa_manager.js +++ b/web_pwa_oca/static/src/js/pwa_manager.js @@ -4,12 +4,13 @@ odoo.define("web_pwa_oca.PWAManager", function (require) { "use strict"; + var core = require("web.core"); var Widget = require("web.Widget"); + var _t = core._t; + var PWAManager = Widget.extend({ - _deferredInstallPrompt: null, - /** * @override */ @@ -17,12 +18,10 @@ odoo.define("web_pwa_oca.PWAManager", function (require) { this._super.apply(this, arguments); if (!('serviceWorker' in navigator)) { throw new Error( - "This browser is not compatible with service workers"); + _t("Service workers are not supported! Maybe you are not using HTTPS?")); } this._service_worker = navigator.serviceWorker; this.registerServiceWorker('/service-worker.js'); - window.addEventListener( - 'beforeinstallprompt', this._onBeforeInstallPrompt.bind(this)); }, /** @@ -33,53 +32,10 @@ odoo.define("web_pwa_oca.PWAManager", function (require) { return this._service_worker.register(sw_script) .then(this._onRegisterServiceWorker) .catch(function (error) { - console.log('[ServiceWorker] Registration failed: ', error); + console.log(_t('[ServiceWorker] Registration failed: '), error); }); }, - install: function () { - if (!this._deferredInstallPrompt) { - return; - } - var self = this; - var systray_menu = this.getParent().menu.systray_menu; - this._deferredInstallPrompt.prompt(); - // Log user response to prompt. - this._deferredInstallPrompt.userChoice - .then(function (choice) { - if (choice.outcome === 'accepted') { - // Hide the install button, it can't be called twice. - systray_menu.$el.find('#pwa_install_button') - .attr('hidden', true); - self._deferredInstallPrompt = null; - console.log('User accepted the A2HS prompt', choice); - } else { - console.log('User dismissed the A2HS prompt', choice); - } - }); - }, - - canBeInstalled: function () { - return !_.isNull(this._deferredInstallPrompt); - }, - - /** - * Handle PWA installation flow - * - * @private - * @param {BeforeInstallPromptEvent} evt - */ - _onBeforeInstallPrompt: function (evt) { - evt.preventDefault(); - this._deferredInstallPrompt = evt; - // UserMenu can be loaded after this module - var menu = this.getParent().menu; - if (menu && menu.systray_menu) { - menu.systray_menu.$el.find('#pwa_install_button')[0] - .removeAttribute('hidden'); - } - }, - /** * Need register some extra API? override this! * @@ -87,7 +43,7 @@ odoo.define("web_pwa_oca.PWAManager", function (require) { * @param {ServiceWorkerRegistration} registration */ _onRegisterServiceWorker: function (registration) { - console.log('[ServiceWorker] Registered:', registration); + console.log(_t('[ServiceWorker] Registered:'), registration); }, }); diff --git a/web_pwa_oca/static/src/xml/pwa_install.xml b/web_pwa_oca/static/src/xml/pwa_install.xml deleted file mode 100644 index ab6681f69..000000000 --- a/web_pwa_oca/static/src/xml/pwa_install.xml +++ /dev/null @@ -1,14 +0,0 @@ - - - - - - - - - - - - - - diff --git a/web_pwa_oca/templates/assets.xml b/web_pwa_oca/templates/assets.xml index e9c91c664..60c8cd419 100644 --- a/web_pwa_oca/templates/assets.xml +++ b/web_pwa_oca/templates/assets.xml @@ -18,7 +18,6 @@