From 563b6a8a39ea3010340d786799631ae6e555fe38 Mon Sep 17 00:00:00 2001 From: luvi Date: Tue, 18 Jul 2023 13:12:15 +0000 Subject: [PATCH] [IMP] web: add isDisplayStandalone feature detection helper This commit adds the isDisplayStandalone helper, allowing to detect whether Odoo is running inside the Progressive Web App (in standalone mode) or not. This feature detection is directly used in the linked enterprise closes odoo/odoo#128969 Pr: https://github.com/odoo/enterprise/pull/43680. Related: odoo/enterprise#43680 Signed-off-by: Pierre Paridans (app) --- addons/web/static/src/core/browser/browser.js | 1 + addons/web/static/src/core/browser/feature_detection.js | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/addons/web/static/src/core/browser/browser.js b/addons/web/static/src/core/browser/browser.js index fc7562c04c2..5d05195ce1a 100644 --- a/addons/web/static/src/core/browser/browser.js +++ b/addons/web/static/src/core/browser/browser.js @@ -33,6 +33,7 @@ export const browser = { cancelAnimationFrame: window.cancelAnimationFrame.bind(window), console: window.console, history: window.history, + matchMedia: window.matchMedia.bind(window), navigator, Notification: window.Notification, open: window.open.bind(window), diff --git a/addons/web/static/src/core/browser/feature_detection.js b/addons/web/static/src/core/browser/feature_detection.js index d0795e58736..2aec3e0b60f 100644 --- a/addons/web/static/src/core/browser/feature_detection.js +++ b/addons/web/static/src/core/browser/feature_detection.js @@ -48,6 +48,10 @@ export function isAndroidApp() { return /OdooMobile.+Android/i.test(browser.navigator.userAgent); } +export function isDisplayStandalone() { + return browser.matchMedia("(display-mode: standalone)").matches; +} + export function hasTouch() { return browser.ontouchstart !== undefined; }