Debian Codegraph @

addons/point_of_sale/static/src/app/utils/init_lna.js

raw
1 import { _t } from "@web/core/l10n/translation";
2
3 /**
4 * Initialize Local Network Access permission handling.
5 *
6 * @returns {Promise<{
7 * type: "warning" | "danger" | "success" | "info"
8 * message: string
9 * }>}
10 */
11 export const initLNA = async (notificationService, callback = () => {}) => {
12 if (!odoo.use_lna) {
13 callback("info", _t("Local Network Access is not configured for this POS."));
14 return;
15 }
16
17 const processLNAState = (result) => {
18 let type = "";
19 let message = "";
20
21 if (result.state === "granted") {
22 type = "success";
23 message = _t("Local Network Access permission granted.");
24 } else if (result.state === "prompt") {
25 type = "warning";
26 message = _t(
27 "Local Network Access permission is not yet granted. Some hardware devices might not work properly. Please allow Local Network Access in your browser settings."
28 );
29 } else {
30 type = "danger";
31 message = _t(
32 "Local Network Access permission is denied. Some hardware devices might not work properly. Please allow Local Network Access in your browser settings."
33 );
34 notificationService.add(message, { type: "warning" });
35 }
36
37 callback(type, message);
38 };
39
40 try {
41 const result = await navigator.permissions.query({ name: "local-network-access" });
42 processLNAState(result);
43 result.onchange = () => processLNAState(result);
44 } catch {
45 odoo.use_lna = false;
46 const isChromiumBased = navigator.userAgent.includes("Chromium") || !!window.chrome;
47 let message;
48 if (!isChromiumBased) {
49 message = _t(
50 "Local Network Access configuration is enabled, but your browser is not Chromium-based. Please use a Chromium-based browser to benefit from this feature. Please note that IOS devices do not support Local Network Access yet."
51 );
52 } else {
53 message = _t(
54 "Local Network Access is enabled for this POS, but your browser version does not support it. Please update your browser to the latest version."
55 );
56 }
57
58 notificationService.add(message, { type: "warning" });
59 callback("danger", message);
60 }
61 };