Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[12.0][IMP] web_pwa_oca: Drop BeforeInstallPrompt #1759

Merged
merged 4 commits into from
Dec 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions web_pwa_oca/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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`:


Expand Down Expand Up @@ -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 using the option.

Known issues / Roadmap
======================
Expand Down Expand Up @@ -131,9 +132,8 @@ 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
* Firefox disable service worker in private mode. See https://bugzilla.mozilla.org/show_bug.cgi?id=1601916

Bug Tracker
===========
Expand Down
3 changes: 0 additions & 3 deletions web_pwa_oca/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
}
2 changes: 0 additions & 2 deletions web_pwa_oca/readme/INSTALL.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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`:


Expand Down
5 changes: 2 additions & 3 deletions web_pwa_oca/readme/ROADMAP.rst
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,5 @@
* 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
* Firefox disable service worker in private mode. See https://bugzilla.mozilla.org/show_bug.cgi?id=1601916
7 changes: 5 additions & 2 deletions web_pwa_oca/readme/USAGE.rst
Original file line number Diff line number Diff line change
@@ -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 using the option.
13 changes: 7 additions & 6 deletions web_pwa_oca/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,6 @@ <h1><a class="toc-backref" href="#id1">Installation</a></h1>
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>
<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>
<pre class="doctest-block">
&gt;&gt;&gt; from openupgradelib import openupgrade
Expand All @@ -432,9 +431,11 @@ <h1><a class="toc-backref" href="#id2">Configuration</a></h1>
<h1><a class="toc-backref" href="#id3">Usage</a></h1>
<p>To use your PWA:</p>
<ol class="arabic simple">
<li>Open the Odoo web app using a supported browser (like Chrome/Chromium)</li>
<li>Install the PWA</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>Open the browser options</li>
<li>Click on ‘Add to Home screen’ (or ‘Install’ in other browsers)</li>
Tardo marked this conversation as resolved.
Show resolved Hide resolved
</ol>
<p>** Maybe you need refresh the page to load the service worker after using the option.</p>
</div>
<div class="section" id="known-issues-roadmap">
<h1><a class="toc-backref" href="#id4">Known issues / Roadmap</a></h1>
Expand Down Expand Up @@ -478,9 +479,9 @@ <h1><a class="toc-backref" href="#id4">Known issues / Roadmap</a></h1>
</li>
<li><p class="first">Evaluate to support ‘require’ system.</p>
</li>
<li><p class="first">‘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.</p>
<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>
</li>
<li><p class="first">Firefox disable service worker in private mode. See <a class="reference external" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1601916">https://bugzilla.mozilla.org/show_bug.cgi?id=1601916</a></p>
</li>
</ul>
</div>
Expand Down
40 changes: 0 additions & 40 deletions web_pwa_oca/static/src/js/pwa_install.js

This file was deleted.

64 changes: 11 additions & 53 deletions web_pwa_oca/static/src/js/pwa_manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,26 @@
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,

var PWAManager = Widget.extend({
/**
* @override
*/
init: function () {
this._super.apply(this, arguments);
if (!('serviceWorker' in navigator)) {
throw new Error(
"This browser is not compatible with service workers");
console.error(
_t("Service workers are not supported! Maybe you are not using HTTPS or you work in private mode."));
}
else {
this._service_worker = navigator.serviceWorker;
this.registerServiceWorker('/service-worker.js');
}
this._service_worker = navigator.serviceWorker;
this.registerServiceWorker('/service-worker.js');
window.addEventListener(
'beforeinstallprompt', this._onBeforeInstallPrompt.bind(this));
},

/**
Expand All @@ -33,61 +34,18 @@ 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);
});
},

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);
}
console.log(_t('[ServiceWorker] Registration failed: '), error);
});
},

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!
*
* @private
* @param {ServiceWorkerRegistration} registration
*/
_onRegisterServiceWorker: function (registration) {
console.log('[ServiceWorker] Registered:', registration);
console.log(_t('[ServiceWorker] Registered:'), registration);
},
});

Expand Down
14 changes: 0 additions & 14 deletions web_pwa_oca/static/src/xml/pwa_install.xml

This file was deleted.

1 change: 0 additions & 1 deletion web_pwa_oca/templates/assets.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
<template id="assets_backend" name="web service worker assets" inherit_id="web.assets_backend">
<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_install.js"></script>
<script type="text/javascript" src="/web_pwa_oca/static/src/js/webclient.js"></script>
</xpath>
</template>
Expand Down