diff --git a/web_pwa_oca/__manifest__.py b/web_pwa_oca/__manifest__.py index d23a0c373..8080c2f04 100644 --- a/web_pwa_oca/__manifest__.py +++ b/web_pwa_oca/__manifest__.py @@ -13,15 +13,8 @@ "license": "LGPL-3", "application": True, "installable": True, - "depends": [ - 'web', - 'mail', - ], - "data": [ - "views/webclient_templates.xml", - ], - 'qweb': [ - 'static/src/xml/pwa_install.xml', - ], - 'images': ['static/description/pwa.png'], + "depends": ["web", "mail"], + "data": ["views/webclient_templates.xml"], + "qweb": ["static/src/xml/pwa_install.xml"], + "images": ["static/description/pwa.png"], } diff --git a/web_pwa_oca/controllers/main.py b/web_pwa_oca/controllers/main.py index 3254b648b..194d091b6 100644 --- a/web_pwa_oca/controllers/main.py +++ b/web_pwa_oca/controllers/main.py @@ -1,75 +1,77 @@ -from odoo.http import request, Controller, route +from odoo.http import Controller, request, route class PWA(Controller): - def get_asset_urls(self, asset_xml_id): - qweb = request.env['ir.qweb'].sudo() + qweb = request.env["ir.qweb"].sudo() assets = qweb._get_asset_nodes(asset_xml_id, {}, True, True) urls = [] for asset in assets: - if asset[0] == 'link': - urls.append(asset[1]['href']) - if asset[0] == 'script': - urls.append(asset[1]['src']) + if asset[0] == "link": + urls.append(asset[1]["href"]) + if asset[0] == "script": + urls.append(asset[1]["src"]) return urls - @route('/service-worker.js', type='http', auth="public") + @route("/service-worker.js", type="http", auth="public") def service_worker(self): - qweb = request.env['ir.qweb'].sudo() + qweb = request.env["ir.qweb"].sudo() urls = [] urls.extend(self.get_asset_urls("web.assets_common")) urls.extend(self.get_asset_urls("web.assets_backend")) version_list = [] for url in urls: - version_list.append(url.split('/')[3]) - cache_version = '-'.join(version_list) - mimetype = 'text/javascript;charset=utf-8' - content = qweb.render('web_pwa_oca.service_worker', { - 'pwa_cache_name': cache_version, - 'pwa_files_to_cache': urls, - }) - return request.make_response(content, [('Content-Type', mimetype)]) + version_list.append(url.split("/")[3]) + cache_version = "-".join(version_list) + mimetype = "text/javascript;charset=utf-8" + content = qweb.render( + "web_pwa_oca.service_worker", + {"pwa_cache_name": cache_version, "pwa_files_to_cache": urls}, + ) + return request.make_response(content, [("Content-Type", mimetype)]) - @route('/web_pwa_oca/manifest.json', type='http', auth="public") + @route("/web_pwa_oca/manifest.json", type="http", auth="public") def manifest(self): - qweb = request.env['ir.qweb'].sudo() - config_param = request.env['ir.config_parameter'].sudo() + qweb = request.env["ir.qweb"].sudo() + config_param = request.env["ir.config_parameter"].sudo() pwa_name = config_param.get_param("pwa.manifest.name", "Odoo PWA") pwa_short_name = config_param.get_param("pwa.manifest.short_name", "Odoo PWA") icon128x128 = config_param.get_param( - "pwa.manifest.icon128x128", - "/web_pwa_oca/static/img/icons/icon-128x128.png") + "pwa.manifest.icon128x128", "/web_pwa_oca/static/img/icons/icon-128x128.png" + ) icon144x144 = config_param.get_param( - "pwa.manifest.icon144x144", - "/web_pwa_oca/static/img/icons/icon-144x144.png") + "pwa.manifest.icon144x144", "/web_pwa_oca/static/img/icons/icon-144x144.png" + ) icon152x152 = config_param.get_param( - "pwa.manifest.icon152x152", - "/web_pwa_oca/static/img/icons/icon-152x152.png") + "pwa.manifest.icon152x152", "/web_pwa_oca/static/img/icons/icon-152x152.png" + ) icon192x192 = config_param.get_param( - "pwa.manifest.icon192x192", - "/web_pwa_oca/static/img/icons/icon-192x192.png") + "pwa.manifest.icon192x192", "/web_pwa_oca/static/img/icons/icon-192x192.png" + ) icon256x256 = config_param.get_param( - "pwa.manifest.icon256x256", - "/web_pwa_oca/static/img/icons/icon-256x256.png") + "pwa.manifest.icon256x256", "/web_pwa_oca/static/img/icons/icon-256x256.png" + ) icon512x512 = config_param.get_param( - "pwa.manifest.icon512x512", - "/web_pwa_oca/static/img/icons/icon-512x512.png") + "pwa.manifest.icon512x512", "/web_pwa_oca/static/img/icons/icon-512x512.png" + ) background_color = config_param.get_param( - "pwa.manifest.background_color", "#2E69B5") - theme_color = config_param.get_param( - "pwa.manifest.theme_color", "#2E69B5") - mimetype = 'application/json;charset=utf-8' - content = qweb.render('web_pwa_oca.manifest', { - 'pwa_name': pwa_name, - 'pwa_short_name': pwa_short_name, - 'icon128x128': icon128x128, - 'icon144x144': icon144x144, - 'icon152x152': icon152x152, - 'icon192x192': icon192x192, - 'icon256x256': icon256x256, - 'icon512x512': icon512x512, - 'background_color': background_color, - 'theme_color': theme_color, - }) - return request.make_response(content, [('Content-Type', mimetype)]) + "pwa.manifest.background_color", "#2E69B5" + ) + theme_color = config_param.get_param("pwa.manifest.theme_color", "#2E69B5") + mimetype = "application/json;charset=utf-8" + content = qweb.render( + "web_pwa_oca.manifest", + { + "pwa_name": pwa_name, + "pwa_short_name": pwa_short_name, + "icon128x128": icon128x128, + "icon144x144": icon144x144, + "icon152x152": icon152x152, + "icon192x192": icon192x192, + "icon256x256": icon256x256, + "icon512x512": icon512x512, + "background_color": background_color, + "theme_color": theme_color, + }, + ) + return request.make_response(content, [("Content-Type", mimetype)]) diff --git a/web_pwa_oca/static/src/js/pwa_install.js b/web_pwa_oca/static/src/js/pwa_install.js index 3a8b741fe..7b7d1f656 100644 --- a/web_pwa_oca/static/src/js/pwa_install.js +++ b/web_pwa_oca/static/src/js/pwa_install.js @@ -1,45 +1,43 @@ -odoo.define('web_pwa_oca.systray.install', function (require) { -"use strict"; +odoo.define("web_pwa_oca.systray.install", function(require) { + "use strict"; -var core = require('web.core'); -var session = require('web.session'); -var UserMenu = require('web.UserMenu'); + var UserMenu = require("web.UserMenu"); -if ('serviceWorker' in navigator) { - window.addEventListener('load', function () { - navigator.serviceWorker.register('/service-worker.js') - .then(function (reg) { - console.log('Service worker registered.', reg); - }); - }); -} - -var deferredInstallPrompt = null; - -UserMenu.include({ - start: function () { - window.addEventListener('beforeinstallprompt', this.saveBeforeInstallPromptEvent); - return this._super.apply(this, arguments); - }, - saveBeforeInstallPromptEvent: function(evt) { - deferredInstallPrompt = evt; - this.$.find('#pwa_install_button')[0].removeAttribute('hidden'); - }, - _onMenuInstallpwa: function () { - deferredInstallPrompt.prompt(); - // Hide the install button, it can't be called twice. - this.el.setAttribute('hidden', true); - // Log user response to prompt. - deferredInstallPrompt.userChoice - .then(function (choice) { - if (choice.outcome === 'accepted') { - console.log('User accepted the A2HS prompt', choice); - } else { - console.log('User dismissed the A2HS prompt', choice); - } - deferredInstallPrompt = null; + if ("serviceWorker" in navigator) { + window.addEventListener("load", function() { + navigator.serviceWorker.register("/service-worker.js").then(function(reg) { + console.log("Service worker registered.", reg); }); - }, -}); + }); + } + var deferredInstallPrompt = null; + + UserMenu.include({ + start: function() { + window.addEventListener( + "beforeinstallprompt", + this.saveBeforeInstallPromptEvent + ); + return this._super.apply(this, arguments); + }, + saveBeforeInstallPromptEvent: function(evt) { + deferredInstallPrompt = evt; + this.$.find("#pwa_install_button")[0].removeAttribute("hidden"); + }, + _onMenuInstallpwa: function() { + deferredInstallPrompt.prompt(); + // Hide the install button, it can't be called twice. + this.el.setAttribute("hidden", true); + // Log user response to prompt. + deferredInstallPrompt.userChoice.then(function(choice) { + if (choice.outcome === "accepted") { + console.log("User accepted the A2HS prompt", choice); + } else { + console.log("User dismissed the A2HS prompt", choice); + } + deferredInstallPrompt = null; + }); + }, + }); }); diff --git a/web_pwa_oca/static/src/xml/pwa_install.xml b/web_pwa_oca/static/src/xml/pwa_install.xml index ab6681f69..6f371785e 100644 --- a/web_pwa_oca/static/src/xml/pwa_install.xml +++ b/web_pwa_oca/static/src/xml/pwa_install.xml @@ -1,14 +1,18 @@ - + - - + - - + - diff --git a/web_pwa_oca/views/webclient_templates.xml b/web_pwa_oca/views/webclient_templates.xml index 14dd5a7a1..cc4f9ac79 100644 --- a/web_pwa_oca/views/webclient_templates.xml +++ b/web_pwa_oca/views/webclient_templates.xml @@ -1,29 +1,35 @@ - +