diff --git a/src/gitService.ts b/src/gitService.ts index 8b3ab26..2c0167c 100644 --- a/src/gitService.ts +++ b/src/gitService.ts @@ -1,6 +1,6 @@ 'use strict'; import { Functions, Iterables, Objects } from './system'; -import { Disposable, Event, EventEmitter, FileSystemWatcher, Range, TextDocument, TextDocumentChangeEvent, TextEditor, Uri, workspace } from 'vscode'; +import { Disposable, Event, EventEmitter, FileSystemWatcher, Range, TextDocument, TextDocumentChangeEvent, TextEditor, Uri, window, WindowState, workspace } from 'vscode'; import { IConfig } from './configuration'; import { DocumentSchemes, ExtensionKey } from './constants'; import { RemoteProviderFactory } from './git/remotes/factory'; @@ -84,8 +84,8 @@ export class GitService extends Disposable { return this._onDidChangeGitCache.event; } - private _onDidChangeFileSystem = new EventEmitter(); - get onDidChangeFileSystem(): Event { + private _onDidChangeFileSystem = new EventEmitter(); + get onDidChangeFileSystem(): Event { return this._onDidChangeFileSystem.event; } @@ -94,6 +94,9 @@ export class GitService extends Disposable { return this._onDidChangeRepo.event; } + private _focused: boolean = true; + private _unfocusedChanges: { repo: boolean, fs: boolean } = { repo: false, fs: false }; + private _gitCache: Map; private _remotesCache: Map; private _cacheDisposable: Disposable | undefined; @@ -117,6 +120,7 @@ export class GitService extends Disposable { this._onConfigurationChanged(); const subscriptions: Disposable[] = [ + window.onDidChangeWindowState(this._onWindowStateChanged, this), workspace.onDidChangeConfiguration(this._onConfigurationChanged, this), RemoteProviderFactory.onDidChange(this._onRemoteProviderChanged, this) ]; @@ -192,6 +196,24 @@ export class GitService extends Disposable { this._fireRepoChange(RepoChangedReasons.Remotes); } + private _onWindowStateChanged(e: WindowState) { + const focusChanged = e.focused !== this._focused; + this._focused = e.focused; + + if (!focusChanged || !e.focused) return; + + // If we've come back into focus and we are dirty, fire the change events + if (this._unfocusedChanges.fs) { + this._unfocusedChanges.fs = false; + this._onDidChangeFileSystem.fire(); + } + + if (this._unfocusedChanges.repo) { + this._unfocusedChanges.repo = false; + this._fireRepoChangeDebounced!(); + } + } + private _onTextDocumentChanged(e: TextDocumentChangeEvent) { if (!this.UseCaching) return; if (e.document.uri.scheme !== DocumentSchemes.File) return; @@ -248,6 +270,11 @@ export class GitService extends Disposable { this._repoChangedReasons.push(reason); } + if (!this._focused) { + this._unfocusedChanges.repo = true; + return; + } + return this._fireRepoChangeDebounced(); } @@ -1022,6 +1049,11 @@ export class GitService extends Disposable { // Ignore .git changes if (/\.git/.test(uri.fsPath)) return; + if (!this._focused) { + this._unfocusedChanges.fs = true; + return; + } + debouncedFn(uri); }; diff --git a/src/views/statusNode.ts b/src/views/statusNode.ts index 10209ac..55e9fd1 100644 --- a/src/views/statusNode.ts +++ b/src/views/statusNode.ts @@ -102,7 +102,7 @@ export class StatusNode extends ExplorerNode { return this.git.config.gitExplorer.includeWorkingTree; } - private async onFileSystemChanged(uri: Uri) { + private async onFileSystemChanged(uri?: Uri) { const status = await this.git.getStatusForRepo(this.uri.repoPath!); // If we haven't changed from having some working changes to none or vice versa then just refresh the node