diff --git a/src/services/GitService.ts b/src/services/GitService.ts index f6fa5ae43..7bf5cd6a6 100644 --- a/src/services/GitService.ts +++ b/src/services/GitService.ts @@ -2,13 +2,16 @@ import {Observable} from "rxjs/Observable"; import {BehaviorSubject} from "rxjs/BehaviorSubject"; import "rxjs/add/observable/timer"; import "rxjs/add/operator/concatMap"; +import "rxjs/add/operator/filter"; +import "rxjs/add/operator/merge"; import "rxjs/add/operator/share"; import "rxjs/add/operator/distinctUntilChanged"; import "rxjs/add/operator/multicast"; import {currentBranchName, GitDirectoryPath, repositoryState, RepositoryState} from "../utils/Git"; +import {services} from "./index"; -const INTERVAL = 2000; +const INTERVAL = 5000; async function getState(directory: string): Promise { const state = await repositoryState(directory); @@ -27,6 +30,7 @@ async function getState(directory: string): Promise { function createObservable(directory: string) { return Observable .timer(0, INTERVAL) + .merge(services.sessions.jobFinishedObservable.filter(session => session.directory === directory)) .concatMap(() => getState(directory)) // Don't emit if a value didn't change. .distinctUntilChanged((x, y) => JSON.stringify(x) === JSON.stringify(y)) diff --git a/src/services/SessionsService.ts b/src/services/SessionsService.ts index aaa7b579d..f96bdd844 100644 --- a/src/services/SessionsService.ts +++ b/src/services/SessionsService.ts @@ -1,13 +1,22 @@ import {Session, SessionID} from "../shell/Session"; import {ApplicationComponent} from "../views/ApplicationComponent"; +import {Observable} from "rxjs/Observable"; +import {Subject} from "rxjs/Subject"; +import "rxjs/add/observable/fromEvent"; + export class SessionsService { + readonly jobFinishedObservable = new Subject(); private readonly sessions: Map = new Map; create(application: ApplicationComponent) { const session = new Session(application); this.sessions.set(session.id, session); + Observable.fromEvent(session, "job-finished").subscribe( + () => this.jobFinishedObservable.next(session), + ); + return session.id; } diff --git a/src/shell/Session.ts b/src/shell/Session.ts index d50f5e083..564345ed3 100644 --- a/src/shell/Session.ts +++ b/src/shell/Session.ts @@ -42,6 +42,7 @@ export class Session extends events.EventEmitter { job.execute(); job.once("end", () => { + this.emit("job-finished"); this.emit("jobs-changed"); const electronWindow = remote.BrowserWindow.getAllWindows()[0];