Skip to content

Commit

Permalink
Closes #163 - stops refresh when unfocused
Browse files Browse the repository at this point in the history
  • Loading branch information
eamodio committed Oct 13, 2017
1 parent fb2d755 commit 57827f5
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 4 deletions.
38 changes: 35 additions & 3 deletions src/gitService.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -85,8 +85,8 @@ export class GitService extends Disposable {
return this._onDidChangeGitCache.event;
}

private _onDidChangeFileSystem = new EventEmitter<Uri>();
get onDidChangeFileSystem(): Event<Uri> {
private _onDidChangeFileSystem = new EventEmitter<Uri | undefined>();
get onDidChangeFileSystem(): Event<Uri | undefined> {
return this._onDidChangeFileSystem.event;
}

Expand All @@ -95,6 +95,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<string, GitCacheEntry>;
private _remotesCache: Map<string, GitRemote[]>;
private _cacheDisposable: Disposable | undefined;
Expand All @@ -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)
];
Expand Down Expand Up @@ -213,6 +217,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;
Expand Down Expand Up @@ -268,6 +290,11 @@ export class GitService extends Disposable {
this._repoChangedReasons.push(reason);
}

if (!this._focused) {
this._unfocusedChanges.repo = true;
return;
}

return this._fireRepoChangeDebounced();
}

Expand Down Expand Up @@ -1016,6 +1043,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);
};

Expand Down
2 changes: 1 addition & 1 deletion src/views/statusNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 57827f5

Please sign in to comment.