diff --git a/web_pwa_customize/README.rst b/web_pwa_customize/README.rst index 4210c429be62..1e992f8b2362 100644 --- a/web_pwa_customize/README.rst +++ b/web_pwa_customize/README.rst @@ -1,7 +1,3 @@ -.. image:: https://odoo-community.org/readme-banner-image - :target: https://odoo-community.org/get-involved?utm_source=readme - :alt: Odoo Community Association - ================= Web Pwa Customize ================= @@ -17,7 +13,7 @@ Web Pwa Customize .. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png :target: https://odoo-community.org/page/development-status :alt: Beta -.. |badge2| image:: https://img.shields.io/badge/license-AGPL--3-blue.png +.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html :alt: License: AGPL-3 .. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fweb-lightgray.png?logo=github @@ -78,6 +74,10 @@ Contributors - Víctor Martínez - Pedro M. Baeza +- `Trascendtech `__: + + - Javier Carpio + Maintainers ----------- diff --git a/web_pwa_customize/__manifest__.py b/web_pwa_customize/__manifest__.py index 8e9910566603..4cd98ce9ea18 100644 --- a/web_pwa_customize/__manifest__.py +++ b/web_pwa_customize/__manifest__.py @@ -2,13 +2,17 @@ # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). { "name": "Web Pwa Customize", + "version": "18.0.1.0.0", + "summary": "Allows to customize the Progressive Web App (PWA) settings", "author": "Tecnativa, Odoo Community Association (OCA)", "website": "https://github.com/OCA/web", - "version": "18.0.1.0.0", "depends": ["web"], "license": "AGPL-3", "category": "Website", "installable": True, "maintainers": ["victoralmau"], - "data": ["views/res_config_settings_views.xml"], + "data": [ + "views/res_config_settings_views.xml", + "views/pwa_assets.xml", + ], } diff --git a/web_pwa_customize/controllers/webmanifest.py b/web_pwa_customize/controllers/webmanifest.py index 13f2600b80b8..a255013833e1 100644 --- a/web_pwa_customize/controllers/webmanifest.py +++ b/web_pwa_customize/controllers/webmanifest.py @@ -1,15 +1,12 @@ # Copyright 2024 Tecnativa - Víctor Martínez -# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -import json +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). -from odoo import http from odoo.http import request -from odoo.tools import ustr -from odoo.addons.web.controllers import webmanifest +from odoo.addons.web.controllers.webmanifest import WebManifest -class WebManifest(webmanifest.WebManifest): +class WebManifest(WebManifest): def _get_pwa_manifest_icons(self, pwa_icon): icons = [] if not pwa_icon.mimetype.startswith("image/svg"): @@ -30,7 +27,16 @@ def _get_pwa_manifest_icons(self, pwa_icon): for icon in all_icons: icon_size_name = icon.url.split("/")[-1].lstrip("icon").split(".")[0] icons.append( - {"src": icon.url, "sizes": icon_size_name, "type": icon.mimetype} + { + "src": icon.url, + "sizes": icon_size_name, + "type": icon.mimetype, + # "any maskable" ensures the icon is displayed as-is in + # Firefox ("any") and used edge-to-edge inside Android + # adaptive icons in Chrome ("maskable"), avoiding the + # white wrapper Chrome adds around non-maskable icons. + "purpose": "any maskable", + } ) else: icons = [ @@ -38,38 +44,31 @@ def _get_pwa_manifest_icons(self, pwa_icon): "src": pwa_icon.url, "sizes": "128x128 144x144 152x152 192x192 256x256 512x512", "type": pwa_icon.mimetype, + "purpose": "any maskable", } ] return icons - @http.route( - "/web/manifest.webmanifest", - type="http", - auth="public", - methods=["GET"], - readonly=True, - ) - def webmanifest(self): - """Call super and overwrite the values that we want.""" - res = super().webmanifest() - manifest = json.loads(res.response[0]) + def _get_webmanifest(self): + manifest = super()._get_webmanifest() icp = request.env["ir.config_parameter"].sudo() - manifest["short_name"] = icp.get_param("pwa.manifest.short_name", "Odoo") + + # Override with custom values + manifest["short_name"] = icp.get_param( + "pwa.manifest.short_name", manifest.get("short_name", "Odoo") + ) manifest["background_color"] = icp.get_param( "pwa.manifest.background_color", "#714B67" ) manifest["theme_color"] = icp.get_param("pwa.manifest.theme_color", "#714B67") + + # Handle custom icons pwa_icon = ( request.env["ir.attachment"] .sudo() - .search([("url", "like", "/web_pwa_customize/icon.")]) + .search([("url", "like", "/web_pwa_customize/icon.")], limit=1) ) if pwa_icon: manifest["icons"] = self._get_pwa_manifest_icons(pwa_icon) - body = json.dumps(manifest, default=ustr) - return request.make_response( - body, - [ - ("Content-Type", "application/manifest+json"), - ], - ) + + return manifest diff --git a/web_pwa_customize/models/__init__.py b/web_pwa_customize/models/__init__.py index 0deb68c46806..80c009e3e668 100644 --- a/web_pwa_customize/models/__init__.py +++ b/web_pwa_customize/models/__init__.py @@ -1 +1 @@ -from . import res_config_settings +from . import ir_http, res_config_settings diff --git a/web_pwa_customize/models/ir_http.py b/web_pwa_customize/models/ir_http.py new file mode 100644 index 000000000000..92e891c2393d --- /dev/null +++ b/web_pwa_customize/models/ir_http.py @@ -0,0 +1,29 @@ +# Copyright 2024 Tecnativa - Víctor Martínez +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +from odoo import models +from odoo.http import request + + +class IrHttp(models.AbstractModel): + _inherit = "ir.http" + + def webclient_rendering_context(self): + result = super().webclient_rendering_context() + icp = request.env["ir.config_parameter"].sudo() + pwa_icon_attachment = ( + request.env["ir.attachment"] + .sudo() + .search([("url", "like", "/web_pwa_customize/icon")], limit=1) + ) + result.update( + { + "manifest_theme_color": icp.get_param( + "pwa.manifest.theme_color", "#71639e" + ), + "manifest_short_name": icp.get_param("pwa.manifest.short_name", "Odoo"), + "manifest_apple_touch_icon": pwa_icon_attachment.url + if pwa_icon_attachment + else "/web/static/img/odoo-icon-ios.png", + } + ) + return result diff --git a/web_pwa_customize/models/res_config_settings.py b/web_pwa_customize/models/res_config_settings.py index 2f4226dcbd5c..9ed0cd1e3a19 100644 --- a/web_pwa_customize/models/res_config_settings.py +++ b/web_pwa_customize/models/res_config_settings.py @@ -1,5 +1,5 @@ # Copyright 2024 Tecnativa - Víctor Martínez -# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl). +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). import base64 import io import sys @@ -62,7 +62,7 @@ def _write_icon_to_attachment(self, extension, mimetype, size=None): resized_image.save(icon_bytes_output, format=extension.lstrip(".").upper()) icon = base64.b64encode(icon_bytes_output.getvalue()) url = f"{self._pwa_icon_url_base}{str(size[0])}x{str(size[1])}{extension}" - # Retreive existing attachment + # Retrieve existing attachment attachment_model = self.env["ir.attachment"].sudo() attachment = attachment_model.search([("url", "like", url)]) # Write values to ir_attachment @@ -134,3 +134,4 @@ def set_values(self): self._write_icon_to_attachment( pwa_icon_extension, pwa_icon_mimetype, size=size ) + return res diff --git a/web_pwa_customize/readme/CONTRIBUTORS.md b/web_pwa_customize/readme/CONTRIBUTORS.md index 5fee3904270d..dfe36ba1f740 100644 --- a/web_pwa_customize/readme/CONTRIBUTORS.md +++ b/web_pwa_customize/readme/CONTRIBUTORS.md @@ -1,3 +1,5 @@ - [Tecnativa](https://www.tecnativa.com): - Víctor Martínez - Pedro M. Baeza +- [Trascendtech](https://trascendtech.com): + - Javier Carpio diff --git a/web_pwa_customize/static/description/index.html b/web_pwa_customize/static/description/index.html index 4f8e9623c2d9..432ac0d923ab 100644 --- a/web_pwa_customize/static/description/index.html +++ b/web_pwa_customize/static/description/index.html @@ -3,7 +3,7 @@ -README.rst +Web Pwa Customize -
+
+

Web Pwa Customize

- - -Odoo Community Association - -
-

Web Pwa Customize

-

Beta License: AGPL-3 OCA/web Translate me on Weblate Try me on Runboat

+

Beta License: AGPL-3 OCA/web Translate me on Weblate Try me on Runboat

This module allows to configure data for Progressive Web App: Short name, Background color, Theme color and Icon.

Table of contents

@@ -392,17 +387,17 @@

Web Pwa Customize

-

Use Cases / Context

+

Use Cases / Context

The existing definitions in the old web_pwa_oca of 16.0 (not existing or customizable in core) are maintained.

-

Configuration

+

Configuration

#. Go to Settings > General Settings. #. In the ‘Progressive Web App’ section you can configure all the data.

-

Bug Tracker

+

Bug Tracker

Bugs are tracked on GitHub Issues. In case of trouble, please check there if your issue has already been reported. If you spotted it first, help us to smash it by providing a detailed and welcomed @@ -410,25 +405,29 @@

Bug Tracker

Do not contact contributors directly about support or help with technical issues.

-

Credits

+

Credits

-

Authors

+

Authors

  • Tecnativa
-

Contributors

+

Contributors

-

Maintainers

+

Maintainers

This module is maintained by the OCA.

Odoo Community Association @@ -443,6 +442,5 @@

Maintainers

-
diff --git a/web_pwa_customize/views/pwa_assets.xml b/web_pwa_customize/views/pwa_assets.xml new file mode 100644 index 000000000000..40ed7bd190e3 --- /dev/null +++ b/web_pwa_customize/views/pwa_assets.xml @@ -0,0 +1,19 @@ + + + +