Skip to content
Open
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
10 changes: 5 additions & 5 deletions web_pwa_customize/README.rst
Original file line number Diff line number Diff line change
@@ -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
=================
Expand All @@ -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
Expand Down Expand Up @@ -78,6 +74,10 @@ Contributors
- Víctor Martínez
- Pedro M. Baeza

- `Trascendtech <https://trascendtech.com>`__:

- Javier Carpio

Maintainers
-----------

Expand Down
8 changes: 6 additions & 2 deletions web_pwa_customize/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
],
}
53 changes: 26 additions & 27 deletions web_pwa_customize/controllers/webmanifest.py
Original file line number Diff line number Diff line change
@@ -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"):
Expand All @@ -30,46 +27,48 @@ 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 = [
{
"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
2 changes: 1 addition & 1 deletion web_pwa_customize/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from . import res_config_settings
from . import ir_http, res_config_settings
29 changes: 29 additions & 0 deletions web_pwa_customize/models/ir_http.py
Original file line number Diff line number Diff line change
@@ -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
5 changes: 3 additions & 2 deletions web_pwa_customize/models/res_config_settings.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -134,3 +134,4 @@ def set_values(self):
self._write_icon_to_attachment(
pwa_icon_extension, pwa_icon_mimetype, size=size
)
return res
2 changes: 2 additions & 0 deletions web_pwa_customize/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
- [Tecnativa](https://www.tecnativa.com):
- Víctor Martínez
- Pedro M. Baeza
- [Trascendtech](https://trascendtech.com):
- Javier Carpio
32 changes: 15 additions & 17 deletions web_pwa_customize/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="generator" content="Docutils: https://docutils.sourceforge.io/" />
<title>README.rst</title>
<title>Web Pwa Customize</title>
<style type="text/css">

/*
Expand Down Expand Up @@ -360,21 +360,16 @@
</style>
</head>
<body>
<div class="document">
<div class="document" id="web-pwa-customize">
<h1 class="title">Web Pwa Customize</h1>


<a class="reference external image-reference" href="https://odoo-community.org/get-involved?utm_source=readme">
<img alt="Odoo Community Association" src="https://odoo-community.org/readme-banner-image" />
</a>
<div class="section" id="web-pwa-customize">
<h1>Web Pwa Customize</h1>
<!-- !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:056d21f8b911279aef8c24b7b295c0b97849ca771684f97ca401f42afc2a7d08
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external image-reference" 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 image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/license-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/web/tree/18.0/web_pwa_customize"><img alt="OCA/web" src="https://img.shields.io/badge/github-OCA%2Fweb-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/web-18-0/web-18-0-web_pwa_customize"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/web&amp;target_branch=18.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p><a class="reference external image-reference" 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 image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/web/tree/18.0/web_pwa_customize"><img alt="OCA/web" src="https://img.shields.io/badge/github-OCA%2Fweb-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/web-18-0/web-18-0-web_pwa_customize"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/web&amp;target_branch=18.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p>This module allows to configure data for Progressive Web App: Short
name, Background color, Theme color and Icon.</p>
<p><strong>Table of contents</strong></p>
Expand All @@ -392,43 +387,47 @@ <h1>Web Pwa Customize</h1>
</ul>
</div>
<div class="section" id="use-cases-context">
<h2><a class="toc-backref" href="#toc-entry-1">Use Cases / Context</a></h2>
<h1><a class="toc-backref" href="#toc-entry-1">Use Cases / Context</a></h1>
<p>The existing definitions in the old web_pwa_oca of 16.0 (not existing or
customizable in core) are maintained.</p>
</div>
<div class="section" id="configuration">
<h2><a class="toc-backref" href="#toc-entry-2">Configuration</a></h2>
<h1><a class="toc-backref" href="#toc-entry-2">Configuration</a></h1>
<p>#. Go to Settings &gt; General Settings. #. In the ‘Progressive Web App’
section you can configure all the data.</p>
</div>
<div class="section" id="bug-tracker">
<h2><a class="toc-backref" href="#toc-entry-3">Bug Tracker</a></h2>
<h1><a class="toc-backref" href="#toc-entry-3">Bug Tracker</a></h1>
<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 to smash it by providing a detailed and welcomed
<a class="reference external" href="https://github.com/OCA/web/issues/new?body=module:%20web_pwa_customize%0Aversion:%2018.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">
<h2><a class="toc-backref" href="#toc-entry-4">Credits</a></h2>
<h1><a class="toc-backref" href="#toc-entry-4">Credits</a></h1>
<div class="section" id="authors">
<h3><a class="toc-backref" href="#toc-entry-5">Authors</a></h3>
<h2><a class="toc-backref" href="#toc-entry-5">Authors</a></h2>
<ul class="simple">
<li>Tecnativa</li>
</ul>
</div>
<div class="section" id="contributors">
<h3><a class="toc-backref" href="#toc-entry-6">Contributors</a></h3>
<h2><a class="toc-backref" href="#toc-entry-6">Contributors</a></h2>
<ul class="simple">
<li><a class="reference external" href="https://www.tecnativa.com">Tecnativa</a>:<ul>
<li>Víctor Martínez</li>
<li>Pedro M. Baeza</li>
</ul>
</li>
<li><a class="reference external" href="https://trascendtech.com">Trascendtech</a>:<ul>
<li>Javier Carpio</li>
</ul>
</li>
</ul>
</div>
<div class="section" id="maintainers">
<h3><a class="toc-backref" href="#toc-entry-7">Maintainers</a></h3>
<h2><a class="toc-backref" href="#toc-entry-7">Maintainers</a></h2>
<p>This module is maintained by the OCA.</p>
<a class="reference external image-reference" href="https://odoo-community.org">
<img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" />
Expand All @@ -443,6 +442,5 @@ <h3><a class="toc-backref" href="#toc-entry-7">Maintainers</a></h3>
</div>
</div>
</div>
</div>
</body>
</html>
19 changes: 19 additions & 0 deletions web_pwa_customize/views/pwa_assets.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<template id="webclient_bootstrap_pwa" inherit_id="web.webclient_bootstrap">
<xpath expr="//meta[@name='theme-color']" position="attributes">
<attribute name="t-att-content">manifest_theme_color</attribute>
</xpath>
<xpath expr="//meta[@name='theme-color']" position="after">
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="default" />
<meta
name="apple-mobile-web-app-title"
t-att-content="manifest_short_name"
/>
</xpath>
<xpath expr="//link[@rel='apple-touch-icon']" position="attributes">
<attribute name="t-att-href">manifest_apple_touch_icon</attribute>
</xpath>
</template>
</odoo>
Loading