mirror of
https://github.com/bringout/oca-technical.git
synced 2026-04-20 09:52:02 +02:00
Initial commit: OCA Technical packages (595 packages)
This commit is contained in:
commit
2cc02aac6e
24950 changed files with 2318079 additions and 0 deletions
|
|
@ -0,0 +1,81 @@
|
|||
/* Copyright 2020 Tecnativa - Alexandre D. Díaz
|
||||
* License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). */
|
||||
|
||||
odoo.define("web_pwa_oca.PWAManager", function (require) {
|
||||
"use strict";
|
||||
|
||||
var core = require("web.core");
|
||||
var config = require("web.config");
|
||||
var Widget = require("web.Widget");
|
||||
|
||||
var _t = core._t;
|
||||
|
||||
/**
|
||||
* @returns {Boolean}
|
||||
*/
|
||||
function isPWAStandalone() {
|
||||
return (
|
||||
window.navigator.standalone ||
|
||||
document.referrer.includes("android-app://") ||
|
||||
window.matchMedia("(display-mode: standalone)").matches
|
||||
);
|
||||
}
|
||||
|
||||
if (isPWAStandalone()) {
|
||||
config.device.isMobile = true;
|
||||
}
|
||||
|
||||
var PWAManager = Widget.extend({
|
||||
/**
|
||||
* @override
|
||||
*/
|
||||
init: function () {
|
||||
this._super.apply(this, arguments);
|
||||
this._isServiceWorkerSupported = "serviceWorker" in navigator;
|
||||
if (!this._isServiceWorkerSupported) {
|
||||
console.error(
|
||||
_t(
|
||||
"Service workers are not supported! Maybe you are not using HTTPS or you work in private mode."
|
||||
)
|
||||
);
|
||||
} else {
|
||||
this._service_worker = navigator.serviceWorker;
|
||||
this.registerServiceWorker("/service-worker.js", {
|
||||
updateViaCache: "none",
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* @param {String} sw_script
|
||||
* @returns {Promise}
|
||||
*/
|
||||
registerServiceWorker: function (sw_script, options) {
|
||||
return this._service_worker
|
||||
.register(sw_script, options)
|
||||
.then(this._onRegisterServiceWorker.bind(this))
|
||||
.catch(function (error) {
|
||||
console.log(_t("[ServiceWorker] Registration failed: "), error);
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* @returns {Boolean}
|
||||
*/
|
||||
isPWAStandalone: function () {
|
||||
return isPWAStandalone();
|
||||
},
|
||||
|
||||
/**
|
||||
* Need register some extra API? override this!
|
||||
*
|
||||
* @private
|
||||
* @param {ServiceWorkerRegistration} registration
|
||||
*/
|
||||
_onRegisterServiceWorker: function (registration) {
|
||||
console.log(_t("[ServiceWorker] Registered:"), registration);
|
||||
},
|
||||
});
|
||||
|
||||
return PWAManager;
|
||||
});
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
/* Copyright 2020 Tecnativa - Alexandre D. Díaz
|
||||
/* Copyright 2022 Tecnativa - Sergio Teruel
|
||||
* License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). */
|
||||
|
||||
odoo.define("web_pwa_oca.pwa_launch", function (require) {
|
||||
"use strict";
|
||||
var core = require("web.core");
|
||||
var PWAManager = require("web_pwa_oca.PWAManager");
|
||||
|
||||
core.bus.on("web_client_ready", null, function () {
|
||||
this.pwa_manager = new PWAManager(this);
|
||||
const def = this.pwa_manager.start();
|
||||
return Promise.all([def]);
|
||||
});
|
||||
});
|
||||
62
odoo-bringout-oca-web-web_pwa_oca/web_pwa_oca/static/src/js/worker/jquery-sw-compat.js
vendored
Normal file
62
odoo-bringout-oca-web-web_pwa_oca/web_pwa_oca/static/src/js/worker/jquery-sw-compat.js
vendored
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
/* Copyright 2020 Tecnativa - Alexandre D. Díaz
|
||||
* License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). */
|
||||
|
||||
// Compatibility layer to load some Odoo modules
|
||||
// This is a hack, not a complete implementation!
|
||||
// only expected to be used by boot.js
|
||||
|
||||
(function () {
|
||||
"use strict";
|
||||
function JQuery(selector, context) {
|
||||
return new JQuery.prototype.init(selector, context);
|
||||
}
|
||||
|
||||
JQuery.prototype = {
|
||||
init: function (selector) {
|
||||
if (typeof selector === "function") {
|
||||
selector();
|
||||
}
|
||||
},
|
||||
|
||||
deparam: function (data) {
|
||||
const params = data.split(",");
|
||||
const res = [];
|
||||
for (const param of params) {
|
||||
res.push(param.split("="));
|
||||
}
|
||||
return _.object(res);
|
||||
},
|
||||
|
||||
param: {
|
||||
querystring: function () {
|
||||
return "debug=1";
|
||||
},
|
||||
},
|
||||
|
||||
when: function (tasks) {
|
||||
return Promise.all(tasks instanceof Array ? tasks : [tasks]).then(
|
||||
(results) => {
|
||||
return results.length === 1 ? results[0] : results;
|
||||
}
|
||||
);
|
||||
},
|
||||
};
|
||||
|
||||
class Deferred {
|
||||
constructor() {
|
||||
this.promise = new Promise((resolve, reject) => {
|
||||
this.reject = reject;
|
||||
this.resolve = resolve;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
JQuery.prototype.Deferred = () => new Deferred();
|
||||
|
||||
self.$ = JQuery;
|
||||
self.$.deparam = JQuery.prototype.deparam;
|
||||
self.$.param = JQuery.prototype.param;
|
||||
self.$.Deferred = JQuery.prototype.Deferred;
|
||||
self.$.when = JQuery.prototype.when;
|
||||
self.window = self;
|
||||
})();
|
||||
|
|
@ -0,0 +1,57 @@
|
|||
/* Copyright 2020 Tecnativa - Alexandre D. Díaz
|
||||
* License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). */
|
||||
|
||||
/**
|
||||
* Services workers are a piece of software separated from the user page.
|
||||
* Here can't use 'Odoo Bootstrap', so we can't work with 'require' system.
|
||||
* When the service worker is called to be installed from the "pwa_manager"
|
||||
* this class is instantiated.
|
||||
*/
|
||||
|
||||
odoo.define("web_pwa_oca.PWA", function (require) {
|
||||
"use strict";
|
||||
|
||||
const OdooClass = require("web.Class");
|
||||
|
||||
const PWA = OdooClass.extend({
|
||||
// eslint-disable-next-line
|
||||
init: function (params) {
|
||||
// To be overridden
|
||||
this._sw_version = params.sw_version;
|
||||
},
|
||||
|
||||
/**
|
||||
* @returns {Promise}
|
||||
*/
|
||||
start: function () {
|
||||
return Promise.resolve();
|
||||
},
|
||||
|
||||
/**
|
||||
* @returns {Promise}
|
||||
*/
|
||||
installWorker: function () {
|
||||
// To be overridden
|
||||
return Promise.resolve();
|
||||
},
|
||||
|
||||
/**
|
||||
* @returns {Promise}
|
||||
*/
|
||||
/* eslint-disable no-unused-vars */
|
||||
activateWorker: function (forced) {
|
||||
// To be overridden
|
||||
return Promise.resolve();
|
||||
},
|
||||
|
||||
/**
|
||||
* @returns {Promise}
|
||||
*/
|
||||
processRequest: function (request) {
|
||||
// To be overridden
|
||||
return fetch(request);
|
||||
},
|
||||
});
|
||||
|
||||
return PWA;
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue