Skip to content
Snippets Groups Projects
Commit ce57d449 authored by tsm-odoo's avatar tsm-odoo
Browse files

[FIX] bus: adapt presence service to work with iframe


Before this PR, the presence service was relying on window events
blur/focus to determine whether or not odoo was focused. The issue is
that in the website backend, an iframe is used. When this iframe is focused,
the window looses the focus and vice versa.

This commit fixes this issue by using `window.parent.hasFocus` method.

task-3003950

closes odoo/odoo#102479

Signed-off-by: default avatarAlexandre Kühn (aku) <aku@odoo.com>
parent eeb66a81
No related branches found
No related tags found
No related merge requests found
......@@ -23,11 +23,10 @@ export const presenceService = {
lastPresenceTime = new Date().getTime();
browser.localStorage.setItem(`${LOCAL_STORAGE_PREFIX}.lastPresence`, lastPresenceTime);
}
function onFocusChange(isFocused) {
isOdooFocused = isFocused;
function onFocusChange() {
isOdooFocused = parent.document.hasFocus();
browser.localStorage.setItem(`${LOCAL_STORAGE_PREFIX}.focus`, isOdooFocused);
if (isFocused) {
if (isOdooFocused) {
lastPresenceTime = new Date().getTime();
env.bus.trigger('window_focus', isOdooFocused);
}
......@@ -43,9 +42,9 @@ export const presenceService = {
}
}
browser.addEventListener('storage', onStorage);
browser.addEventListener('focus', () => onFocusChange(true));
browser.addEventListener('blur', () => onFocusChange(false));
browser.addEventListener('pagehide', () => onFocusChange(false));
browser.addEventListener('focus', () => onFocusChange());
browser.addEventListener('blur', () => onFocusChange());
browser.addEventListener('pagehide', () => onFocusChange());
browser.addEventListener('click', onPresence);
browser.addEventListener('keydown', onPresence);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment