Skip to content

Commit 894a2e0

Browse files
devvaannshabose
authored andcommitted
fix: git panel not getting updated when phoenix gains focus
1 parent a9d4d8d commit 894a2e0

File tree

2 files changed

+15
-16
lines changed

2 files changed

+15
-16
lines changed

src/extensions/default/Git/src/Main.js

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}

src/extensions/default/Git/src/git/GitCli.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -797,6 +797,8 @@ define(function (require, exports) {
797797
});
798798
}
799799

800+
// this function right now is not being used anywhere,
801+
// but leaving it here (we might need it in the future)
800802
function hasStatusChanged() {
801803
const prevStatus = lastGitStatusResults;
802804
return status().then(function (currentStatus) {

0 commit comments

Comments
 (0)