From 396936904e2804191fdf4197234c940fb3fc184d Mon Sep 17 00:00:00 2001 From: Jeremy Croff Date: Tue, 23 Jan 2024 14:14:11 -0600 Subject: [PATCH 1/9] fix: uses visibility api from electron to determine visibility, implements focus seperately --- desktop/ELECTRON_EVENTS.js | 1 + desktop/contextBridge.js | 1 + desktop/main.js | 5 +++++ src/libs/Visibility/index.desktop.ts | 2 +- 4 files changed, 8 insertions(+), 1 deletion(-) diff --git a/desktop/ELECTRON_EVENTS.js b/desktop/ELECTRON_EVENTS.js index ee8c0521892e..b2fa95171315 100644 --- a/desktop/ELECTRON_EVENTS.js +++ b/desktop/ELECTRON_EVENTS.js @@ -6,6 +6,7 @@ const ELECTRON_EVENTS = { REQUEST_FOCUS_APP: 'requestFocusApp', REQUEST_UPDATE_BADGE_COUNT: 'requestUpdateBadgeCount', REQUEST_VISIBILITY: 'requestVisibility', + REQUEST_HAS_FOCUS:' requestHasFocus', KEYBOARD_SHORTCUTS_PAGE: 'keyboard-shortcuts-page', START_UPDATE: 'start-update', UPDATE_DOWNLOADED: 'update-downloaded', diff --git a/desktop/contextBridge.js b/desktop/contextBridge.js index a8b89cdc0b64..1c8be9115ae7 100644 --- a/desktop/contextBridge.js +++ b/desktop/contextBridge.js @@ -7,6 +7,7 @@ const WHITELIST_CHANNELS_RENDERER_TO_MAIN = [ ELECTRON_EVENTS.REQUEST_FOCUS_APP, ELECTRON_EVENTS.REQUEST_UPDATE_BADGE_COUNT, ELECTRON_EVENTS.REQUEST_VISIBILITY, + ELECTRON_EVENTS.REQUEST_HAS_FOCUS, ELECTRON_EVENTS.START_UPDATE, ELECTRON_EVENTS.LOCALE_UPDATED, ]; diff --git a/desktop/main.js b/desktop/main.js index e53f03530b57..170c60293c5d 100644 --- a/desktop/main.js +++ b/desktop/main.js @@ -557,6 +557,11 @@ const mainWindow = () => { ipcMain.on(ELECTRON_EVENTS.REQUEST_VISIBILITY, (event) => { // This is how synchronous messages work in Electron + // eslint-disable-next-line no-param-reassign + event.returnValue = browserWindow && !browserWindow.isDestroyed() && browserWindow.isVisible(); + }); + + ipcMain.on(ELECTRON_EVENTS.REQUEST_HAS_FOCUS, (event) => { // eslint-disable-next-line no-param-reassign event.returnValue = browserWindow && !browserWindow.isDestroyed() && browserWindow.isFocused(); }); diff --git a/src/libs/Visibility/index.desktop.ts b/src/libs/Visibility/index.desktop.ts index c01b6001f456..de887ba331be 100644 --- a/src/libs/Visibility/index.desktop.ts +++ b/src/libs/Visibility/index.desktop.ts @@ -8,7 +8,7 @@ import type {HasFocus, IsVisible, OnVisibilityChange} from './types'; */ const isVisible: IsVisible = () => !!window.electron.sendSync(ELECTRON_EVENTS.REQUEST_VISIBILITY); -const hasFocus: HasFocus = () => true; +const hasFocus: HasFocus = () => !!window.electron.sendSync(ELECTRON_EVENTS.REQUEST_HAS_FOCUS); /** * Adds event listener for changes in visibility state From 20020502033da43bbb17145b13c4c3f1899c0363 Mon Sep 17 00:00:00 2001 From: Jeremy Croff Date: Tue, 23 Jan 2024 21:38:48 -0600 Subject: [PATCH 2/9] fix: handle visibility and focus events --- src/pages/home/report/ReportActionsList.js | 23 +++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/src/pages/home/report/ReportActionsList.js b/src/pages/home/report/ReportActionsList.js index 8d79e7af8dd4..05f73032d7ea 100644 --- a/src/pages/home/report/ReportActionsList.js +++ b/src/pages/home/report/ReportActionsList.js @@ -13,6 +13,7 @@ import useLocalize from '@hooks/useLocalize'; import useNetwork from '@hooks/useNetwork'; import useReportScrollManager from '@hooks/useReportScrollManager'; import useThemeStyles from '@hooks/useThemeStyles'; +import useAppFocusEvent from '@hooks/useAppFocusEvent'; import compose from '@libs/compose'; import DateUtils from '@libs/DateUtils'; import * as ReportActionsUtils from '@libs/ReportActionsUtils'; @@ -202,18 +203,23 @@ function ReportActionsList({ prevReportID = report.reportID; }, [report.reportID]); + const readNewestReportActionOnFocus = () => { + if(!ReportUtils.isUnread(report)){ + return + } + if (Visibility.hasFocus() && scrollingVerticalOffset.current < MSG_VISIBLE_THRESHOLD) { + Report.readNewestAction(report.reportID); + } else { + readActionSkipped.current = true; + } + } + useEffect(() => { if (!userActiveSince.current || report.reportID !== prevReportID) { return; } - if (ReportUtils.isUnread(report)) { - if (Visibility.isVisible() && scrollingVerticalOffset.current < MSG_VISIBLE_THRESHOLD) { - Report.readNewestAction(report.reportID); - } else { - readActionSkipped.current = true; - } - } + readNewestReportActionOnFocus() if (currentUnreadMarker || lastVisibleActionCreatedRef.current === report.lastVisibleActionCreated) { return; @@ -225,6 +231,9 @@ function ReportActionsList({ // eslint-disable-next-line react-hooks/exhaustive-deps }, [report.lastVisibleActionCreated, report.reportID]); + // mark actions as read when the user opens up the tab or app + useAppFocusEvent(readNewestReportActionOnFocus) + useEffect(() => { if (!userActiveSince.current || report.reportID !== prevReportID) { return; From 1a1b84cecbae8dc9805e267a53a20087298f0c08 Mon Sep 17 00:00:00 2001 From: Jeremy Croff Date: Wed, 24 Jan 2024 11:51:27 -0600 Subject: [PATCH 3/9] fix/34829: refactor condition --- src/pages/home/report/ReportActionsList.js | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/pages/home/report/ReportActionsList.js b/src/pages/home/report/ReportActionsList.js index 05f73032d7ea..b2ea93da286d 100644 --- a/src/pages/home/report/ReportActionsList.js +++ b/src/pages/home/report/ReportActionsList.js @@ -204,10 +204,7 @@ function ReportActionsList({ }, [report.reportID]); const readNewestReportActionOnFocus = () => { - if(!ReportUtils.isUnread(report)){ - return - } - if (Visibility.hasFocus() && scrollingVerticalOffset.current < MSG_VISIBLE_THRESHOLD) { + if (ReportUtils.isUnread(report) && Visibility.hasFocus() && scrollingVerticalOffset.current < MSG_VISIBLE_THRESHOLD) { Report.readNewestAction(report.reportID); } else { readActionSkipped.current = true; From da88368bbebeed6a38b38c9986e99606fbb2b304 Mon Sep 17 00:00:00 2001 From: Jeremy Croff Date: Wed, 24 Jan 2024 16:09:20 -0600 Subject: [PATCH 4/9] fix/34829: only mark as read if changed --- src/pages/home/report/ReportActionsList.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/pages/home/report/ReportActionsList.js b/src/pages/home/report/ReportActionsList.js index b2ea93da286d..32fc0b7e209e 100644 --- a/src/pages/home/report/ReportActionsList.js +++ b/src/pages/home/report/ReportActionsList.js @@ -204,6 +204,9 @@ function ReportActionsList({ }, [report.reportID]); const readNewestReportActionOnFocus = () => { + if (!userActiveSince.current || report.reportID !== prevReportID) { + return; + } if (ReportUtils.isUnread(report) && Visibility.hasFocus() && scrollingVerticalOffset.current < MSG_VISIBLE_THRESHOLD) { Report.readNewestAction(report.reportID); } else { @@ -212,9 +215,6 @@ function ReportActionsList({ } useEffect(() => { - if (!userActiveSince.current || report.reportID !== prevReportID) { - return; - } readNewestReportActionOnFocus() From 13b0752c554f804cca0015433722a7174ec826cc Mon Sep 17 00:00:00 2001 From: Jeremy Croff Date: Tue, 30 Jan 2024 21:27:01 -0600 Subject: [PATCH 5/9] fix/34829: format --- .ruby-version | 1 + src/pages/home/report/ReportActionsList.js | 13 +++++-------- 2 files changed, 6 insertions(+), 8 deletions(-) create mode 100644 .ruby-version diff --git a/.ruby-version b/.ruby-version new file mode 100644 index 000000000000..818bd47abfc9 --- /dev/null +++ b/.ruby-version @@ -0,0 +1 @@ +3.0.6 diff --git a/src/pages/home/report/ReportActionsList.js b/src/pages/home/report/ReportActionsList.js index 340594c12229..841fd92ac801 100644 --- a/src/pages/home/report/ReportActionsList.js +++ b/src/pages/home/report/ReportActionsList.js @@ -9,11 +9,11 @@ import InvertedFlatList from '@components/InvertedFlatList'; import {withPersonalDetails} from '@components/OnyxProvider'; import withCurrentUserPersonalDetails, {withCurrentUserPersonalDetailsDefaultProps, withCurrentUserPersonalDetailsPropTypes} from '@components/withCurrentUserPersonalDetails'; import withWindowDimensions, {windowDimensionsPropTypes} from '@components/withWindowDimensions'; +import useAppFocusEvent from '@hooks/useAppFocusEvent'; import useLocalize from '@hooks/useLocalize'; import useNetwork from '@hooks/useNetwork'; import useReportScrollManager from '@hooks/useReportScrollManager'; import useThemeStyles from '@hooks/useThemeStyles'; -import useAppFocusEvent from '@hooks/useAppFocusEvent'; import compose from '@libs/compose'; import DateUtils from '@libs/DateUtils'; import * as ReportActionsUtils from '@libs/ReportActionsUtils'; @@ -213,24 +213,21 @@ function ReportActionsList({ } else { readActionSkipped.current = true; } - } + }; useEffect(() => { - - readNewestReportActionOnFocus() - + readNewestReportActionOnFocus(); if (currentUnreadMarker || lastVisibleActionCreatedRef.current === report.lastVisibleActionCreated) { return; } - cacheUnreadMarkers.delete(report.reportID); lastVisibleActionCreatedRef.current = report.lastVisibleActionCreated; setCurrentUnreadMarker(null); // eslint-disable-next-line react-hooks/exhaustive-deps }, [report.lastVisibleActionCreated, report.reportID]); - // mark actions as read when the user opens up the tab or app - useAppFocusEvent(readNewestReportActionOnFocus) + // mark actions as read when the user opens up the tab or app and current report is open + useAppFocusEvent(readNewestReportActionOnFocus); useEffect(() => { if (!userActiveSince.current || report.reportID !== prevReportID) { From cf948907031864860eb9f0eddaa7116fa0975134 Mon Sep 17 00:00:00 2001 From: Jeremy Croff Date: Wed, 31 Jan 2024 18:46:19 -0600 Subject: [PATCH 6/9] fix/34829: remove other logic to simplify solution --- desktop/ELECTRON_EVENTS.js | 1 - desktop/contextBridge.js | 1 - desktop/main.js | 5 ----- src/libs/Visibility/index.desktop.ts | 2 +- src/pages/home/report/ReportActionsList.js | 10 +++++----- 5 files changed, 6 insertions(+), 13 deletions(-) diff --git a/desktop/ELECTRON_EVENTS.js b/desktop/ELECTRON_EVENTS.js index b2fa95171315..ee8c0521892e 100644 --- a/desktop/ELECTRON_EVENTS.js +++ b/desktop/ELECTRON_EVENTS.js @@ -6,7 +6,6 @@ const ELECTRON_EVENTS = { REQUEST_FOCUS_APP: 'requestFocusApp', REQUEST_UPDATE_BADGE_COUNT: 'requestUpdateBadgeCount', REQUEST_VISIBILITY: 'requestVisibility', - REQUEST_HAS_FOCUS:' requestHasFocus', KEYBOARD_SHORTCUTS_PAGE: 'keyboard-shortcuts-page', START_UPDATE: 'start-update', UPDATE_DOWNLOADED: 'update-downloaded', diff --git a/desktop/contextBridge.js b/desktop/contextBridge.js index 1c8be9115ae7..a8b89cdc0b64 100644 --- a/desktop/contextBridge.js +++ b/desktop/contextBridge.js @@ -7,7 +7,6 @@ const WHITELIST_CHANNELS_RENDERER_TO_MAIN = [ ELECTRON_EVENTS.REQUEST_FOCUS_APP, ELECTRON_EVENTS.REQUEST_UPDATE_BADGE_COUNT, ELECTRON_EVENTS.REQUEST_VISIBILITY, - ELECTRON_EVENTS.REQUEST_HAS_FOCUS, ELECTRON_EVENTS.START_UPDATE, ELECTRON_EVENTS.LOCALE_UPDATED, ]; diff --git a/desktop/main.js b/desktop/main.js index 170c60293c5d..e53f03530b57 100644 --- a/desktop/main.js +++ b/desktop/main.js @@ -557,11 +557,6 @@ const mainWindow = () => { ipcMain.on(ELECTRON_EVENTS.REQUEST_VISIBILITY, (event) => { // This is how synchronous messages work in Electron - // eslint-disable-next-line no-param-reassign - event.returnValue = browserWindow && !browserWindow.isDestroyed() && browserWindow.isVisible(); - }); - - ipcMain.on(ELECTRON_EVENTS.REQUEST_HAS_FOCUS, (event) => { // eslint-disable-next-line no-param-reassign event.returnValue = browserWindow && !browserWindow.isDestroyed() && browserWindow.isFocused(); }); diff --git a/src/libs/Visibility/index.desktop.ts b/src/libs/Visibility/index.desktop.ts index de887ba331be..1526eb143fb9 100644 --- a/src/libs/Visibility/index.desktop.ts +++ b/src/libs/Visibility/index.desktop.ts @@ -8,7 +8,7 @@ import type {HasFocus, IsVisible, OnVisibilityChange} from './types'; */ const isVisible: IsVisible = () => !!window.electron.sendSync(ELECTRON_EVENTS.REQUEST_VISIBILITY); -const hasFocus: HasFocus = () => !!window.electron.sendSync(ELECTRON_EVENTS.REQUEST_HAS_FOCUS); +const hasFocus: HasFocus = () => true /** * Adds event listener for changes in visibility state diff --git a/src/pages/home/report/ReportActionsList.js b/src/pages/home/report/ReportActionsList.js index 59a96a36d770..33879f31c7db 100644 --- a/src/pages/home/report/ReportActionsList.js +++ b/src/pages/home/report/ReportActionsList.js @@ -203,11 +203,11 @@ function ReportActionsList({ prevReportID = report.reportID; }, [report.reportID]); - const readNewestReportActionOnFocus = () => { + const readNewestReportAction = () => { if (!userActiveSince.current || report.reportID !== prevReportID) { return; } - if (ReportUtils.isUnread(report) && Visibility.hasFocus() && scrollingVerticalOffset.current < MSG_VISIBLE_THRESHOLD) { + if (ReportUtils.isUnread(report) && Visibility.isVisible() && scrollingVerticalOffset.current < MSG_VISIBLE_THRESHOLD) { Report.readNewestAction(report.reportID); } else { readActionSkipped.current = true; @@ -215,7 +215,7 @@ function ReportActionsList({ }; useEffect(() => { - readNewestReportActionOnFocus(); + readNewestReportAction(); if (currentUnreadMarker || lastVisibleActionCreatedRef.current === report.lastVisibleActionCreated) { return; } @@ -225,8 +225,8 @@ function ReportActionsList({ // eslint-disable-next-line react-hooks/exhaustive-deps }, [report.lastVisibleActionCreated, report.reportID]); - // mark actions as read when the user opens up the tab or app and current report is open - useAppFocusEvent(readNewestReportActionOnFocus); + // recheck on focus for read, allows notifications to + useAppFocusEvent(readNewestReportAction); useEffect(() => { if (!userActiveSince.current || report.reportID !== prevReportID) { From b03d47a7770069c74cf0edb98ea18b0e66ebb0bf Mon Sep 17 00:00:00 2001 From: Jeremy Croff <157416545+jeremy-croff@users.noreply.github.com> Date: Wed, 31 Jan 2024 18:47:37 -0600 Subject: [PATCH 7/9] Delete .ruby-version --- .ruby-version | 1 - 1 file changed, 1 deletion(-) delete mode 100644 .ruby-version diff --git a/.ruby-version b/.ruby-version deleted file mode 100644 index 818bd47abfc9..000000000000 --- a/.ruby-version +++ /dev/null @@ -1 +0,0 @@ -3.0.6 From bb4cef0cef70e6a0aa898a4ed0579ba725ff667d Mon Sep 17 00:00:00 2001 From: Jeremy Croff <157416545+jeremy-croff@users.noreply.github.com> Date: Wed, 31 Jan 2024 18:47:54 -0600 Subject: [PATCH 8/9] Update index.desktop.ts --- src/libs/Visibility/index.desktop.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/Visibility/index.desktop.ts b/src/libs/Visibility/index.desktop.ts index 1526eb143fb9..c01b6001f456 100644 --- a/src/libs/Visibility/index.desktop.ts +++ b/src/libs/Visibility/index.desktop.ts @@ -8,7 +8,7 @@ import type {HasFocus, IsVisible, OnVisibilityChange} from './types'; */ const isVisible: IsVisible = () => !!window.electron.sendSync(ELECTRON_EVENTS.REQUEST_VISIBILITY); -const hasFocus: HasFocus = () => true +const hasFocus: HasFocus = () => true; /** * Adds event listener for changes in visibility state From 3e71481d2240a38970901e0809aeec42f6040a47 Mon Sep 17 00:00:00 2001 From: Jeremy Croff <157416545+jeremy-croff@users.noreply.github.com> Date: Wed, 31 Jan 2024 18:48:30 -0600 Subject: [PATCH 9/9] Update ReportActionsList.js --- src/pages/home/report/ReportActionsList.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/pages/home/report/ReportActionsList.js b/src/pages/home/report/ReportActionsList.js index 33879f31c7db..245aa2d41380 100644 --- a/src/pages/home/report/ReportActionsList.js +++ b/src/pages/home/report/ReportActionsList.js @@ -225,7 +225,6 @@ function ReportActionsList({ // eslint-disable-next-line react-hooks/exhaustive-deps }, [report.lastVisibleActionCreated, report.reportID]); - // recheck on focus for read, allows notifications to useAppFocusEvent(readNewestReportAction); useEffect(() => {