Skip to content

Commit

Permalink
Prevent sending heartbeat when vscode command changed selection
Browse files Browse the repository at this point in the history
  • Loading branch information
alanhamlett committed Sep 3, 2024
1 parent 752a626 commit b70816c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
17 changes: 12 additions & 5 deletions src/wakatime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,9 @@ export class WakaTime {
if (apiUrl.value?.trim()) {
try {
const parsedUrl = new URL(apiUrl.value);
url = `${parsedUrl.protocol}//${parsedUrl.hostname}${parsedUrl.port ? `:${parsedUrl.port}` : ''}`;
url = `${parsedUrl.protocol}//${parsedUrl.hostname}${
parsedUrl.port ? `:${parsedUrl.port}` : ''
}`;
} catch (e) {
this.logger.warnException(e);
}
Expand Down Expand Up @@ -417,8 +419,8 @@ export class WakaTime {
private setupEventListeners(): void {
// subscribe to selection change and editor activation events
let subscriptions: vscode.Disposable[] = [];
vscode.window.onDidChangeTextEditorSelection(this.onChange, this, subscriptions);
vscode.window.onDidChangeActiveTextEditor(this.onChange, this, subscriptions);
vscode.window.onDidChangeTextEditorSelection(this.onChangeSelection, this, subscriptions);
vscode.window.onDidChangeActiveTextEditor(this.onChangeTab, this, subscriptions);
vscode.workspace.onDidSaveTextDocument(this.onSave, this, subscriptions);

vscode.tasks.onDidStartTask(this.onDidStartTask, this, subscriptions);
Expand Down Expand Up @@ -459,11 +461,16 @@ export class WakaTime {
this.onEvent(false);
}

private onChange(): void {
private onChangeSelection(e: vscode.TextEditorSelectionChangeEvent): void {
if (e.kind === vscode.TextEditorSelectionChangeKind.Command) return;
this.onEvent(false);
}

private onSave(): void {
private onChangeTab(_e: vscode.TextEditor | undefined): void {
this.onEvent(false);
}

private onSave(_e: vscode.TextDocument | undefined): void {
this.onEvent(true);
}

Expand Down
13 changes: 9 additions & 4 deletions src/web/wakatime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -312,8 +312,8 @@ export class WakaTime {
private setupEventListeners(): void {
// subscribe to selection change and editor activation events
let subscriptions: vscode.Disposable[] = [];
vscode.window.onDidChangeTextEditorSelection(this.onChange, this, subscriptions);
vscode.window.onDidChangeActiveTextEditor(this.onChange, this, subscriptions);
vscode.window.onDidChangeTextEditorSelection(this.onChangeSelection, this, subscriptions);
vscode.window.onDidChangeActiveTextEditor(this.onChangeTab, this, subscriptions);
vscode.workspace.onDidSaveTextDocument(this.onSave, this, subscriptions);

vscode.tasks.onDidStartTask(this.onDidStartTask, this, subscriptions);
Expand Down Expand Up @@ -354,11 +354,16 @@ export class WakaTime {
this.onEvent(false);
}

private onChange(): void {
private onChangeSelection(e: vscode.TextEditorSelectionChangeEvent): void {
if (e.kind === vscode.TextEditorSelectionChangeKind.Command) return;
this.onEvent(false);
}

private onSave(): void {
private onChangeTab(_e: vscode.TextEditor | undefined): void {
this.onEvent(false);
}

private onSave(_e: vscode.TextDocument | undefined): void {
this.onEvent(true);
}

Expand Down

0 comments on commit b70816c

Please sign in to comment.