Skip to content
This repository has been archived by the owner on May 21, 2019. It is now read-only.

Commit

Permalink
Update git status after a job is finished.
Browse files Browse the repository at this point in the history
  • Loading branch information
vlad-shatskyi committed Aug 4, 2017
1 parent 38bbd74 commit 375d1a3
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/services/GitService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<GitState> {
const state = await repositoryState(directory);
Expand All @@ -27,6 +30,7 @@ async function getState(directory: string): Promise<GitState> {
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))
Expand Down
9 changes: 9 additions & 0 deletions src/services/SessionsService.ts
Original file line number Diff line number Diff line change
@@ -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<Session>();
private readonly sessions: Map<SessionID, Session> = 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;
}

Expand Down
1 change: 1 addition & 0 deletions src/shell/Session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down

0 comments on commit 375d1a3

Please sign in to comment.