-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: stop interval when window not focused - [INS-4571] #8082
Conversation
5ba1a23
to
b335300
Compare
packages/insomnia/src/ui/components/dropdowns/git-sync-dropdown.tsx
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@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 loadingPush = gitPushFetcher.state === 'loading'; | ||
const loadingPull = gitPullFetcher.state === 'loading'; | ||
const loadingFetch = gitFetchFetcher.state === 'loading'; | ||
const loadingStatus = gitStatusFetcher.state === 'loading'; | ||
|
||
useEffect(() => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@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:
isWinsowFocused
bridgefocus
andblur
eventisCheckingGitChanges
to 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.