@@ -399,32 +399,29 @@ define(function (require, exports) {
399399 }
400400 }
401401
402- let lastExecutionTime = 0 ;
403402 let isCommandExecuting = false ;
404- const FOCUS_SWITCH_DEDUPE_TIME = 5000 ;
405403 function refreshOnFocusChange ( ) {
406404 // to sync external git changes after switching to app.
407405 if ( gitEnabled ) {
408- const now = Date . now ( ) ;
406+ const isGitPanelVisible = Panel . getPanel ( ) . is ( ":visible" ) ;
409407
410408 if ( isCommandExecuting ) {
411409 return ;
412410 }
413-
414- if ( now - lastExecutionTime > FOCUS_SWITCH_DEDUPE_TIME ) {
415- isCommandExecuting = true ;
416- lastExecutionTime = Date . now ( ) ;
417- Git . hasStatusChanged ( ) . then ( ( hasChanged ) => {
418- if ( ! hasChanged ) {
419- return ;
420- }
421-
422- CommandManager . execute ( Constants . CMD_GIT_REFRESH ) . fail ( ( err ) => {
423- console . error ( "error refreshing on focus switch" , err ) ;
424- } ) ;
425- } ) . finally ( ( ) => {
411+ isCommandExecuting = true ;
412+
413+ // if the git panel is visible, its very likely user is working with git (maybe external)
414+ // so when Phoenix gains focus, we do a complete git refresh to show latest status
415+ if ( isGitPanelVisible ) {
416+ CommandManager . execute ( Constants . CMD_GIT_REFRESH ) . fail ( ( err ) => {
417+ console . error ( "error refreshing on focus switch" , err ) ;
418+ } ) . always ( ( ) => {
426419 isCommandExecuting = false ;
427420 } ) ;
421+ } else {
422+ // if panel not visible, we just refresh the git branch (shown in sidebar)
423+ Branch . refresh ( ) ;
424+ isCommandExecuting = false ;
428425 }
429426 }
430427 }
0 commit comments