[MIG] web_pwa_oca: Migration to v15.0

pull/2640/head
sergio-teruel 2022-10-03 21:29:56 +02:00 committed by Michele
parent 54d4d0eac2
commit 162a3d1943
No known key found for this signature in database
GPG Key ID: 41B96132B0596B70
11 changed files with 114 additions and 75 deletions

View File

@ -14,13 +14,13 @@ Progressive web application
:target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html
:alt: License: LGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fweb-lightgray.png?logo=github
:target: https://github.com/OCA/web/tree/14.0/web_pwa_oca
:target: https://github.com/OCA/web/tree/15.0/web_pwa_oca
:alt: OCA/web
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/web-14-0/web-14-0-web_pwa_oca
:target: https://translation.odoo-community.org/projects/web-15-0/web-15-0-web_pwa_oca
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png
:target: https://runbot.odoo-community.org/runbot/162/14.0
:target: https://runbot.odoo-community.org/runbot/162/15.0
:alt: Try me on Runbot
|badge1| |badge2| |badge3| |badge4| |badge5|
@ -140,7 +140,7 @@ Bug Tracker
Bugs are tracked on `GitHub Issues <https://github.com/OCA/web/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us smashing it by providing a detailed and welcomed
`feedback <https://github.com/OCA/web/issues/new?body=module:%20web_pwa_oca%0Aversion:%2014.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
`feedback <https://github.com/OCA/web/issues/new?body=module:%20web_pwa_oca%0Aversion:%2015.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
Do not contact contributors directly about support or help with technical issues.
@ -164,6 +164,7 @@ Contributors
* Alexandre D. Díaz
* João Marques
* Sergio Teruel
Maintainers
~~~~~~~~~~~
@ -186,6 +187,6 @@ Current `maintainer <https://odoo-community.org/page/maintainer-role>`__:
|maintainer-eLBati|
This module is part of the `OCA/web <https://github.com/OCA/web/tree/14.0/web_pwa_oca>`_ project on GitHub.
This module is part of the `OCA/web <https://github.com/OCA/web/tree/15.0/web_pwa_oca>`_ project on GitHub.
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

View File

@ -6,7 +6,7 @@
{
"name": "Progressive web application",
"summary": "Make Odoo a PWA",
"version": "14.0.1.0.0",
"version": "15.0.1.0.0",
"development_status": "Beta",
"category": "Website",
"website": "https://github.com/OCA/web",
@ -17,5 +17,11 @@
"installable": True,
"depends": ["web", "mail"],
"data": ["templates/assets.xml", "views/res_config_settings_views.xml"],
"assets": {
"web.assets_backend": [
"/web_pwa_oca/static/src/js/pwa_manager.js",
"/web_pwa_oca/static/src/js/webclient.js",
]
},
"images": ["static/description/pwa.png"],
}

View File

@ -13,9 +13,9 @@ class PWA(Controller):
return [
"/web/static/lib/underscore/underscore.js",
"/web_pwa_oca/static/src/js/worker/jquery-sw-compat.js",
"/web/static/src/js/promise_extension.js",
"/web/static/src/js/boot.js",
"/web/static/src/js/core/class.js",
"/web/static/src/legacy/js/promise_extension.js",
"/web/static/src/boot.js",
"/web/static/src/legacy/js/core/class.js",
"/web_pwa_oca/static/src/js/worker/pwa.js",
]
@ -52,6 +52,7 @@ class PWA(Controller):
% (str(size[0]), str(size[1])),
"sizes": "{}x{}".format(str(size[0]), str(size[1])),
"type": "image/png",
"purpose": "any maskable",
}
)
elif not pwa_icon.mimetype.startswith("image/svg"):

View File

@ -48,7 +48,15 @@ class ServiceWorker(PWA):
def _get_js_pwa_init(self):
return """
const oca_pwa = new PWA({});
let promise_start = Promise.resolve();
if (typeof self.oca_pwa === "undefined") {{
self.oca_pwa = new PWA({});
promise_start = self.oca_pwa.start();
if (self.serviceWorker.state === "activated") {{
promise_start = promise_start.then(
() => self.oca_pwa.activateWorker(true));
}}
}}
""".format(
self._get_pwa_params()
)

View File

@ -6,3 +6,4 @@
* Alexandre D. Díaz
* João Marques
* Sergio Teruel

View File

@ -367,7 +367,7 @@ ul.auto-toc {
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external" href="http://www.gnu.org/licenses/lgpl-3.0-standalone.html"><img alt="License: LGPL-3" src="https://img.shields.io/badge/licence-LGPL--3-blue.png" /></a> <a class="reference external" href="https://github.com/OCA/web/tree/14.0/web_pwa_oca"><img alt="OCA/web" src="https://img.shields.io/badge/github-OCA%2Fweb-lightgray.png?logo=github" /></a> <a class="reference external" href="https://translation.odoo-community.org/projects/web-14-0/web-14-0-web_pwa_oca"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external" href="https://runbot.odoo-community.org/runbot/162/14.0"><img alt="Try me on Runbot" src="https://img.shields.io/badge/runbot-Try%20me-875A7B.png" /></a></p>
<p><a class="reference external" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external" href="http://www.gnu.org/licenses/lgpl-3.0-standalone.html"><img alt="License: LGPL-3" src="https://img.shields.io/badge/licence-LGPL--3-blue.png" /></a> <a class="reference external" href="https://github.com/OCA/web/tree/15.0/web_pwa_oca"><img alt="OCA/web" src="https://img.shields.io/badge/github-OCA%2Fweb-lightgray.png?logo=github" /></a> <a class="reference external" href="https://translation.odoo-community.org/projects/web-15-0/web-15-0-web_pwa_oca"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external" href="https://runbot.odoo-community.org/runbot/162/15.0"><img alt="Try me on Runbot" src="https://img.shields.io/badge/runbot-Try%20me-875A7B.png" /></a></p>
<p>Make Odoo an installable Progressive Web Application.</p>
<p>Progressive Web Apps provide an installable, app-like experience on desktop and mobile that are built and delivered directly via the web.
Theyre web apps that are fast and reliable. And most importantly, theyre web apps that work in any browser.
@ -464,7 +464,7 @@ need to use the following workaround:</p>
<pre class="code javascript literal-block">
<span class="kd">var</span> <span class="nx">MyClass</span> <span class="o">=</span> <span class="nx">OdooClass</span><span class="p">.</span><span class="nx">extend</span><span class="p">({</span>
<span class="nx">myFunc</span><span class="o">:</span> <span class="kd">function</span><span class="p">()</span> <span class="p">{</span>
<span class="k">return</span> <span class="k">new</span> <span class="nb">Promise</span><span class="p">(</span><span class="k">async</span> <span class="p">(</span><span class="nx">resolve</span><span class="p">,</span> <span class="nx">reject</span><span class="p">)</span> <span class="p">=&gt;</span> <span class="p">{</span>
<span class="k">return</span> <span class="ow">new</span> <span class="nb">Promise</span><span class="p">(</span><span class="k">async</span> <span class="p">(</span><span class="nx">resolve</span><span class="p">,</span> <span class="nx">reject</span><span class="p">)</span> <span class="p">=&gt;</span> <span class="p">{</span>
<span class="kd">const</span> <span class="nx">mydata</span> <span class="o">=</span> <span class="k">await</span> <span class="p">...</span><span class="k">do</span> <span class="k">await</span> <span class="nx">stuff</span><span class="p">...</span>
<span class="k">return</span> <span class="nx">resolve</span><span class="p">(</span><span class="nx">mydata</span><span class="p">);</span>
<span class="p">});</span>
@ -488,7 +488,7 @@ doesnt send the cookie and web manifest returns 404.</p>
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/web/issues">GitHub Issues</a>.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us smashing it by providing a detailed and welcomed
<a class="reference external" href="https://github.com/OCA/web/issues/new?body=module:%20web_pwa_oca%0Aversion:%2014.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<a class="reference external" href="https://github.com/OCA/web/issues/new?body=module:%20web_pwa_oca%0Aversion:%2015.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<p>Do not contact contributors directly about support or help with technical issues.</p>
</div>
<div class="section" id="credits">
@ -510,6 +510,7 @@ If you spotted it first, help us smashing it by providing a detailed and welcome
<li><a class="reference external" href="https://tecnativa.com">Tecnativa</a>:<ul>
<li>Alexandre D. Díaz</li>
<li>João Marques</li>
<li>Sergio Teruel</li>
</ul>
</li>
</ul>
@ -523,7 +524,7 @@ mission is to support the collaborative development of Odoo features and
promote its widespread use.</p>
<p>Current <a class="reference external" href="https://odoo-community.org/page/maintainer-role">maintainer</a>:</p>
<p><a class="reference external" href="https://github.com/eLBati"><img alt="eLBati" src="https://github.com/eLBati.png?size=40px" /></a></p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/web/tree/14.0/web_pwa_oca">OCA/web</a> project on GitHub.</p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/web/tree/15.0/web_pwa_oca">OCA/web</a> project on GitHub.</p>
<p>You are welcome to contribute. To learn how please visit <a class="reference external" href="https://odoo-community.org/page/Contribute">https://odoo-community.org/page/Contribute</a>.</p>
</div>
</div>

View File

@ -5,26 +5,44 @@ odoo.define("web_pwa_oca.PWAManager", function (require) {
"use strict";
var core = require("web.core");
var config = require("web.config");
var Widget = require("web.Widget");
var _t = core._t;
/**
* @returns {Boolean}
*/
function isPWAStandalone() {
return (
window.navigator.standalone ||
document.referrer.includes("android-app://") ||
window.matchMedia("(display-mode: standalone)").matches
);
}
if (isPWAStandalone()) {
config.device.isMobile = true;
}
var PWAManager = Widget.extend({
/**
* @override
*/
init: function () {
this._super.apply(this, arguments);
if (!("serviceWorker" in navigator)) {
this._isServiceWorkerSupported = "serviceWorker" in navigator;
if (!this._isServiceWorkerSupported) {
console.error(
_t(
"Service workers are not supported! Maybe you are not using HTTPS or you work in private mode."
)
);
}
if ("serviceWorker" in navigator) {
} else {
this._service_worker = navigator.serviceWorker;
this.registerServiceWorker("/service-worker.js");
this.registerServiceWorker("/service-worker.js", {
updateViaCache: "none",
});
}
},
@ -32,15 +50,22 @@ odoo.define("web_pwa_oca.PWAManager", function (require) {
* @param {String} sw_script
* @returns {Promise}
*/
registerServiceWorker: function (sw_script) {
registerServiceWorker: function (sw_script, options) {
return this._service_worker
.register(sw_script)
.then(this._onRegisterServiceWorker)
.register(sw_script, options)
.then(this._onRegisterServiceWorker.bind(this))
.catch(function (error) {
console.log(_t("[ServiceWorker] Registration failed: "), error);
});
},
/**
* @returns {Boolean}
*/
isPWAStandalone: function () {
return isPWAStandalone();
},
/**
* Need register some extra API? override this!
*

View File

@ -1,19 +1,15 @@
/* Copyright 2020 Tecnativa - Alexandre D. Díaz
/* Copyright 2022 Tecnativa - Sergio Teruel
* License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). */
odoo.define("web_pwa_oca.webclient", function (require) {
odoo.define("web_pwa_oca.pwa_launch", function (require) {
"use strict";
var WebClient = require("web.WebClient");
var core = require("web.core");
var PWAManager = require("web_pwa_oca.PWAManager");
WebClient.include({
/**
* @override
*/
show_application: function () {
this.pwa_manager = new PWAManager(this);
return this._super.apply(this, arguments);
},
core.bus.on("web_client_ready", null, function () {
this.pwa_manager = new PWAManager(this);
const def = this.pwa_manager.start();
return Promise.all([def]);
});
});

View File

@ -17,6 +17,14 @@ odoo.define("web_pwa_oca.PWA", function (require) {
// eslint-disable-next-line
init: function (params) {
// To be overridden
this._sw_version = params.sw_version;
},
/**
* @returns {Promise}
*/
start: function () {
return Promise.resolve();
},
/**
@ -30,10 +38,19 @@ odoo.define("web_pwa_oca.PWA", function (require) {
/**
* @returns {Promise}
*/
activateWorker: function () {
/* eslint-disable no-unused-vars */
activateWorker: function (forced) {
// To be overridden
return Promise.resolve();
},
/**
* @returns {Promise}
*/
processRequest: function (request) {
// To be overridden
return fetch(request);
},
});
return PWA;

View File

@ -28,20 +28,5 @@
<meta name="theme-color" t-att-content="pwa_theme_color" />
</xpath>
</template>
<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
type="text/javascript"
src="/web_pwa_oca/static/src/js/webclient.js"
/>
</xpath>
</template>
</odoo>

View File

@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<data>
<record id="res_config_settings_view_form" model="ir.ui.view">
<field name="name">res.config.settings.view.form.pwa</field>
<field name="model">res.config.settings</field>
@ -13,53 +12,53 @@
<div class="o_setting_right_pane">
<label for="pwa_name" string="PWA Title" />
<span
class="fa fa-lg fa-globe"
title="Icon next to name"
/>
class="fa fa-lg fa-globe"
title="Icon next to name"
/>
<div class="text-muted">
Name and icon of your PWA
</div>
<div class="content-group">
<div class="row mt16">
<label
class="col-lg-3 o_light_label"
string="Name"
for="pwa_name"
/>
class="col-lg-3 o_light_label"
string="Name"
for="pwa_name"
/>
<field name="pwa_name" />
</div>
<div class="row mt16">
<label
class="col-lg-3 o_light_label"
string="Short Name"
for="pwa_short_name"
/>
class="col-lg-3 o_light_label"
string="Short Name"
for="pwa_short_name"
/>
<field name="pwa_short_name" />
</div>
<div class="row">
<label
class="col-lg-3 o_light_label"
for="pwa_background_color"
/>
class="col-lg-3 o_light_label"
for="pwa_background_color"
/>
<field name="pwa_background_color" />
</div>
<div class="row">
<label
class="col-lg-3 o_light_label"
for="pwa_theme_color"
/>
class="col-lg-3 o_light_label"
for="pwa_theme_color"
/>
<field name="pwa_theme_color" />
</div>
<div class="row">
<label
class="col-lg-3 o_light_label"
for="pwa_icon"
/>
class="col-lg-3 o_light_label"
for="pwa_icon"
/>
<field
name="pwa_icon"
widget="image"
class="float-left oe_avatar"
/>
name="pwa_icon"
widget="image"
class="float-left oe_avatar"
/>
</div>
</div>
</div>
@ -68,5 +67,4 @@
</div>
</field>
</record>
</data>
</odoo>