fix: stop interval when window not focused - [INS-4571]#8082
fix: stop interval when window not focused - [INS-4571]#8082CurryYangxx wants to merge 2 commits intodevelopfrom
Conversation
5ba1a23 to
b335300
Compare
gatzjames
left a comment
There was a problem hiding this comment.
I think we can use the document.hasFocus() method and avoid the bridge here.
Also the checkGitChanges doesn't seem to work as expected.
| return; | ||
| } | ||
| isCheckingGitChanges.current = true; | ||
| await checkGitChanges(workspaceId); |
There was a problem hiding this comment.
Not sure this is updating the UI since it doesn't use the routes and the app doesn't re-render
There was a problem hiding this comment.
@gatzjames do you mean the checkGitChanges function? We don't need to update the UI in this scenario, we just need to update the hasUncommitChange db field when the user is working on the collection page, and we use this field to show notifications on the other router page(dashboard page).
| const loadingFetch = gitFetchFetcher.state === 'loading'; | ||
| const loadingStatus = gitStatusFetcher.state === 'loading'; | ||
|
|
||
| useEffect(() => { |
There was a problem hiding this comment.
Not sure we need the bridge here. Could you share some more info on your approach?
Tried with document.hasFocus() and it works as expected if the app is not focused since we only have one tab in one window renderer
There was a problem hiding this comment.
@gatzjames I haven't used document.hasFocus before, I can try it and if it works I can use it instead. And I think listening to the BrowserWindow focus and 'blur' event is necessary here.
452eb3c to
f4ffed3
Compare
|
After discussing with the team, we have some concern about using focus to control when the interval starts may introduce some side effects. Also after James's pr #8027, the performance of git status has been greatly improved. |
Changes:
isWinsowFocusedbridgefocusandblureventisCheckingGitChangesto record the task status, if the last time task is not finished, skip this time.Background:

We use a timer in the collection to periodically check the status of the git repository and update db, to display uncommitted changes in the dashboard page.