| 1 |
import { Loader } from "@point_of_sale/app/components/loader/loader"; |
| 2 |
import { getTemplate } from "@web/core/templates"; |
| 3 |
import { mount, reactive, whenReady } from "@odoo/owl"; |
| 4 |
import { _t, appTranslateFn } from "@web/core/l10n/translation"; |
| 5 |
import { hasTouch } from "@web/core/browser/feature_detection"; |
| 6 |
import { localization } from "@web/core/l10n/localization"; |
| 7 |
import { user } from "@web/core/user"; |
| 8 |
import { session } from "@web/session"; |
| 9 |
import { mountComponent } from "@web/env"; |
| 10 |
import { Chrome } from "@point_of_sale/app/pos_app"; |
| 11 |
|
| 12 |
const loader = reactive({ isShown: true, error: false }); |
| 13 |
whenReady(() => { |
| 14 |
mount(Loader, document.body, { |
| 15 |
getTemplate, |
| 16 |
props: { loader }, |
| 17 |
translatableAttributes: ["data-tooltip"], |
| 18 |
translateFn: appTranslateFn, |
| 19 |
}); |
| 20 |
}); |
| 21 |
|
| 22 |
(async function startPosApp() { |
| 23 |
odoo.info = { |
| 24 |
db: session.db, |
| 25 |
server_version: session.server_version, |
| 26 |
server_version_info: session.server_version_info, |
| 27 |
isEnterprise: session.server_version_info.slice(-1)[0] === "e", |
| 28 |
}; |
| 29 |
await whenReady(); |
| 30 |
try { |
| 31 |
const app = await mountComponent(Chrome, document.body, { |
| 32 |
name: "Odoo Point of Sale", |
| 33 |
props: { disableLoader: () => (loader.isShown = false) }, |
| 34 |
}); |
| 35 |
window.addEventListener("beforeunload", function (event) { |
| 36 |
if (app.env.services.pos_data.network.offline) { |
| 37 |
var confirmationMessage = _t( |
| 38 |
"You are currently offline. Reloading the page may cause you to lose unsaved data." |
| 39 |
); |
| 40 |
event.returnValue = confirmationMessage; |
| 41 |
return confirmationMessage; |
| 42 |
} |
| 43 |
}); |
| 44 |
const classList = document.body.classList; |
| 45 |
if (localization.direction === "rtl") { |
| 46 |
classList.add("o_rtl"); |
| 47 |
} |
| 48 |
if (user.userId === 1) { |
| 49 |
classList.add("o_is_superuser"); |
| 50 |
} |
| 51 |
if (app.env.debug) { |
| 52 |
classList.add("o_debug"); |
| 53 |
} |
| 54 |
if (hasTouch()) { |
| 55 |
classList.add("o_touch_device"); |
| 56 |
classList.add("o_mobile_overscroll"); |
| 57 |
document.documentElement.classList.add("o_mobile_overscroll"); |
| 58 |
} |
| 59 |
|
| 60 |
registerServiceWorker(); |
| 61 |
} catch (e) { |
| 62 |
loader.error = e; |
| 63 |
throw e; |
| 64 |
} |
| 65 |
})(); |
| 66 |
|
| 67 |
function registerServiceWorker() { |
| 68 |
// Register the service worker for the POS |
| 69 |
const urlsToCache = JSON.parse(odoo.urls_to_cache); |
| 70 |
urlsToCache.push("/web/static/lib/zxing-library/zxing-library.js"); |
| 71 |
|
| 72 |
navigator.serviceWorker?.register("/pos/service-worker.js").then((registration) => { |
| 73 |
const worker = registration.installing || registration.waiting || registration.active; |
| 74 |
worker.postMessage({ urlsToCache }); |
| 75 |
}); |
| 76 |
} |