mirror of https://github.com/OCA/web.git
[IMP] web_pwa_oca: black, isort, prettier
pre-commit fixes pre-commit fixes 2pull/2310/head
parent
4ec8d1ab8b
commit
402ca37b14
|
@ -13,15 +13,8 @@
|
||||||
"license": "LGPL-3",
|
"license": "LGPL-3",
|
||||||
"application": True,
|
"application": True,
|
||||||
"installable": True,
|
"installable": True,
|
||||||
"depends": [
|
"depends": ["web", "mail"],
|
||||||
'web',
|
"data": ["views/webclient_templates.xml"],
|
||||||
'mail',
|
"qweb": ["static/src/xml/pwa_install.xml"],
|
||||||
],
|
"images": ["static/description/pwa.png"],
|
||||||
"data": [
|
|
||||||
"views/webclient_templates.xml",
|
|
||||||
],
|
|
||||||
'qweb': [
|
|
||||||
'static/src/xml/pwa_install.xml',
|
|
||||||
],
|
|
||||||
'images': ['static/description/pwa.png'],
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,75 +1,77 @@
|
||||||
from odoo.http import request, Controller, route
|
from odoo.http import Controller, request, route
|
||||||
|
|
||||||
|
|
||||||
class PWA(Controller):
|
class PWA(Controller):
|
||||||
|
|
||||||
def get_asset_urls(self, asset_xml_id):
|
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)
|
assets = qweb._get_asset_nodes(asset_xml_id, {}, True, True)
|
||||||
urls = []
|
urls = []
|
||||||
for asset in assets:
|
for asset in assets:
|
||||||
if asset[0] == 'link':
|
if asset[0] == "link":
|
||||||
urls.append(asset[1]['href'])
|
urls.append(asset[1]["href"])
|
||||||
if asset[0] == 'script':
|
if asset[0] == "script":
|
||||||
urls.append(asset[1]['src'])
|
urls.append(asset[1]["src"])
|
||||||
return urls
|
return urls
|
||||||
|
|
||||||
@route('/service-worker.js', type='http', auth="public")
|
@route("/service-worker.js", type="http", auth="public")
|
||||||
def service_worker(self):
|
def service_worker(self):
|
||||||
qweb = request.env['ir.qweb'].sudo()
|
qweb = request.env["ir.qweb"].sudo()
|
||||||
urls = []
|
urls = []
|
||||||
urls.extend(self.get_asset_urls("web.assets_common"))
|
urls.extend(self.get_asset_urls("web.assets_common"))
|
||||||
urls.extend(self.get_asset_urls("web.assets_backend"))
|
urls.extend(self.get_asset_urls("web.assets_backend"))
|
||||||
version_list = []
|
version_list = []
|
||||||
for url in urls:
|
for url in urls:
|
||||||
version_list.append(url.split('/')[3])
|
version_list.append(url.split("/")[3])
|
||||||
cache_version = '-'.join(version_list)
|
cache_version = "-".join(version_list)
|
||||||
mimetype = 'text/javascript;charset=utf-8'
|
mimetype = "text/javascript;charset=utf-8"
|
||||||
content = qweb.render('web_pwa_oca.service_worker', {
|
content = qweb.render(
|
||||||
'pwa_cache_name': cache_version,
|
"web_pwa_oca.service_worker",
|
||||||
'pwa_files_to_cache': urls,
|
{"pwa_cache_name": cache_version, "pwa_files_to_cache": urls},
|
||||||
})
|
)
|
||||||
return request.make_response(content, [('Content-Type', mimetype)])
|
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):
|
def manifest(self):
|
||||||
qweb = request.env['ir.qweb'].sudo()
|
qweb = request.env["ir.qweb"].sudo()
|
||||||
config_param = request.env['ir.config_parameter'].sudo()
|
config_param = request.env["ir.config_parameter"].sudo()
|
||||||
pwa_name = config_param.get_param("pwa.manifest.name", "Odoo PWA")
|
pwa_name = config_param.get_param("pwa.manifest.name", "Odoo PWA")
|
||||||
pwa_short_name = config_param.get_param("pwa.manifest.short_name", "Odoo PWA")
|
pwa_short_name = config_param.get_param("pwa.manifest.short_name", "Odoo PWA")
|
||||||
icon128x128 = config_param.get_param(
|
icon128x128 = config_param.get_param(
|
||||||
"pwa.manifest.icon128x128",
|
"pwa.manifest.icon128x128", "/web_pwa_oca/static/img/icons/icon-128x128.png"
|
||||||
"/web_pwa_oca/static/img/icons/icon-128x128.png")
|
)
|
||||||
icon144x144 = config_param.get_param(
|
icon144x144 = config_param.get_param(
|
||||||
"pwa.manifest.icon144x144",
|
"pwa.manifest.icon144x144", "/web_pwa_oca/static/img/icons/icon-144x144.png"
|
||||||
"/web_pwa_oca/static/img/icons/icon-144x144.png")
|
)
|
||||||
icon152x152 = config_param.get_param(
|
icon152x152 = config_param.get_param(
|
||||||
"pwa.manifest.icon152x152",
|
"pwa.manifest.icon152x152", "/web_pwa_oca/static/img/icons/icon-152x152.png"
|
||||||
"/web_pwa_oca/static/img/icons/icon-152x152.png")
|
)
|
||||||
icon192x192 = config_param.get_param(
|
icon192x192 = config_param.get_param(
|
||||||
"pwa.manifest.icon192x192",
|
"pwa.manifest.icon192x192", "/web_pwa_oca/static/img/icons/icon-192x192.png"
|
||||||
"/web_pwa_oca/static/img/icons/icon-192x192.png")
|
)
|
||||||
icon256x256 = config_param.get_param(
|
icon256x256 = config_param.get_param(
|
||||||
"pwa.manifest.icon256x256",
|
"pwa.manifest.icon256x256", "/web_pwa_oca/static/img/icons/icon-256x256.png"
|
||||||
"/web_pwa_oca/static/img/icons/icon-256x256.png")
|
)
|
||||||
icon512x512 = config_param.get_param(
|
icon512x512 = config_param.get_param(
|
||||||
"pwa.manifest.icon512x512",
|
"pwa.manifest.icon512x512", "/web_pwa_oca/static/img/icons/icon-512x512.png"
|
||||||
"/web_pwa_oca/static/img/icons/icon-512x512.png")
|
)
|
||||||
background_color = config_param.get_param(
|
background_color = config_param.get_param(
|
||||||
"pwa.manifest.background_color", "#2E69B5")
|
"pwa.manifest.background_color", "#2E69B5"
|
||||||
theme_color = config_param.get_param(
|
)
|
||||||
"pwa.manifest.theme_color", "#2E69B5")
|
theme_color = config_param.get_param("pwa.manifest.theme_color", "#2E69B5")
|
||||||
mimetype = 'application/json;charset=utf-8'
|
mimetype = "application/json;charset=utf-8"
|
||||||
content = qweb.render('web_pwa_oca.manifest', {
|
content = qweb.render(
|
||||||
'pwa_name': pwa_name,
|
"web_pwa_oca.manifest",
|
||||||
'pwa_short_name': pwa_short_name,
|
{
|
||||||
'icon128x128': icon128x128,
|
"pwa_name": pwa_name,
|
||||||
'icon144x144': icon144x144,
|
"pwa_short_name": pwa_short_name,
|
||||||
'icon152x152': icon152x152,
|
"icon128x128": icon128x128,
|
||||||
'icon192x192': icon192x192,
|
"icon144x144": icon144x144,
|
||||||
'icon256x256': icon256x256,
|
"icon152x152": icon152x152,
|
||||||
'icon512x512': icon512x512,
|
"icon192x192": icon192x192,
|
||||||
'background_color': background_color,
|
"icon256x256": icon256x256,
|
||||||
'theme_color': theme_color,
|
"icon512x512": icon512x512,
|
||||||
})
|
"background_color": background_color,
|
||||||
return request.make_response(content, [('Content-Type', mimetype)])
|
"theme_color": theme_color,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
return request.make_response(content, [("Content-Type", mimetype)])
|
||||||
|
|
|
@ -1,15 +1,12 @@
|
||||||
odoo.define('web_pwa_oca.systray.install', function (require) {
|
odoo.define("web_pwa_oca.systray.install", function(require) {
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
var core = require('web.core');
|
var UserMenu = require("web.UserMenu");
|
||||||
var session = require('web.session');
|
|
||||||
var UserMenu = require('web.UserMenu');
|
|
||||||
|
|
||||||
if ('serviceWorker' in navigator) {
|
if ("serviceWorker" in navigator) {
|
||||||
window.addEventListener('load', function () {
|
window.addEventListener("load", function() {
|
||||||
navigator.serviceWorker.register('/service-worker.js')
|
navigator.serviceWorker.register("/service-worker.js").then(function(reg) {
|
||||||
.then(function (reg) {
|
console.log("Service worker registered.", reg);
|
||||||
console.log('Service worker registered.', reg);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -18,28 +15,29 @@ var deferredInstallPrompt = null;
|
||||||
|
|
||||||
UserMenu.include({
|
UserMenu.include({
|
||||||
start: function() {
|
start: function() {
|
||||||
window.addEventListener('beforeinstallprompt', this.saveBeforeInstallPromptEvent);
|
window.addEventListener(
|
||||||
|
"beforeinstallprompt",
|
||||||
|
this.saveBeforeInstallPromptEvent
|
||||||
|
);
|
||||||
return this._super.apply(this, arguments);
|
return this._super.apply(this, arguments);
|
||||||
},
|
},
|
||||||
saveBeforeInstallPromptEvent: function(evt) {
|
saveBeforeInstallPromptEvent: function(evt) {
|
||||||
deferredInstallPrompt = evt;
|
deferredInstallPrompt = evt;
|
||||||
this.$.find('#pwa_install_button')[0].removeAttribute('hidden');
|
this.$.find("#pwa_install_button")[0].removeAttribute("hidden");
|
||||||
},
|
},
|
||||||
_onMenuInstallpwa: function() {
|
_onMenuInstallpwa: function() {
|
||||||
deferredInstallPrompt.prompt();
|
deferredInstallPrompt.prompt();
|
||||||
// Hide the install button, it can't be called twice.
|
// Hide the install button, it can't be called twice.
|
||||||
this.el.setAttribute('hidden', true);
|
this.el.setAttribute("hidden", true);
|
||||||
// Log user response to prompt.
|
// Log user response to prompt.
|
||||||
deferredInstallPrompt.userChoice
|
deferredInstallPrompt.userChoice.then(function(choice) {
|
||||||
.then(function (choice) {
|
if (choice.outcome === "accepted") {
|
||||||
if (choice.outcome === 'accepted') {
|
console.log("User accepted the A2HS prompt", choice);
|
||||||
console.log('User accepted the A2HS prompt', choice);
|
|
||||||
} else {
|
} else {
|
||||||
console.log('User dismissed the A2HS prompt', choice);
|
console.log("User dismissed the A2HS prompt", choice);
|
||||||
}
|
}
|
||||||
deferredInstallPrompt = null;
|
deferredInstallPrompt = null;
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,14 +1,18 @@
|
||||||
<?xml version="1.0" encoding="UTF-8" ?>
|
<?xml version="1.0" encoding="UTF-8" ?>
|
||||||
<templates>
|
<templates>
|
||||||
|
|
||||||
<t t-name="web_pwa_oca.systray.install">
|
<t t-name="web_pwa_oca.systray.install">
|
||||||
<a href="#" role="menuitem" id="pwa_install_button" data-menu="installpwa" class="dropdown-item" hidden="1">Install PWA</a>
|
<a
|
||||||
|
href="#"
|
||||||
|
role="menuitem"
|
||||||
|
id="pwa_install_button"
|
||||||
|
data-menu="installpwa"
|
||||||
|
class="dropdown-item"
|
||||||
|
hidden="1"
|
||||||
|
>Install PWA</a>
|
||||||
</t>
|
</t>
|
||||||
|
|
||||||
<t t-extend="UserMenu.Actions">
|
<t t-extend="UserMenu.Actions">
|
||||||
<t t-jquery="a[data-menu='settings']" t-operation="after">
|
<t t-jquery="a[data-menu='settings']" t-operation="after">
|
||||||
<t t-call="web_pwa_oca.systray.install" />
|
<t t-call="web_pwa_oca.systray.install" />
|
||||||
</t>
|
</t>
|
||||||
</t>
|
</t>
|
||||||
|
|
||||||
</templates>
|
</templates>
|
||||||
|
|
|
@ -8,14 +8,20 @@
|
||||||
<meta name="apple-mobile-web-app-capable" content="yes" />
|
<meta name="apple-mobile-web-app-capable" content="yes" />
|
||||||
<meta name="apple-mobile-web-app-status-bar-style" content="black" />
|
<meta name="apple-mobile-web-app-status-bar-style" content="black" />
|
||||||
<meta name="apple-mobile-web-app-title" content="Odoo PWA" />
|
<meta name="apple-mobile-web-app-title" content="Odoo PWA" />
|
||||||
<link rel="apple-touch-icon" href="/web_pwa_oca/static/img/icons/icon-152x152.png"/>
|
<link
|
||||||
|
rel="apple-touch-icon"
|
||||||
|
href="/web_pwa_oca/static/img/icons/icon-152x152.png"
|
||||||
|
/>
|
||||||
<!-- Add meta theme-color -->
|
<!-- Add meta theme-color -->
|
||||||
<meta name="theme-color" content="#2E69B5" />
|
<meta name="theme-color" content="#2E69B5" />
|
||||||
</xpath>
|
</xpath>
|
||||||
</template>
|
</template>
|
||||||
<template id="assets_backend" name="PWA assets" inherit_id="web.assets_backend">
|
<template id="assets_backend" name="PWA assets" inherit_id="web.assets_backend">
|
||||||
<xpath expr="." position="inside">
|
<xpath expr="." position="inside">
|
||||||
<script type="text/javascript" src="/web_pwa_oca/static/src/js/pwa_install.js"/>
|
<script
|
||||||
|
type="text/javascript"
|
||||||
|
src="/web_pwa_oca/static/src/js/pwa_install.js"
|
||||||
|
/>
|
||||||
</xpath>
|
</xpath>
|
||||||
</template>
|
</template>
|
||||||
<template id="service_worker" name="PWA service worker">
|
<template id="service_worker" name="PWA service worker">
|
||||||
|
@ -65,7 +71,6 @@ self.addEventListener('fetch', function(evt) {
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<template id="manifest" name="PWA manifest">
|
<template id="manifest" name="PWA manifest">
|
||||||
{
|
{
|
||||||
"name": "<t t-esc="pwa_name" />",
|
"name": "<t t-esc="pwa_name" />",
|
||||||
|
@ -101,5 +106,4 @@ self.addEventListener('fetch', function(evt) {
|
||||||
"theme_color": "<t t-esc="theme_color" />"
|
"theme_color": "<t t-esc="theme_color" />"
|
||||||
}
|
}
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
</odoo>
|
</odoo>
|
||||||
|
|
Loading…
Reference in New Issue