Skip to content

Commit

Permalink
Merge pull request #18065 from tienifr/fix/17242-17969
Browse files Browse the repository at this point in the history
fix: web does not show not show notifications for not active window
  • Loading branch information
luacmartins authored May 1, 2023
2 parents 9b7d6cd + bc2124f commit ce3b938
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 1 deletion.
8 changes: 8 additions & 0 deletions src/libs/Visibility/index.desktop.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@ function isVisible() {
return window.electron.sendSync(ELECTRON_EVENTS.REQUEST_VISIBILITY);
}

/**
* @returns {Boolean}
*/
function hasFocus() {
return true;
}

/**
* Adds event listener for changes in visibility state
*
Expand All @@ -32,4 +39,5 @@ function onVisibilityChange(callback) {
export default {
isVisible,
onVisibilityChange,
hasFocus,
};
10 changes: 10 additions & 0 deletions src/libs/Visibility/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@ function isVisible() {
return document.visibilityState === 'visible';
}

/**
* Whether the app is focused.
*
* @returns {Boolean}
*/
function hasFocus() {
return document.hasFocus();
}

/**
* Adds event listener for changes in visibility state
*
Expand All @@ -25,5 +34,6 @@ function onVisibilityChange(callback) {

export default {
isVisible,
hasFocus,
onVisibilityChange,
};
8 changes: 8 additions & 0 deletions src/libs/Visibility/index.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@ import {AppState} from 'react-native';
*/
const isVisible = () => AppState.currentState === 'active';

/**
* @returns {Boolean}
*/
function hasFocus() {
return true;
}

/**
* Adds event listener for changes in visibility state
*
Expand All @@ -24,5 +31,6 @@ function onVisibilityChange(callback) {

export default {
isVisible,
hasFocus,
onVisibilityChange,
};
2 changes: 1 addition & 1 deletion src/libs/actions/Report.js
Original file line number Diff line number Diff line change
Expand Up @@ -1218,7 +1218,7 @@ function shouldShowReportActionNotification(reportID, action = null, isRemote =
}

// If we are currently viewing this report do not show a notification.
if (reportID === Navigation.getReportIDFromRoute() && Visibility.isVisible()) {
if (reportID === Navigation.getReportIDFromRoute() && Visibility.isVisible() && Visibility.hasFocus()) {
Log.info(`${tag} No notification because it was a comment for the current report`);
return false;
}
Expand Down

0 comments on commit ce3b938

Please sign in to comment.