mirror of
https://github.com/OCA/web.git
synced 2025-02-22 13:21:25 +02:00
Rename web_pwa -> web_pwa_oca
This commit is contained in:
45
web_pwa_oca/static/src/js/pwa_install.js
Normal file
45
web_pwa_oca/static/src/js/pwa_install.js
Normal file
@@ -0,0 +1,45 @@
|
||||
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');
|
||||
|
||||
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;
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
});
|
||||
14
web_pwa_oca/static/src/xml/pwa_install.xml
Normal file
14
web_pwa_oca/static/src/xml/pwa_install.xml
Normal file
@@ -0,0 +1,14 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<templates>
|
||||
|
||||
<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>
|
||||
</t>
|
||||
|
||||
<t t-extend="UserMenu.Actions">
|
||||
<t t-jquery="a[data-menu='settings']" t-operation="after">
|
||||
<t t-call="web_pwa_oca.systray.install"/>
|
||||
</t>
|
||||
</t>
|
||||
|
||||
</templates>
|
||||
Reference in New Issue
Block a user