mirror of https://github.com/OCA/web.git
[IMP] web_pwa_oca: Drop BeforeInstallPrompt
parent
102c81e48d
commit
4a293d8d12
|
@ -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.
|
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`:
|
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:
|
To use your PWA:
|
||||||
|
|
||||||
#. Open the Odoo web app using a supported browser (like Chrome/Chromium)
|
#. Open the Odoo web app using a supported browser (See https://caniuse.com/?search=A2HS)
|
||||||
#. Install the PWA
|
#. 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
|
Known issues / Roadmap
|
||||||
======================
|
======================
|
||||||
|
@ -131,9 +132,7 @@ Known issues / Roadmap
|
||||||
* Fix issue when trying to run in localhost with several databases. The browser
|
* Fix issue when trying to run in localhost with several databases. The browser
|
||||||
doesn't send the cookie and web manifest returns 404.
|
doesn't send the cookie and web manifest returns 404.
|
||||||
* Evaluate to support 'require' system.
|
* Evaluate to support 'require' system.
|
||||||
* 'Install PWA' menu option disappears even if not installed. This is due to the
|
* Firefox can't detect 'standalone' mode. See https://bugzilla.mozilla.org/show_bug.cgi?id=1285858
|
||||||
very nature of service workers, so they are running including when you close
|
|
||||||
the page tabs.
|
|
||||||
|
|
||||||
Bug Tracker
|
Bug Tracker
|
||||||
===========
|
===========
|
||||||
|
|
|
@ -24,8 +24,5 @@
|
||||||
"templates/service_worker.xml",
|
"templates/service_worker.xml",
|
||||||
"views/res_config_settings_views.xml",
|
"views/res_config_settings_views.xml",
|
||||||
],
|
],
|
||||||
'qweb': [
|
|
||||||
'static/src/xml/pwa_install.xml',
|
|
||||||
],
|
|
||||||
'images': ['static/description/pwa.png'],
|
'images': ['static/description/pwa.png'],
|
||||||
}
|
}
|
||||||
|
|
|
@ -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.
|
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`:
|
In case you previously installed `web_pwa`, run the following steps with `odoo shell`, after having installed `openupgradelib`:
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -32,6 +32,4 @@
|
||||||
* Fix issue when trying to run in localhost with several databases. The browser
|
* Fix issue when trying to run in localhost with several databases. The browser
|
||||||
doesn't send the cookie and web manifest returns 404.
|
doesn't send the cookie and web manifest returns 404.
|
||||||
* Evaluate to support 'require' system.
|
* Evaluate to support 'require' system.
|
||||||
* 'Install PWA' menu option disappears even if not installed. This is due to the
|
* Firefox can't detect 'standalone' mode. See https://bugzilla.mozilla.org/show_bug.cgi?id=1285858
|
||||||
very nature of service workers, so they are running including when you close
|
|
||||||
the page tabs.
|
|
||||||
|
|
|
@ -1,4 +1,7 @@
|
||||||
To use your PWA:
|
To use your PWA:
|
||||||
|
|
||||||
#. Open the Odoo web app using a supported browser (like Chrome/Chromium)
|
#. Open the Odoo web app using a supported browser (See https://caniuse.com/?search=A2HS)
|
||||||
#. Install the PWA
|
#. 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'.
|
||||||
|
|
|
@ -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.
|
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.</p>
|
And like all other installed apps, it’s a top level app in the task switcher.</p>
|
||||||
<p>In Chrome, a Progressive Web App can either be installed through the three-dot context menu.</p>
|
<p>In Chrome, a Progressive Web App can either be installed through the three-dot context menu.</p>
|
||||||
<p>This module also provides a “Install PWA” link in Odoo user menu.</p>
|
|
||||||
<p>In case you previously installed <cite>web_pwa</cite>, run the following steps with <cite>odoo shell</cite>, after having installed <cite>openupgradelib</cite>:</p>
|
<p>In case you previously installed <cite>web_pwa</cite>, run the following steps with <cite>odoo shell</cite>, after having installed <cite>openupgradelib</cite>:</p>
|
||||||
<pre class="doctest-block">
|
<pre class="doctest-block">
|
||||||
>>> from openupgradelib import openupgrade
|
>>> from openupgradelib import openupgrade
|
||||||
|
@ -432,9 +431,11 @@ And like all other installed apps, it’s a top level app in the task switcher.<
|
||||||
<h1><a class="toc-backref" href="#id3">Usage</a></h1>
|
<h1><a class="toc-backref" href="#id3">Usage</a></h1>
|
||||||
<p>To use your PWA:</p>
|
<p>To use your PWA:</p>
|
||||||
<ol class="arabic simple">
|
<ol class="arabic simple">
|
||||||
<li>Open the Odoo web app using a supported browser (like Chrome/Chromium)</li>
|
<li>Open the Odoo web app using a supported browser (See <a class="reference external" href="https://caniuse.com/?search=A2HS">https://caniuse.com/?search=A2HS</a>)</li>
|
||||||
<li>Install the PWA</li>
|
<li>Open the browser options</li>
|
||||||
|
<li>Click on ‘Add to Home screen’ (or ‘Install’ in other browsers)</li>
|
||||||
</ol>
|
</ol>
|
||||||
|
<p>** Maybe you need refresh the page to load the service worker after use ‘add to home screen’.</p>
|
||||||
</div>
|
</div>
|
||||||
<div class="section" id="known-issues-roadmap">
|
<div class="section" id="known-issues-roadmap">
|
||||||
<h1><a class="toc-backref" href="#id4">Known issues / Roadmap</a></h1>
|
<h1><a class="toc-backref" href="#id4">Known issues / Roadmap</a></h1>
|
||||||
|
@ -478,9 +479,7 @@ doesn’t send the cookie and web manifest returns 404.</p>
|
||||||
</li>
|
</li>
|
||||||
<li><p class="first">Evaluate to support ‘require’ system.</p>
|
<li><p class="first">Evaluate to support ‘require’ system.</p>
|
||||||
</li>
|
</li>
|
||||||
<li><p class="first">‘Install PWA’ menu option disappears even if not installed. This is due to the
|
<li><p class="first">Firefox can’t detect ‘standalone’ mode. See <a class="reference external" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1285858">https://bugzilla.mozilla.org/show_bug.cgi?id=1285858</a></p>
|
||||||
very nature of service workers, so they are running including when you close
|
|
||||||
the page tabs.</p>
|
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -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();
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
});
|
|
|
@ -4,12 +4,13 @@
|
||||||
odoo.define("web_pwa_oca.PWAManager", function (require) {
|
odoo.define("web_pwa_oca.PWAManager", function (require) {
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
|
var core = require("web.core");
|
||||||
var Widget = require("web.Widget");
|
var Widget = require("web.Widget");
|
||||||
|
|
||||||
|
var _t = core._t;
|
||||||
|
|
||||||
|
|
||||||
var PWAManager = Widget.extend({
|
var PWAManager = Widget.extend({
|
||||||
_deferredInstallPrompt: null,
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @override
|
* @override
|
||||||
*/
|
*/
|
||||||
|
@ -17,12 +18,10 @@ odoo.define("web_pwa_oca.PWAManager", function (require) {
|
||||||
this._super.apply(this, arguments);
|
this._super.apply(this, arguments);
|
||||||
if (!('serviceWorker' in navigator)) {
|
if (!('serviceWorker' in navigator)) {
|
||||||
throw new Error(
|
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._service_worker = navigator.serviceWorker;
|
||||||
this.registerServiceWorker('/service-worker.js');
|
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)
|
return this._service_worker.register(sw_script)
|
||||||
.then(this._onRegisterServiceWorker)
|
.then(this._onRegisterServiceWorker)
|
||||||
.catch(function (error) {
|
.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!
|
* Need register some extra API? override this!
|
||||||
*
|
*
|
||||||
|
@ -87,7 +43,7 @@ odoo.define("web_pwa_oca.PWAManager", function (require) {
|
||||||
* @param {ServiceWorkerRegistration} registration
|
* @param {ServiceWorkerRegistration} registration
|
||||||
*/
|
*/
|
||||||
_onRegisterServiceWorker: function (registration) {
|
_onRegisterServiceWorker: function (registration) {
|
||||||
console.log('[ServiceWorker] Registered:', registration);
|
console.log(_t('[ServiceWorker] Registered:'), registration);
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -1,14 +0,0 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<templates>
|
|
||||||
|
|
||||||
<t t-name="web_pwa_oca.systray.install">
|
|
||||||
<a href="#" role="menuitem" id="pwa_install_button" data-menu="installpwa" class="dropdown-item" hidden="1">Install PWA</a>
|
|
||||||
</t>
|
|
||||||
|
|
||||||
<t t-extend="UserMenu.Actions">
|
|
||||||
<t t-jquery="a[data-menu='settings']" t-operation="after">
|
|
||||||
<t t-call="web_pwa_oca.systray.install"/>
|
|
||||||
</t>
|
|
||||||
</t>
|
|
||||||
|
|
||||||
</templates>
|
|
|
@ -18,7 +18,6 @@
|
||||||
<template id="assets_backend" name="web service worker assets" inherit_id="web.assets_backend">
|
<template id="assets_backend" name="web service worker assets" inherit_id="web.assets_backend">
|
||||||
<xpath expr="." position="inside">
|
<xpath expr="." position="inside">
|
||||||
<script type="text/javascript" src="/web_pwa_oca/static/src/js/pwa_manager.js"></script>
|
<script type="text/javascript" src="/web_pwa_oca/static/src/js/pwa_manager.js"></script>
|
||||||
<script type="text/javascript" src="/web_pwa_oca/static/src/js/pwa_install.js"></script>
|
|
||||||
<script type="text/javascript" src="/web_pwa_oca/static/src/js/webclient.js"></script>
|
<script type="text/javascript" src="/web_pwa_oca/static/src/js/webclient.js"></script>
|
||||||
</xpath>
|
</xpath>
|
||||||
</template>
|
</template>
|
||||||
|
|
Loading…
Reference in New Issue