Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Fix polling in relation to re-initialization #138

Merged
merged 1 commit into from
Mar 2, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/extensionmanager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ export class ExtensionManager implements Disposable {
// Add the event listener for settings changes, then re-initialized the extension
if (workspace) {
workspace.onDidChangeConfiguration(() => {
Logger.LogDebug("Reinitializing due to onDidChangeConfiguration");
//FUTURE: Check to see if we really need to do the re-initialization
this.Reinitialize();
});
}
Expand Down Expand Up @@ -391,7 +393,7 @@ export class ExtensionManager implements Disposable {
}
}

private notifyBranchChanged(currentBranch: string) {
private notifyBranchChanged(currentBranch: string) : void {
this._teamExtension.NotifyBranchChanged(currentBranch);
//this._tfvcExtension.NotifyBranchChanged(currentBranch);
}
Expand Down
58 changes: 39 additions & 19 deletions src/team-extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ export class TeamExtension {
private _gitClient: GitClient;
private _witClient: WitClient;
private _pinnedQuerySettings: PinnedQuerySettings;
private _pollingTimer: NodeJS.Timer;
private _initialTimer: NodeJS.Timer;

constructor(manager: ExtensionManager) {
this._manager = manager;
Expand Down Expand Up @@ -317,27 +319,33 @@ export class TeamExtension {
public InitializeStatusBars() {
//Only initialize the status bar item if this is a Git repository
if (this._manager.RepoContext.Type === RepositoryType.GIT) {
this._pullRequestStatusBarItem = window.createStatusBarItem(StatusBarAlignment.Left, 99);
this._pullRequestStatusBarItem.command = CommandNames.GetPullRequests;
this._pullRequestStatusBarItem.text = GitClient.GetPullRequestStatusText(0);
this._pullRequestStatusBarItem.tooltip = Strings.BrowseYourPullRequests;
this._pullRequestStatusBarItem.show();
if (!this._pullRequestStatusBarItem) {
this._pullRequestStatusBarItem = window.createStatusBarItem(StatusBarAlignment.Left, 99);
this._pullRequestStatusBarItem.command = CommandNames.GetPullRequests;
this._pullRequestStatusBarItem.text = GitClient.GetPullRequestStatusText(0);
this._pullRequestStatusBarItem.tooltip = Strings.BrowseYourPullRequests;
this._pullRequestStatusBarItem.show();
}
}

this._buildStatusBarItem = window.createStatusBarItem(StatusBarAlignment.Left, 98);
this._buildStatusBarItem.command = CommandNames.OpenBuildSummaryPage;
this._buildStatusBarItem.text = `$(icon octicon-package) ` + `$(icon octicon-dash)`;
this._buildStatusBarItem.tooltip = Strings.NoBuildsFound;
this._buildStatusBarItem.show();
if (!this._buildStatusBarItem) {
this._buildStatusBarItem = window.createStatusBarItem(StatusBarAlignment.Left, 98);
this._buildStatusBarItem.command = CommandNames.OpenBuildSummaryPage;
this._buildStatusBarItem.text = `$(icon octicon-package) ` + `$(icon octicon-dash)`;
this._buildStatusBarItem.tooltip = Strings.NoBuildsFound;
this._buildStatusBarItem.show();
}

this._pinnedQueryStatusBarItem = window.createStatusBarItem(StatusBarAlignment.Left, 97);
this._pinnedQueryStatusBarItem.command = CommandNames.ViewPinnedQueryWorkItems;
this._pinnedQueryStatusBarItem.text = WitClient.GetPinnedQueryStatusText(0);
this._pinnedQueryStatusBarItem.tooltip = Strings.ViewYourPinnedQuery;
this._pinnedQueryStatusBarItem.show();
if (!this._pinnedQueryStatusBarItem) {
this._pinnedQueryStatusBarItem = window.createStatusBarItem(StatusBarAlignment.Left, 97);
this._pinnedQueryStatusBarItem.command = CommandNames.ViewPinnedQueryWorkItems;
this._pinnedQueryStatusBarItem.text = WitClient.GetPinnedQueryStatusText(0);
this._pinnedQueryStatusBarItem.tooltip = Strings.ViewYourPinnedQuery;
this._pinnedQueryStatusBarItem.show();
}
}

public InitializeClients(repoType: RepositoryType) {
public InitializeClients(repoType: RepositoryType) : void {
//We can initialize for any repo type (just skip _gitClient if not Git)
this._pinnedQuerySettings = new PinnedQuerySettings(this._manager.ServerContext.RepoInfo.Account);
this._buildClient = new BuildClient(this._manager.ServerContext, this._buildStatusBarItem);
Expand All @@ -346,7 +354,6 @@ export class TeamExtension {
this._gitClient = new GitClient(this._manager.ServerContext, this._pullRequestStatusBarItem);
}
this._witClient = new WitClient(this._manager.ServerContext, this._pinnedQuerySettings.PinnedQuery, this._pinnedQueryStatusBarItem);
this.refreshPollingItems();
this.startPolling();
}

Expand Down Expand Up @@ -386,22 +393,35 @@ export class TeamExtension {

//Sets up the interval to refresh polling items
private startPolling(): void {
setInterval(() => this.refreshPollingItems(), 1000 * 60 * this._manager.Settings.PollingInterval);
if (!this._pollingTimer) {
this._initialTimer = setTimeout(() => this.refreshPollingItems(), 1000 * 8);
this._pollingTimer = setInterval(() => this.refreshPollingItems(), 1000 * 60 * this._manager.Settings.PollingInterval);
}
}

public NotifyBranchChanged(currentBranch: string) {
public NotifyBranchChanged(currentBranch: string) : void {
this.refreshPollingItems();
}

dispose() {
if (this._pollingTimer) {
if (this._initialTimer) {
clearTimeout(this._initialTimer);
}
clearInterval(this._pollingTimer);
this._pollingTimer = undefined;
}
if (this._pullRequestStatusBarItem !== undefined) {
this._pullRequestStatusBarItem.dispose();
this._pullRequestStatusBarItem = undefined;
}
if (this._buildStatusBarItem !== undefined) {
this._buildStatusBarItem.dispose();
this._buildStatusBarItem = undefined;
}
if (this._pinnedQueryStatusBarItem !== undefined) {
this._pinnedQueryStatusBarItem.dispose();
this._pinnedQueryStatusBarItem = undefined;
}
}
}